2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 22:55:11 +00:00

Add search from group member button to dialogs.

This commit is contained in:
John Preston
2017-08-01 14:43:50 +03:00
parent 6f27e310ae
commit 91fda6b654
14 changed files with 124 additions and 100 deletions

View File

@@ -66,7 +66,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "styles/style_boxes.h"
#include "mtproto/dc_options.h"
#include "core/file_utilities.h"
#include "boxes/calendar_box.h"
#include "auth_session.h"
#include "window/notifications_manager.h"
#include "window/window_controller.h"
@@ -2991,97 +2990,6 @@ void MainWidget::dlgUpdated(PeerData *peer, MsgId msgId) {
}
}
void MainWidget::showJumpToDate(PeerData *peer, QDate requestedDate) {
Expects(peer != nullptr);
auto currentPeerDate = [peer] {
if (auto history = App::historyLoaded(peer)) {
if (history->scrollTopItem) {
return history->scrollTopItem->date.date();
} else if (history->loadedAtTop() && !history->isEmpty() && history->peer->migrateFrom()) {
if (auto migrated = App::historyLoaded(history->peer->migrateFrom())) {
if (migrated->scrollTopItem) {
// We're up in the migrated history.
// So current date is the date of first message here.
return history->blocks.front()->items.front()->date.date();
}
}
} else if (!history->lastMsgDate.isNull()) {
return history->lastMsgDate.date();
}
}
return QDate::currentDate();
};
auto maxPeerDate = [peer] {
if (auto history = App::historyLoaded(peer)) {
if (!history->lastMsgDate.isNull()) {
return history->lastMsgDate.date();
}
}
return QDate::currentDate();
};
auto minPeerDate = [peer] {
if (auto history = App::historyLoaded(peer)) {
if (history->loadedAtTop()) {
if (history->isEmpty()) {
return QDate::currentDate();
}
return history->blocks.front()->items.front()->date.date();
}
}
return QDate(2013, 8, 1); // Telegram was launched in August 2013 :)
};
auto highlighted = requestedDate.isNull() ? currentPeerDate() : requestedDate;
auto month = highlighted;
auto box = Box<CalendarBox>(month, highlighted, [this, peer](const QDate &date) { jumpToDate(peer, date); });
box->setMinDate(minPeerDate());
box->setMaxDate(maxPeerDate());
Ui::show(std::move(box));
}
void MainWidget::jumpToDate(PeerData *peer, const QDate &date) {
// API returns a message with date <= offset_date.
// So we request a message with offset_date = desired_date - 1 and add_offset = -1.
// This should give us the first message with date >= desired_date.
auto offset_date = static_cast<int>(QDateTime(date).toTime_t()) - 1;
auto add_offset = -1;
auto limit = 1;
auto flags = MTPmessages_Search::Flags(0);
auto request = MTPmessages_GetHistory(peer->input, MTP_int(0), MTP_int(offset_date), MTP_int(add_offset), MTP_int(limit), MTP_int(0), MTP_int(0));
MTP::send(request, ::rpcDone([peer](const MTPmessages_Messages &result) {
auto getMessagesList = [&result, peer]() -> const QVector<MTPMessage>* {
auto handleMessages = [](auto &messages) {
App::feedUsers(messages.vusers);
App::feedChats(messages.vchats);
return &messages.vmessages.v;
};
switch (result.type()) {
case mtpc_messages_messages: return handleMessages(result.c_messages_messages());
case mtpc_messages_messagesSlice: return handleMessages(result.c_messages_messagesSlice());
case mtpc_messages_channelMessages: {
auto &messages = result.c_messages_channelMessages();
if (peer && peer->isChannel()) {
peer->asChannel()->ptsReceived(messages.vpts.v);
} else {
LOG(("API Error: received messages.channelMessages when no channel was passed! (MainWidget::showJumpToDate)"));
}
return handleMessages(messages);
} break;
}
return nullptr;
};
if (auto list = getMessagesList()) {
App::feedMsgs(*list, NewMessageExisting);
for (auto &message : *list) {
auto id = idFromMessage(message);
Ui::showPeerHistory(peer, id);
return;
}
}
Ui::showPeerHistory(peer, ShowAtUnreadMsgId);
}));
}
void MainWidget::windowShown() {
_history->windowShown();
}
@@ -3102,7 +3010,7 @@ bool MainWidget::deleteChannelFailed(const RPCError &error) {
void MainWidget::inviteToChannelDone(ChannelData *channel, const MTPUpdates &updates) {
sentUpdatesReceived(updates);
App::api()->requestParticipantsCountDelayed(channel);
AuthSession::Current().api().requestParticipantsCountDelayed(channel);
}
void MainWidget::historyToDown(History *history) {