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"
|
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(
|
|
|
|
not_null<PeerData*> peer,
|
2020-10-06 12:58:16 +00:00
|
|
|
Fn<void(not_null<PeerData*>)> callback,
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void()> closedCallback) {
|
2017-12-04 07:33:33 +00:00
|
|
|
auto createController = [
|
|
|
|
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>(
|
|
|
|
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();
|
|
|
|
});
|
2019-09-18 11:19:05 +00:00
|
|
|
}), Ui::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(
|
|
|
|
not_null<PeerData*> peer,
|
2020-10-06 12:58:16 +00:00
|
|
|
Fn<void(not_null<PeerData*>)> callback)
|
2019-09-09 07:05:29 +00:00
|
|
|
: AddSpecialBoxController(
|
2019-01-13 13:28:05 +00:00
|
|
|
peer,
|
2019-09-09 07:05:29 +00:00
|
|
|
ParticipantsBoxController::Role::Members,
|
|
|
|
AdminDoneCallback(),
|
|
|
|
BannedDoneCallback())
|
2020-10-06 12:58:16 +00:00
|
|
|
, _callback(std::move(callback)) {
|
2019-09-09 07:05:29 +00:00
|
|
|
_excludeSelf = false;
|
2017-08-01 15:55:51 +00:00
|
|
|
}
|
|
|
|
|
2019-01-13 13:28:05 +00:00
|
|
|
void SearchFromController::prepare() {
|
2019-09-09 07:05:29 +00:00
|
|
|
AddSpecialBoxController::prepare();
|
2019-06-18 15:00:55 +00:00
|
|
|
delegate()->peerListSetTitle(tr::lng_search_messages_from());
|
2020-10-06 12:58:16 +00:00
|
|
|
if (const auto megagroup = peer()->asMegagroup()) {
|
2021-04-01 21:04:10 +00:00
|
|
|
if (!delegate()->peerListFindRow(megagroup->id.value)) {
|
2020-10-06 12:58:16 +00:00
|
|
|
delegate()->peerListAppendRow(
|
|
|
|
std::make_unique<PeerListRow>(megagroup));
|
|
|
|
setDescriptionText({});
|
|
|
|
delegate()->peerListRefreshRows();
|
|
|
|
}
|
|
|
|
}
|
2017-08-01 15:55:51 +00:00
|
|
|
}
|
|
|
|
|
2019-01-13 13:28:05 +00:00
|
|
|
void SearchFromController::rowClicked(not_null<PeerListRow*> row) {
|
|
|
|
if (const auto onstack = base::duplicate(_callback)) {
|
2020-10-06 12:58:16 +00:00
|
|
|
onstack(row->peer());
|
2019-01-13 13:28:05 +00:00
|
|
|
}
|
2017-08-01 15:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Dialogs
|