2017-08-01 15:55:51 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-08-01 15:55:51 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-08-01 15:55:51 +00:00
|
|
|
*/
|
|
|
|
#include "dialogs/dialogs_search_from_controllers.h"
|
|
|
|
|
|
|
|
#include "lang/lang_keys.h"
|
2017-12-17 08:13:26 +00:00
|
|
|
#include "data/data_peer_values.h"
|
2017-08-01 15:55:51 +00:00
|
|
|
#include "observer_peer.h"
|
|
|
|
#include "auth_session.h"
|
|
|
|
#include "apiwrap.h"
|
|
|
|
|
|
|
|
namespace Dialogs {
|
|
|
|
|
2017-10-03 13:05:58 +00:00
|
|
|
void ShowSearchFromBox(
|
2017-12-04 07:33:33 +00:00
|
|
|
not_null<Window::Navigation*> navigation,
|
2017-10-03 13:05:58 +00:00
|
|
|
not_null<PeerData*> peer,
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(not_null<UserData*>)> callback,
|
|
|
|
Fn<void()> closedCallback) {
|
2017-12-04 07:33:33 +00:00
|
|
|
auto createController = [
|
|
|
|
navigation,
|
|
|
|
peer,
|
|
|
|
callback = std::move(callback)
|
|
|
|
]() -> std::unique_ptr<PeerListController> {
|
2017-08-01 15:55:51 +00:00
|
|
|
if (peer) {
|
|
|
|
if (auto chat = peer->asChat()) {
|
2017-12-04 07:33:33 +00:00
|
|
|
return std::make_unique<Dialogs::ChatSearchFromController>(
|
|
|
|
navigation,
|
|
|
|
chat,
|
|
|
|
std::move(callback));
|
2017-08-01 15:55:51 +00:00
|
|
|
} else if (auto group = peer->asMegagroup()) {
|
2017-12-04 07:33:33 +00:00
|
|
|
return std::make_unique<Dialogs::ChannelSearchFromController>(
|
|
|
|
navigation,
|
|
|
|
group,
|
|
|
|
std::move(callback));
|
2017-08-01 15:55:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
};
|
|
|
|
if (auto controller = createController()) {
|
2018-03-29 19:49:31 +00:00
|
|
|
auto subscription = std::make_shared<rpl::lifetime>();
|
2017-08-17 08:31:24 +00:00
|
|
|
auto box = Ui::show(Box<PeerListBox>(std::move(controller), [subscription](not_null<PeerListBox*> box) {
|
2017-08-13 16:09:14 +00:00
|
|
|
box->addButton(langFactory(lng_cancel), [box, subscription] { box->closeBox(); });
|
2017-09-15 17:34:41 +00:00
|
|
|
}), LayerOption::KeepOther);
|
2018-03-29 19:49:31 +00:00
|
|
|
box->boxClosing() | rpl::start_with_next(
|
|
|
|
std::move(closedCallback),
|
|
|
|
*subscription);
|
2017-08-01 15:55:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-03 13:05:58 +00:00
|
|
|
ChatSearchFromController::ChatSearchFromController(
|
2017-12-04 07:33:33 +00:00
|
|
|
not_null<Window::Navigation*> navigation,
|
2017-10-03 13:05:58 +00:00
|
|
|
not_null<ChatData*> chat,
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(not_null<UserData*>)> callback)
|
2017-10-03 13:05:58 +00:00
|
|
|
: PeerListController()
|
2017-08-01 15:55:51 +00:00
|
|
|
, _chat(chat)
|
|
|
|
, _callback(std::move(callback)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatSearchFromController::prepare() {
|
|
|
|
setSearchNoResultsText(lang(lng_blocked_list_not_found));
|
|
|
|
delegate()->peerListSetSearchMode(PeerListSearchMode::Enabled);
|
|
|
|
delegate()->peerListSetTitle(langFactory(lng_search_messages_from));
|
|
|
|
|
|
|
|
rebuildRows();
|
|
|
|
|
|
|
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(Notify::PeerUpdate::Flag::MembersChanged, [this](const Notify::PeerUpdate &update) {
|
|
|
|
if (update.peer == _chat) {
|
|
|
|
rebuildRows();
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
void ChatSearchFromController::rowClicked(not_null<PeerListRow*> row) {
|
2017-08-01 15:55:51 +00:00
|
|
|
Expects(row->peer()->isUser());
|
2018-11-26 11:00:31 +00:00
|
|
|
|
|
|
|
const auto onstack = _callback;
|
|
|
|
onstack(row->peer()->asUser());
|
2017-08-01 15:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChatSearchFromController::rebuildRows() {
|
|
|
|
auto ms = getms();
|
|
|
|
auto wasEmpty = !delegate()->peerListFullRowsCount();
|
|
|
|
|
|
|
|
auto now = unixtime();
|
2017-12-17 08:13:26 +00:00
|
|
|
const auto byOnline = [&](not_null<UserData*> user) {
|
|
|
|
return Data::SortByOnlineValue(user, now);
|
|
|
|
};
|
|
|
|
auto ordered = QMultiMap<TimeId, not_null<UserData*>>();
|
2017-08-01 15:55:51 +00:00
|
|
|
if (_chat->noParticipantInfo()) {
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().api().requestFullPeer(_chat);
|
2017-12-01 18:38:44 +00:00
|
|
|
} else if (!_chat->participants.empty()) {
|
|
|
|
for (const auto [user, version] : _chat->participants) {
|
2017-12-17 08:13:26 +00:00
|
|
|
ordered.insertMulti(byOnline(user), user);
|
2017-08-01 15:55:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for_const (auto user, _chat->lastAuthors) {
|
|
|
|
if (user->isInaccessible()) continue;
|
|
|
|
appendRow(user);
|
|
|
|
if (!ordered.isEmpty()) {
|
2017-12-17 08:13:26 +00:00
|
|
|
ordered.remove(byOnline(user), user);
|
2017-08-01 15:55:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!ordered.isEmpty()) {
|
|
|
|
for (auto i = ordered.cend(), b = ordered.cbegin(); i != b;) {
|
|
|
|
appendRow(*(--i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
checkForEmptyRows();
|
|
|
|
delegate()->peerListRefreshRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatSearchFromController::checkForEmptyRows() {
|
|
|
|
if (delegate()->peerListFullRowsCount()) {
|
|
|
|
setDescriptionText(QString());
|
|
|
|
} else {
|
|
|
|
setDescriptionText(lang(lng_contacts_loading));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
void ChatSearchFromController::appendRow(not_null<UserData*> user) {
|
2017-08-01 15:55:51 +00:00
|
|
|
if (!delegate()->peerListFindRow(user->id)) {
|
|
|
|
delegate()->peerListAppendRow(std::make_unique<PeerListRow>(user));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-03 13:05:58 +00:00
|
|
|
ChannelSearchFromController::ChannelSearchFromController(
|
2017-12-04 07:33:33 +00:00
|
|
|
not_null<Window::Navigation*> navigation,
|
2017-10-03 13:05:58 +00:00
|
|
|
not_null<ChannelData*> channel,
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(not_null<UserData*>)> callback)
|
2017-10-03 13:05:58 +00:00
|
|
|
: ParticipantsBoxController(
|
2017-12-04 07:33:33 +00:00
|
|
|
navigation,
|
2017-10-03 13:05:58 +00:00
|
|
|
channel,
|
|
|
|
ParticipantsBoxController::Role::Members)
|
2017-08-01 15:55:51 +00:00
|
|
|
, _callback(std::move(callback)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChannelSearchFromController::prepare() {
|
|
|
|
ParticipantsBoxController::prepare();
|
|
|
|
delegate()->peerListSetTitle(langFactory(lng_search_messages_from));
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
void ChannelSearchFromController::rowClicked(not_null<PeerListRow*> row) {
|
2017-08-01 15:55:51 +00:00
|
|
|
Expects(row->peer()->isUser());
|
2018-11-26 11:00:31 +00:00
|
|
|
|
|
|
|
const auto onstack = _callback;
|
|
|
|
onstack(row->peer()->asUser());
|
2017-08-01 15:55:51 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
std::unique_ptr<PeerListRow> ChannelSearchFromController::createRow(not_null<UserData*> user) const {
|
2017-08-01 15:55:51 +00:00
|
|
|
return std::make_unique<PeerListRow>(user);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Dialogs
|