mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-30 22:25:12 +00:00
Limit the CalendarBox selectable days.
Use available information (first and last message date) to limit the days you can choose in jump-to-date calendar box.
This commit is contained in:
@@ -2765,20 +2765,55 @@ void MainWidget::showJumpToDate(PeerData *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 = currentPeerDate(), month = highlighted;
|
||||
Ui::show(Box<CalendarBox>(month, highlighted, [this, peer](const QDate &date) { jumpToDate(peer, date); }));
|
||||
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) {
|
||||
auto time = static_cast<int>(QDateTime(date).toTime_t());
|
||||
// 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(time), MTP_int(-1), MTP_int(1), MTP_int(0), MTP_int(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) {
|
||||
|
Reference in New Issue
Block a user