/* 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 "boxes/peers/edit_linked_chat_box.h" #include "lang/lang_keys.h" #include "data/data_channel.h" #include "ui/widgets/labels.h" #include "ui/wrap/vertical_layout.h" #include "boxes/peer_list_box.h" #include "styles/style_boxes.h" namespace { TextWithEntities BoldText(const QString &text) { auto result = TextWithEntities{ text }; result.entities.push_back( EntityInText(EntityType::Bold, 0, text.size())); return result; } } // namespace EditLinkedChatBox::EditLinkedChatBox( QWidget*, not_null channel, const std::vector> &chats, Fn callback) : _channel(channel) , _content(setupContent(channel, nullptr, chats, callback)) { } EditLinkedChatBox::EditLinkedChatBox( QWidget*, not_null channel, not_null chat, Fn callback) : _channel(channel) , _content(setupContent(channel, chat, {}, callback)) { } object_ptr EditLinkedChatBox::setupContent( not_null channel, ChannelData *chat, const std::vector> &chats, Fn callback) { Expects(channel->isBroadcast() || (chat != nullptr)); auto result = object_ptr(this); const auto about = result->add( object_ptr( result, QString(), Ui::FlatLabel::InitType::Simple, st::linkedChatAbout), st::linkedChatAboutPadding); about->setMarkedText([&]() -> TextWithEntities { if (!channel->isBroadcast()) { return lng_manage_linked_channel_about__generic< TextWithEntities >(lt_channel, BoldText(chat->name)); } else if (chat != nullptr) { return lng_manage_discussion_group_about_chosen__generic< TextWithEntities >(lt_group, BoldText(chat->name)); } else { return { lang(lng_manage_discussion_group_about) }; } }()); class ListController : public PeerListController , public PeerListContentDelegate { public: ListController(Fn)> callback) : _callback(std::move(callback)) { } void prepare() override { } void rowClicked(not_null row) override { _callback(row->peer()->asChannel()); } void peerListSetTitle(Fn title) override { } void peerListSetAdditionalTitle(Fn title) override { } bool peerListIsRowSelected(not_null peer) override { return false; } int peerListSelectedRowsCount() override { return 0; } auto peerListCollectSelectedRows() -> std::vector> override { return {}; } void peerListScrollToTop() override { } void peerListAddSelectedRowInBunch( not_null peer) override { } void peerListFinishSelectedRowsBunch() override { } void peerListSetDescription( object_ptr description) override { } private: Fn)> _callback; }; const auto controller = Ui::CreateChild(this, [=](not_null chat) { const auto onstack = callback; onstack(chat); }); controller->setDelegate(controller); const auto list = result->add(object_ptr( this, controller, st::peerListBox)); const auto createRow = [](not_null chat) { auto result = std::make_unique(chat); result->setCustomStatus(chat->isPublic() ? ('@' + chat->username) : lang(lng_manage_discussion_group_private)); return result; }; if (chat) { list->appendRow(createRow(chat)); } else { for (const auto chat : chats) { list->appendRow(createRow(chat)); } } return result; } void EditLinkedChatBox::prepare() { setTitle(langFactory(_channel->isBroadcast() ? lng_manage_discussion_group : lng_manage_linked_channel)); setDimensionsToContent( st::boxWidth, setInnerWidget(std::move(_content))); addButton(langFactory(lng_close), [=] { closeBox(); }); }