tdesktop/Telegram/SourceFiles/dialogs/dialogs_search_from_control...

84 lines
2.2 KiB
C++
Raw Normal View History

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "dialogs/dialogs_search_from_controllers.h"
#include "lang/lang_keys.h"
#include "data/data_peer_values.h"
#include "data/data_channel.h"
#include "data/data_chat.h"
#include "data/data_user.h"
2019-07-24 11:45:24 +00:00
#include "main/main_session.h"
#include "apiwrap.h"
namespace Dialogs {
object_ptr<Ui::BoxContent> SearchFromBox(
not_null<PeerData*> peer,
2020-10-06 12:58:16 +00:00
Fn<void(not_null<PeerData*>)> callback,
Fn<void()> closedCallback) {
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));
}
return nullptr;
};
if (auto controller = createController()) {
auto subscription = std::make_shared<rpl::lifetime>();
auto box = Box<PeerListBox>(
std::move(controller),
[subscription](not_null<PeerListBox*> box) {
box->addButton(tr::lng_cancel(), [box, subscription] {
box->closeBox();
});
2019-01-13 13:28:05 +00:00
});
box->boxClosing() | rpl::start_with_next(
std::move(closedCallback),
*subscription);
return box;
}
return nullptr;
}
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)
: AddSpecialBoxController(
2019-01-13 13:28:05 +00:00
peer,
ParticipantsBoxController::Role::Members,
AdminDoneCallback(),
BannedDoneCallback())
2020-10-06 12:58:16 +00:00
, _callback(std::move(callback)) {
_excludeSelf = false;
}
2019-01-13 13:28:05 +00:00
void SearchFromController::prepare() {
AddSpecialBoxController::prepare();
delegate()->peerListSetTitle(tr::lng_search_messages_from());
2020-10-06 12:58:16 +00:00
if (const auto megagroup = peer()->asMegagroup()) {
if (!delegate()->peerListFindRow(megagroup->id.value)) {
2020-10-06 12:58:16 +00:00
delegate()->peerListAppendRow(
std::make_unique<PeerListRow>(megagroup));
setDescriptionText({});
delegate()->peerListRefreshRows();
}
}
}
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
}
}
} // namespace Dialogs