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"
|
2019-01-10 06:26:08 +00:00
|
|
|
#include "data/data_channel.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_chat.h"
|
|
|
|
#include "data/data_user.h"
|
2017-08-01 15:55:51 +00:00
|
|
|
#include "observer_peer.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2017-08-01 15:55:51 +00:00
|
|
|
#include "apiwrap.h"
|
|
|
|
|
|
|
|
namespace Dialogs {
|
|
|
|
|
2017-10-03 13:05:58 +00:00
|
|
|
void ShowSearchFromBox(
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionNavigation*> 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> {
|
2019-01-13 13:28:05 +00:00
|
|
|
if (peer && (peer->isChat() || peer->isMegagroup())) {
|
|
|
|
return std::make_unique<Dialogs::SearchFromController>(
|
|
|
|
navigation,
|
|
|
|
peer,
|
|
|
|
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) {
|
2019-06-18 16:53:27 +00:00
|
|
|
box->addButton(tr::lng_cancel(), [box, subscription] {
|
2019-01-13 13:28:05 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-13 13:28:05 +00:00
|
|
|
SearchFromController::SearchFromController(
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
2019-01-13 13:28:05 +00:00
|
|
|
not_null<PeerData*> peer,
|
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,
|
2019-01-13 13:28:05 +00:00
|
|
|
peer,
|
2017-10-03 13:05:58 +00:00
|
|
|
ParticipantsBoxController::Role::Members)
|
2017-08-01 15:55:51 +00:00
|
|
|
, _callback(std::move(callback)) {
|
|
|
|
}
|
|
|
|
|
2019-01-13 13:28:05 +00:00
|
|
|
void SearchFromController::prepare() {
|
2017-08-01 15:55:51 +00:00
|
|
|
ParticipantsBoxController::prepare();
|
2019-06-18 15:00:55 +00:00
|
|
|
delegate()->peerListSetTitle(tr::lng_search_messages_from());
|
2017-08-01 15:55:51 +00:00
|
|
|
}
|
|
|
|
|
2019-01-13 13:28:05 +00:00
|
|
|
void SearchFromController::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
|
|
|
|
2019-01-13 13:28:05 +00:00
|
|
|
if (const auto onstack = base::duplicate(_callback)) {
|
|
|
|
onstack(row->peer()->asUser());
|
|
|
|
}
|
2017-08-01 15:55:51 +00:00
|
|
|
}
|
|
|
|
|
2019-01-13 13:28:05 +00:00
|
|
|
std::unique_ptr<PeerListRow> SearchFromController::createRow(
|
|
|
|
not_null<UserData*> user) const {
|
2017-08-01 15:55:51 +00:00
|
|
|
return std::make_unique<PeerListRow>(user);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Dialogs
|