diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 441ad22e4..3e3ac5439 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -2865,9 +2865,12 @@ void ApiWrap::readFeaturedSets() { } } -void ApiWrap::jumpToDate(Dialogs::Key chat, const QDate &date) { +void ApiWrap::resolveJumpToDate( + Dialogs::Key chat, + const QDate &date, + Fn, MsgId)> callback) { if (const auto peer = chat.peer()) { - jumpToHistoryDate(peer, date); + resolveJumpToHistoryDate(peer, date, std::move(callback)); } } @@ -2939,20 +2942,22 @@ void ApiWrap::requestMessageAfterDate( }).send(); } -void ApiWrap::jumpToHistoryDate(not_null peer, const QDate &date) { +void ApiWrap::resolveJumpToHistoryDate( + not_null peer, + const QDate &date, + Fn, MsgId)> callback) { if (const auto channel = peer->migrateTo()) { - jumpToHistoryDate(channel, date); - return; + return resolveJumpToHistoryDate(channel, date, std::move(callback)); } const auto jumpToDateInPeer = [=] { requestMessageAfterDate(peer, date, [=](MsgId resultId) { - Ui::showPeerHistory(peer, resultId); + callback(peer, resultId); }); }; if (const auto chat = peer->migrateFrom()) { requestMessageAfterDate(chat, date, [=](MsgId resultId) { if (resultId) { - Ui::showPeerHistory(chat, resultId); + callback(chat, resultId); } else { jumpToDateInPeer(); } diff --git a/Telegram/SourceFiles/apiwrap.h b/Telegram/SourceFiles/apiwrap.h index 1f87488ff..e9886ef8e 100644 --- a/Telegram/SourceFiles/apiwrap.h +++ b/Telegram/SourceFiles/apiwrap.h @@ -258,7 +258,10 @@ public: bool isQuitPrevent(); - void jumpToDate(Dialogs::Key chat, const QDate &date); + void resolveJumpToDate( + Dialogs::Key chat, + const QDate &date, + Fn, MsgId)> callback); using SliceType = Data::LoadDirection; void requestSharedMedia( @@ -445,7 +448,10 @@ private: void requestSavedGifs(TimeId now); void readFeaturedSets(); - void jumpToHistoryDate(not_null peer, const QDate &date); + void resolveJumpToHistoryDate( + not_null peer, + const QDate &date, + Fn, MsgId)> callback); template void requestMessageAfterDate( not_null peer, diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index 3af9d6029..549de2ee6 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -1441,12 +1441,19 @@ void SessionController::showCalendar(Dialogs::Key chat, QDate requestedDate) { button->setPointerCursor(false); } }; + const auto weak = base::make_weak(this); + const auto jump = [=](const QDate &date) { + const auto open = [=](not_null peer, MsgId id) { + if (const auto strong = weak.get()) { + strong->showPeerHistory(peer, SectionShow::Way::Forward, id); + } + }; + session().api().resolveJumpToDate(chat, date, open); + }; show(Box(Ui::CalendarBoxArgs{ .month = highlighted, .highlighted = highlighted, - .callback = [=](const QDate &date) { - session().api().jumpToDate(chat, date); - }, + .callback = [=](const QDate &date) { jump(date); }, .minDate = minPeerDate, .maxDate = maxPeerDate, .allowsSelection = history->peer->isUser(),