Auto-convert legacy groups for discussions.

This commit is contained in:
John Preston 2019-05-30 16:12:10 +03:00
parent f1c7409980
commit 56d3e69399
3 changed files with 60 additions and 22 deletions

View File

@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "data/data_channel.h" #include "data/data_channel.h"
#include "data/data_chat.h"
#include "ui/widgets/labels.h" #include "ui/widgets/labels.h"
#include "ui/wrap/vertical_layout.h" #include "ui/wrap/vertical_layout.h"
#include "info/profile/info_profile_button.h" #include "info/profile/info_profile_button.h"
@ -32,12 +33,12 @@ TextWithEntities BoldText(const QString &text) {
return result; return result;
} }
class Controller : public PeerListController { class Controller : public PeerListController, public base::has_weak_ptr {
public: public:
Controller( Controller(
not_null<ChannelData*> channel, not_null<ChannelData*> channel,
ChannelData *chat, ChannelData *chat,
const std::vector<not_null<ChannelData*>> &chats, const std::vector<not_null<PeerData*>> &chats,
Fn<void(ChannelData*)> callback); Fn<void(ChannelData*)> callback);
void prepare() override; void prepare() override;
@ -46,10 +47,11 @@ public:
private: private:
void choose(not_null<ChannelData*> chat); void choose(not_null<ChannelData*> chat);
void choose(not_null<ChatData*> chat);
not_null<ChannelData*> _channel; not_null<ChannelData*> _channel;
ChannelData *_chat = nullptr; ChannelData *_chat = nullptr;
std::vector<not_null<ChannelData*>> _chats; std::vector<not_null<PeerData*>> _chats;
Fn<void(ChannelData*)> _callback; Fn<void(ChannelData*)> _callback;
ChannelData *_waitForFull = nullptr; ChannelData *_waitForFull = nullptr;
@ -59,7 +61,7 @@ private:
Controller::Controller( Controller::Controller(
not_null<ChannelData*> channel, not_null<ChannelData*> channel,
ChannelData *chat, ChannelData *chat,
const std::vector<not_null<ChannelData*>> &chats, const std::vector<not_null<PeerData*>> &chats,
Fn<void(ChannelData*)> callback) Fn<void(ChannelData*)> callback)
: _channel(channel) : _channel(channel)
, _chat(chat) , _chat(chat)
@ -79,14 +81,15 @@ int Controller::contentWidth() const {
} }
void Controller::prepare() { void Controller::prepare() {
const auto appendRow = [&](not_null<ChannelData*> chat) { const auto appendRow = [&](not_null<PeerData*> chat) {
if (delegate()->peerListFindRow(chat->id)) { if (delegate()->peerListFindRow(chat->id)) {
return; return;
} }
auto row = std::make_unique<PeerListRow>(chat); auto row = std::make_unique<PeerListRow>(chat);
row->setCustomStatus(chat->isPublic() const auto username = chat->userName();
? ('@' + chat->username) row->setCustomStatus(username.isEmpty()
: lang(lng_manage_discussion_group_private)); ? lang(lng_manage_discussion_group_private)
: ('@' + username));
delegate()->peerListAppendRow(std::move(row)); delegate()->peerListAppendRow(std::move(row));
}; };
if (_chat) { if (_chat) {
@ -106,13 +109,17 @@ void Controller::rowClicked(not_null<PeerListRow*> row) {
Ui::showPeerHistory(_chat, ShowAtUnreadMsgId); Ui::showPeerHistory(_chat, ShowAtUnreadMsgId);
return; return;
} }
const auto chat = row->peer()->asChannel(); const auto peer = row->peer();
if (chat->wasFullUpdated()) { 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); choose(chat);
return;
} }
_waitForFull = chat;
chat->updateFull();
} }
void Controller::choose(not_null<ChannelData*> chat) { void Controller::choose(not_null<ChannelData*> chat) {
@ -149,6 +156,41 @@ void Controller::choose(not_null<ChannelData*> chat) {
LayerOption::KeepOther); LayerOption::KeepOther);
} }
void Controller::choose(not_null<ChatData*> 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<QPointer<BoxContent>>();
const auto sure = [=] {
if (*box) {
(*box)->closeBox();
}
const auto done = [=](not_null<ChannelData*> chat) {
const auto onstack = _callback;
onstack(chat);
};
chat->session().api().migrateChat(chat, crl::guard(this, done));
};
*box = Ui::show(
Box<ConfirmBox>(
text,
lang(lng_manage_discussion_group_link),
sure),
LayerOption::KeepOther);
}
object_ptr<Ui::RpWidget> SetupAbout( object_ptr<Ui::RpWidget> SetupAbout(
not_null<QWidget*> parent, not_null<QWidget*> parent,
not_null<ChannelData*> channel, not_null<ChannelData*> channel,
@ -230,7 +272,7 @@ object_ptr<Ui::RpWidget> SetupUnlink(
object_ptr<BoxContent> EditLinkedChatBox( object_ptr<BoxContent> EditLinkedChatBox(
not_null<ChannelData*> channel, not_null<ChannelData*> channel,
ChannelData *chat, ChannelData *chat,
std::vector<not_null<ChannelData*>> &&chats, std::vector<not_null<PeerData*>> &&chats,
Fn<void(ChannelData*)> callback) { Fn<void(ChannelData*)> callback) {
Expects(channel->isBroadcast() || (chat != nullptr)); Expects(channel->isBroadcast() || (chat != nullptr));
@ -270,7 +312,7 @@ object_ptr<BoxContent> EditLinkedChatBox(
object_ptr<BoxContent> EditLinkedChatBox( object_ptr<BoxContent> EditLinkedChatBox(
not_null<ChannelData*> channel, not_null<ChannelData*> channel,
std::vector<not_null<ChannelData*>> &&chats, std::vector<not_null<PeerData*>> &&chats,
Fn<void(ChannelData*)> callback) { Fn<void(ChannelData*)> callback) {
return EditLinkedChatBox(channel, nullptr, std::move(chats), callback); return EditLinkedChatBox(channel, nullptr, std::move(chats), callback);
} }

View File

@ -16,5 +16,5 @@ object_ptr<BoxContent> EditLinkedChatBox(
object_ptr<BoxContent> EditLinkedChatBox( object_ptr<BoxContent> EditLinkedChatBox(
not_null<ChannelData*> channel, not_null<ChannelData*> channel,
std::vector<not_null<ChannelData*>> &&chats, std::vector<not_null<PeerData*>> &&chats,
Fn<void(ChannelData*)> callback); Fn<void(ChannelData*)> callback);

View File

@ -543,14 +543,10 @@ void Controller::showEditLinkedChatBox() {
const auto list = result.match([&](const auto &data) { const auto list = result.match([&](const auto &data) {
return data.vchats.v; return data.vchats.v;
}); });
auto chats = std::vector<not_null<ChannelData*>>(); auto chats = std::vector<not_null<PeerData*>>();
chats.reserve(list.size()); chats.reserve(list.size());
for (const auto &item : list) { for (const auto &item : list) {
const auto chat = _peer->owner().processChat(item); chats.emplace_back(_peer->owner().processChat(item));
if (chat->isChannel()) {
chats.emplace_back(chat->asChannel());
} else if (chat->isChat()) {
}
} }
*box = Ui::show( *box = Ui::show(
EditLinkedChatBox(channel, std::move(chats), callback), EditLinkedChatBox(channel, std::move(chats), callback),