mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 14:45:14 +00:00
@@ -1960,7 +1960,11 @@ void ApiWrap::applyUpdateNoPtsCheck(const MTPUpdate &update) {
|
||||
}
|
||||
}
|
||||
|
||||
void ApiWrap::jumpToDate(not_null<PeerData*> peer, const QDate &date) {
|
||||
template <typename Callback>
|
||||
void ApiWrap::requestMessageAfterDate(
|
||||
not_null<PeerData*> peer,
|
||||
const QDate &date,
|
||||
Callback &&callback) {
|
||||
// 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.
|
||||
@@ -1980,7 +1984,11 @@ void ApiWrap::jumpToDate(not_null<PeerData*> peer, const QDate &date) {
|
||||
MTP_int(maxId),
|
||||
MTP_int(minId),
|
||||
MTP_int(historyHash)
|
||||
)).done([peer](const MTPmessages_Messages &result) {
|
||||
)).done([
|
||||
peer,
|
||||
offsetDate,
|
||||
callback = std::forward<Callback>(callback)
|
||||
](const MTPmessages_Messages &result) {
|
||||
auto getMessagesList = [&result, peer]() -> const QVector<MTPMessage>* {
|
||||
auto handleMessages = [](auto &messages) {
|
||||
App::feedUsers(messages.vusers);
|
||||
@@ -2011,15 +2019,39 @@ void ApiWrap::jumpToDate(not_null<PeerData*> peer, const QDate &date) {
|
||||
if (auto list = getMessagesList()) {
|
||||
App::feedMsgs(*list, NewMessageExisting);
|
||||
for (auto &message : *list) {
|
||||
auto id = idFromMessage(message);
|
||||
Ui::showPeerHistory(peer, id);
|
||||
return;
|
||||
if (dateFromMessage(message) >= offsetDate) {
|
||||
callback(idFromMessage(message));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ui::showPeerHistory(peer, ShowAtUnreadMsgId);
|
||||
callback(ShowAtUnreadMsgId);
|
||||
}).send();
|
||||
}
|
||||
|
||||
void ApiWrap::jumpToDate(not_null<PeerData*> peer, const QDate &date) {
|
||||
if (auto channel = peer->migrateTo()) {
|
||||
jumpToDate(channel, date);
|
||||
return;
|
||||
}
|
||||
auto jumpToDateInPeer = [peer, date, this] {
|
||||
requestMessageAfterDate(peer, date, [peer](MsgId resultId) {
|
||||
Ui::showPeerHistory(peer, resultId);
|
||||
});
|
||||
};
|
||||
if (auto chat = peer->migrateFrom()) {
|
||||
requestMessageAfterDate(chat, date, [=](MsgId resultId) {
|
||||
if (resultId) {
|
||||
Ui::showPeerHistory(chat, resultId);
|
||||
} else {
|
||||
jumpToDateInPeer();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
jumpToDateInPeer();
|
||||
}
|
||||
}
|
||||
|
||||
void ApiWrap::preloadEnoughUnreadMentions(not_null<History*> history) {
|
||||
auto fullCount = history->getUnreadMentionsCount();
|
||||
auto loadedCount = history->getUnreadMentionsLoadedCount();
|
||||
|
Reference in New Issue
Block a user