In jump-to-date don't clear history stack.

This commit is contained in:
John Preston 2022-07-19 14:29:04 +03:00
parent 58fb14e292
commit bb29773090
3 changed files with 30 additions and 12 deletions

View file

@ -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<void(not_null<PeerData*>, MsgId)> callback) {
if (const auto peer = chat.peer()) { if (const auto peer = chat.peer()) {
jumpToHistoryDate(peer, date); resolveJumpToHistoryDate(peer, date, std::move(callback));
} }
} }
@ -2939,20 +2942,22 @@ void ApiWrap::requestMessageAfterDate(
}).send(); }).send();
} }
void ApiWrap::jumpToHistoryDate(not_null<PeerData*> peer, const QDate &date) { void ApiWrap::resolveJumpToHistoryDate(
not_null<PeerData*> peer,
const QDate &date,
Fn<void(not_null<PeerData*>, MsgId)> callback) {
if (const auto channel = peer->migrateTo()) { if (const auto channel = peer->migrateTo()) {
jumpToHistoryDate(channel, date); return resolveJumpToHistoryDate(channel, date, std::move(callback));
return;
} }
const auto jumpToDateInPeer = [=] { const auto jumpToDateInPeer = [=] {
requestMessageAfterDate(peer, date, [=](MsgId resultId) { requestMessageAfterDate(peer, date, [=](MsgId resultId) {
Ui::showPeerHistory(peer, resultId); callback(peer, resultId);
}); });
}; };
if (const auto chat = peer->migrateFrom()) { if (const auto chat = peer->migrateFrom()) {
requestMessageAfterDate(chat, date, [=](MsgId resultId) { requestMessageAfterDate(chat, date, [=](MsgId resultId) {
if (resultId) { if (resultId) {
Ui::showPeerHistory(chat, resultId); callback(chat, resultId);
} else { } else {
jumpToDateInPeer(); jumpToDateInPeer();
} }

View file

@ -258,7 +258,10 @@ public:
bool isQuitPrevent(); bool isQuitPrevent();
void jumpToDate(Dialogs::Key chat, const QDate &date); void resolveJumpToDate(
Dialogs::Key chat,
const QDate &date,
Fn<void(not_null<PeerData*>, MsgId)> callback);
using SliceType = Data::LoadDirection; using SliceType = Data::LoadDirection;
void requestSharedMedia( void requestSharedMedia(
@ -445,7 +448,10 @@ private:
void requestSavedGifs(TimeId now); void requestSavedGifs(TimeId now);
void readFeaturedSets(); void readFeaturedSets();
void jumpToHistoryDate(not_null<PeerData*> peer, const QDate &date); void resolveJumpToHistoryDate(
not_null<PeerData*> peer,
const QDate &date,
Fn<void(not_null<PeerData*>, MsgId)> callback);
template <typename Callback> template <typename Callback>
void requestMessageAfterDate( void requestMessageAfterDate(
not_null<PeerData*> peer, not_null<PeerData*> peer,

View file

@ -1441,12 +1441,19 @@ void SessionController::showCalendar(Dialogs::Key chat, QDate requestedDate) {
button->setPointerCursor(false); button->setPointerCursor(false);
} }
}; };
const auto weak = base::make_weak(this);
const auto jump = [=](const QDate &date) {
const auto open = [=](not_null<PeerData*> 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::CalendarBox>(Ui::CalendarBoxArgs{ show(Box<Ui::CalendarBox>(Ui::CalendarBoxArgs{
.month = highlighted, .month = highlighted,
.highlighted = highlighted, .highlighted = highlighted,
.callback = [=](const QDate &date) { .callback = [=](const QDate &date) { jump(date); },
session().api().jumpToDate(chat, date);
},
.minDate = minPeerDate, .minDate = minPeerDate,
.maxDate = maxPeerDate, .maxDate = maxPeerDate,
.allowsSelection = history->peer->isUser(), .allowsSelection = history->peer->isUser(),