diff --git a/Telegram/SourceFiles/boxes/peers/edit_linked_chat_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_linked_chat_box.cpp index fa2f5b00f4..7b848fa4db 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_linked_chat_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_linked_chat_box.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "data/data_channel.h" +#include "data/data_chat.h" #include "ui/widgets/labels.h" #include "ui/wrap/vertical_layout.h" #include "info/profile/info_profile_button.h" @@ -32,12 +33,12 @@ TextWithEntities BoldText(const QString &text) { return result; } -class Controller : public PeerListController { +class Controller : public PeerListController, public base::has_weak_ptr { public: Controller( not_null channel, ChannelData *chat, - const std::vector> &chats, + const std::vector> &chats, Fn callback); void prepare() override; @@ -46,10 +47,11 @@ public: private: void choose(not_null chat); + void choose(not_null chat); not_null _channel; ChannelData *_chat = nullptr; - std::vector> _chats; + std::vector> _chats; Fn _callback; ChannelData *_waitForFull = nullptr; @@ -59,7 +61,7 @@ private: Controller::Controller( not_null channel, ChannelData *chat, - const std::vector> &chats, + const std::vector> &chats, Fn callback) : _channel(channel) , _chat(chat) @@ -79,14 +81,15 @@ int Controller::contentWidth() const { } void Controller::prepare() { - const auto appendRow = [&](not_null chat) { + const auto appendRow = [&](not_null chat) { if (delegate()->peerListFindRow(chat->id)) { return; } auto row = std::make_unique(chat); - row->setCustomStatus(chat->isPublic() - ? ('@' + chat->username) - : lang(lng_manage_discussion_group_private)); + const auto username = chat->userName(); + row->setCustomStatus(username.isEmpty() + ? lang(lng_manage_discussion_group_private) + : ('@' + username)); delegate()->peerListAppendRow(std::move(row)); }; if (_chat) { @@ -106,13 +109,17 @@ void Controller::rowClicked(not_null row) { Ui::showPeerHistory(_chat, ShowAtUnreadMsgId); return; } - const auto chat = row->peer()->asChannel(); - if (chat->wasFullUpdated()) { + const auto peer = row->peer(); + if (const auto channel = peer->asChannel()) { + if (channel->wasFullUpdated()) { + choose(channel); + return; + } + _waitForFull = channel; + channel->updateFull(); + } else if (const auto chat = peer->asChat()) { choose(chat); - return; } - _waitForFull = chat; - chat->updateFull(); } void Controller::choose(not_null chat) { @@ -149,6 +156,41 @@ void Controller::choose(not_null chat) { LayerOption::KeepOther); } +void Controller::choose(not_null chat) { + auto text = lng_manage_discussion_group_sure__generic< + TextWithEntities + >( + lt_group, + BoldText(chat->name), + lt_channel, + BoldText(_channel->name)); + if (!_channel->isPublic()) { + text.append( + "\n\n" + lang(lng_manage_linked_channel_private)); + } + text.append("\n\n"); + text.append(lng_manage_discussion_group_warning__generic( + lt_visible, + BoldText(lang(lng_manage_discussion_group_visible)))); + const auto box = std::make_shared>(); + const auto sure = [=] { + if (*box) { + (*box)->closeBox(); + } + const auto done = [=](not_null chat) { + const auto onstack = _callback; + onstack(chat); + }; + chat->session().api().migrateChat(chat, crl::guard(this, done)); + }; + *box = Ui::show( + Box( + text, + lang(lng_manage_discussion_group_link), + sure), + LayerOption::KeepOther); +} + object_ptr SetupAbout( not_null parent, not_null channel, @@ -230,7 +272,7 @@ object_ptr SetupUnlink( object_ptr EditLinkedChatBox( not_null channel, ChannelData *chat, - std::vector> &&chats, + std::vector> &&chats, Fn callback) { Expects(channel->isBroadcast() || (chat != nullptr)); @@ -270,7 +312,7 @@ object_ptr EditLinkedChatBox( object_ptr EditLinkedChatBox( not_null channel, - std::vector> &&chats, + std::vector> &&chats, Fn callback) { return EditLinkedChatBox(channel, nullptr, std::move(chats), callback); } diff --git a/Telegram/SourceFiles/boxes/peers/edit_linked_chat_box.h b/Telegram/SourceFiles/boxes/peers/edit_linked_chat_box.h index 77e36a6d77..0962dfddab 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_linked_chat_box.h +++ b/Telegram/SourceFiles/boxes/peers/edit_linked_chat_box.h @@ -16,5 +16,5 @@ object_ptr EditLinkedChatBox( object_ptr EditLinkedChatBox( not_null channel, - std::vector> &&chats, + std::vector> &&chats, Fn callback); diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index e44e9cc71e..e6530ca944 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -543,14 +543,10 @@ void Controller::showEditLinkedChatBox() { const auto list = result.match([&](const auto &data) { return data.vchats.v; }); - auto chats = std::vector>(); + auto chats = std::vector>(); chats.reserve(list.size()); for (const auto &item : list) { - const auto chat = _peer->owner().processChat(item); - if (chat->isChannel()) { - chats.emplace_back(chat->asChannel()); - } else if (chat->isChat()) { - } + chats.emplace_back(_peer->owner().processChat(item)); } *box = Ui::show( EditLinkedChatBox(channel, std::move(chats), callback),