2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-09-02 07:25:46 +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

@@ -24,6 +24,9 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "mainwidget.h"
#include "styles/style_window.h"
#include "styles/style_dialogs.h"
#include "boxes/calendar_box.h"
#include "auth_session.h"
#include "apiwrap.h"
namespace Window {
@@ -133,4 +136,51 @@ void Controller::provideChatWidth(int requestedWidth) {
}
}
void Controller::showJumpToDate(gsl::not_null<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) { AuthSession::Current().api().jumpToDate(peer, date); });
box->setMinDate(minPeerDate());
box->setMaxDate(maxPeerDate());
Ui::show(std::move(box));
}
} // namespace Window