2019-05-23 21:38:49 +00:00
|
|
|
/*
|
|
|
|
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"
|
2019-05-30 13:12:10 +00:00
|
|
|
#include "data/data_chat.h"
|
2019-05-23 21:38:49 +00:00
|
|
|
#include "ui/widgets/labels.h"
|
|
|
|
#include "ui/wrap/vertical_layout.h"
|
2019-06-12 13:26:04 +00:00
|
|
|
#include "ui/text/text_utilities.h"
|
2019-05-24 10:32:43 +00:00
|
|
|
#include "info/profile/info_profile_button.h"
|
|
|
|
#include "info/profile/info_profile_values.h"
|
2019-05-23 21:38:49 +00:00
|
|
|
#include "boxes/peer_list_box.h"
|
2019-05-24 11:38:48 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
2019-05-24 11:14:02 +00:00
|
|
|
#include "boxes/add_contact_box.h"
|
2019-05-30 12:25:19 +00:00
|
|
|
#include "apiwrap.h"
|
|
|
|
#include "auth_session.h"
|
2019-05-23 21:38:49 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2019-05-24 10:32:43 +00:00
|
|
|
#include "styles/style_info.h"
|
2019-05-23 21:38:49 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2019-05-30 10:54:10 +00:00
|
|
|
constexpr auto kEnableSearchRowsCount = 10;
|
|
|
|
|
2019-05-30 13:12:10 +00:00
|
|
|
class Controller : public PeerListController, public base::has_weak_ptr {
|
2019-05-24 10:32:43 +00:00
|
|
|
public:
|
2019-05-30 10:54:10 +00:00
|
|
|
Controller(
|
|
|
|
not_null<ChannelData*> channel,
|
|
|
|
ChannelData *chat,
|
2019-05-30 13:12:10 +00:00
|
|
|
const std::vector<not_null<PeerData*>> &chats,
|
2019-05-30 10:54:10 +00:00
|
|
|
Fn<void(ChannelData*)> callback);
|
|
|
|
|
|
|
|
void prepare() override;
|
|
|
|
void rowClicked(not_null<PeerListRow*> row) override;
|
|
|
|
int contentWidth() const override;
|
2019-05-24 10:32:43 +00:00
|
|
|
|
|
|
|
private:
|
2019-05-30 12:25:19 +00:00
|
|
|
void choose(not_null<ChannelData*> chat);
|
2019-05-30 13:12:10 +00:00
|
|
|
void choose(not_null<ChatData*> chat);
|
2019-05-30 12:25:19 +00:00
|
|
|
|
2019-05-30 10:54:10 +00:00
|
|
|
not_null<ChannelData*> _channel;
|
|
|
|
ChannelData *_chat = nullptr;
|
2019-05-30 13:12:10 +00:00
|
|
|
std::vector<not_null<PeerData*>> _chats;
|
2019-05-30 10:54:10 +00:00
|
|
|
Fn<void(ChannelData*)> _callback;
|
2019-05-24 10:32:43 +00:00
|
|
|
|
2019-05-30 12:25:19 +00:00
|
|
|
ChannelData *_waitForFull = nullptr;
|
|
|
|
|
2019-05-24 10:32:43 +00:00
|
|
|
};
|
|
|
|
|
2019-05-30 10:54:10 +00:00
|
|
|
Controller::Controller(
|
|
|
|
not_null<ChannelData*> channel,
|
|
|
|
ChannelData *chat,
|
2019-05-30 13:12:10 +00:00
|
|
|
const std::vector<not_null<PeerData*>> &chats,
|
2019-05-30 10:54:10 +00:00
|
|
|
Fn<void(ChannelData*)> callback)
|
|
|
|
: _channel(channel)
|
|
|
|
, _chat(chat)
|
|
|
|
, _chats(std::move(chats))
|
|
|
|
, _callback(std::move(callback)) {
|
2019-05-30 12:25:19 +00:00
|
|
|
base::ObservableViewer(
|
|
|
|
channel->session().api().fullPeerUpdated()
|
|
|
|
) | rpl::start_with_next([=](PeerData *peer) {
|
|
|
|
if (peer == _waitForFull) {
|
|
|
|
choose(std::exchange(_waitForFull, nullptr));
|
|
|
|
}
|
|
|
|
}, lifetime());
|
2019-05-30 10:54:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int Controller::contentWidth() const {
|
|
|
|
return st::boxWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Controller::prepare() {
|
2019-05-30 13:12:10 +00:00
|
|
|
const auto appendRow = [&](not_null<PeerData*> chat) {
|
2019-05-30 10:54:10 +00:00
|
|
|
if (delegate()->peerListFindRow(chat->id)) {
|
|
|
|
return;
|
2019-05-24 10:32:43 +00:00
|
|
|
}
|
2019-05-30 10:54:10 +00:00
|
|
|
auto row = std::make_unique<PeerListRow>(chat);
|
2019-05-30 13:12:10 +00:00
|
|
|
const auto username = chat->userName();
|
|
|
|
row->setCustomStatus(username.isEmpty()
|
2019-05-31 16:47:31 +00:00
|
|
|
? lang(lng_manage_discussion_group_private_status)
|
2019-05-30 13:12:10 +00:00
|
|
|
: ('@' + username));
|
2019-05-30 10:54:10 +00:00
|
|
|
delegate()->peerListAppendRow(std::move(row));
|
2019-05-24 10:32:43 +00:00
|
|
|
};
|
2019-05-30 10:54:10 +00:00
|
|
|
if (_chat) {
|
|
|
|
appendRow(_chat);
|
2019-05-24 10:32:43 +00:00
|
|
|
} else {
|
2019-05-30 10:54:10 +00:00
|
|
|
for (const auto chat : _chats) {
|
|
|
|
appendRow(chat);
|
|
|
|
}
|
|
|
|
if (_chats.size() >= kEnableSearchRowsCount) {
|
|
|
|
delegate()->peerListSetSearchMode(PeerListSearchMode::Enabled);
|
2019-05-24 10:32:43 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-30 10:54:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Controller::rowClicked(not_null<PeerListRow*> row) {
|
|
|
|
if (_chat != nullptr) {
|
|
|
|
Ui::showPeerHistory(_chat, ShowAtUnreadMsgId);
|
|
|
|
return;
|
|
|
|
}
|
2019-05-30 13:12:10 +00:00
|
|
|
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()) {
|
2019-05-30 12:25:19 +00:00
|
|
|
choose(chat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Controller::choose(not_null<ChannelData*> chat) {
|
2019-06-12 20:11:41 +00:00
|
|
|
auto text = lng_manage_discussion_group_sure__rich(
|
2019-05-30 10:54:10 +00:00
|
|
|
lt_group,
|
2019-06-12 13:26:04 +00:00
|
|
|
Ui::Text::Bold(chat->name),
|
2019-05-30 10:54:10 +00:00
|
|
|
lt_channel,
|
2019-06-12 13:26:04 +00:00
|
|
|
Ui::Text::Bold(_channel->name));
|
2019-05-30 10:54:10 +00:00
|
|
|
if (!_channel->isPublic()) {
|
|
|
|
text.append(
|
|
|
|
"\n\n" + lang(lng_manage_linked_channel_private));
|
|
|
|
}
|
2019-05-31 16:47:31 +00:00
|
|
|
if (!chat->isPublic()) {
|
|
|
|
text.append("\n\n" + lang(lng_manage_discussion_group_private));
|
|
|
|
if (chat->hiddenPreHistory()) {
|
|
|
|
text.append("\n\n");
|
2019-06-12 20:11:41 +00:00
|
|
|
text.append(lng_manage_discussion_group_warning__rich(
|
2019-05-31 16:47:31 +00:00
|
|
|
lt_visible,
|
2019-06-12 13:26:04 +00:00
|
|
|
Ui::Text::Bold(lang(lng_manage_discussion_group_visible))));
|
2019-05-31 16:47:31 +00:00
|
|
|
}
|
2019-05-30 12:25:19 +00:00
|
|
|
}
|
2019-05-30 10:54:10 +00:00
|
|
|
const auto box = std::make_shared<QPointer<BoxContent>>();
|
|
|
|
const auto sure = [=] {
|
|
|
|
if (*box) {
|
|
|
|
(*box)->closeBox();
|
|
|
|
}
|
|
|
|
const auto onstack = _callback;
|
|
|
|
onstack(chat);
|
|
|
|
};
|
|
|
|
*box = Ui::show(
|
|
|
|
Box<ConfirmBox>(
|
|
|
|
text,
|
|
|
|
lang(lng_manage_discussion_group_link),
|
|
|
|
sure),
|
|
|
|
LayerOption::KeepOther);
|
2019-05-24 10:32:43 +00:00
|
|
|
}
|
|
|
|
|
2019-05-30 13:12:10 +00:00
|
|
|
void Controller::choose(not_null<ChatData*> chat) {
|
2019-06-12 20:11:41 +00:00
|
|
|
auto text = lng_manage_discussion_group_sure__rich(
|
2019-05-30 13:12:10 +00:00
|
|
|
lt_group,
|
2019-06-12 13:26:04 +00:00
|
|
|
Ui::Text::Bold(chat->name),
|
2019-05-30 13:12:10 +00:00
|
|
|
lt_channel,
|
2019-06-12 13:26:04 +00:00
|
|
|
Ui::Text::Bold(_channel->name));
|
2019-05-30 13:12:10 +00:00
|
|
|
if (!_channel->isPublic()) {
|
|
|
|
text.append(
|
|
|
|
"\n\n" + lang(lng_manage_linked_channel_private));
|
|
|
|
}
|
2019-05-31 16:47:31 +00:00
|
|
|
text.append("\n\n" + lang(lng_manage_discussion_group_private));
|
2019-05-30 13:12:10 +00:00
|
|
|
text.append("\n\n");
|
2019-06-14 12:01:35 +00:00
|
|
|
text.append(lng_manage_discussion_group_warning__rich(
|
2019-05-30 13:12:10 +00:00
|
|
|
lt_visible,
|
2019-06-12 13:26:04 +00:00
|
|
|
Ui::Text::Bold(lang(lng_manage_discussion_group_visible))));
|
2019-05-30 13:12:10 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-05-24 10:32:43 +00:00
|
|
|
object_ptr<Ui::RpWidget> SetupAbout(
|
|
|
|
not_null<QWidget*> parent,
|
|
|
|
not_null<ChannelData*> channel,
|
|
|
|
ChannelData *chat) {
|
|
|
|
auto about = object_ptr<Ui::FlatLabel>(
|
|
|
|
parent,
|
|
|
|
QString(),
|
|
|
|
st::linkedChatAbout);
|
|
|
|
about->setMarkedText([&]() -> TextWithEntities {
|
|
|
|
if (!channel->isBroadcast()) {
|
2019-06-12 20:11:41 +00:00
|
|
|
return lng_manage_linked_channel_about__rich(
|
|
|
|
lt_channel,
|
|
|
|
Ui::Text::Bold(chat->name));
|
2019-05-24 10:32:43 +00:00
|
|
|
} else if (chat != nullptr) {
|
2019-06-12 20:11:41 +00:00
|
|
|
return lng_manage_discussion_group_about_chosen__rich(
|
|
|
|
lt_group,
|
|
|
|
Ui::Text::Bold(chat->name));
|
2019-05-24 10:32:43 +00:00
|
|
|
} else {
|
|
|
|
return { lang(lng_manage_discussion_group_about) };
|
|
|
|
}
|
|
|
|
}());
|
|
|
|
return std::move(about);
|
|
|
|
}
|
|
|
|
|
2019-05-24 11:48:50 +00:00
|
|
|
object_ptr<Ui::RpWidget> SetupFooter(
|
|
|
|
not_null<QWidget*> parent,
|
|
|
|
not_null<ChannelData*> channel) {
|
|
|
|
return object_ptr<Ui::FlatLabel>(
|
|
|
|
parent,
|
|
|
|
lang(channel->isBroadcast()
|
|
|
|
? lng_manage_discussion_group_posted
|
|
|
|
: lng_manage_linked_channel_posted),
|
|
|
|
st::linkedChatAbout);
|
|
|
|
}
|
|
|
|
|
2019-05-24 10:32:43 +00:00
|
|
|
object_ptr<Ui::RpWidget> SetupCreateGroup(
|
|
|
|
not_null<QWidget*> parent,
|
2019-05-24 11:14:02 +00:00
|
|
|
not_null<ChannelData*> channel,
|
|
|
|
Fn<void(ChannelData*)> callback) {
|
|
|
|
Expects(channel->isBroadcast());
|
|
|
|
|
2019-05-24 10:32:43 +00:00
|
|
|
auto result = object_ptr<Info::Profile::Button>(
|
|
|
|
parent,
|
|
|
|
Lang::Viewer(
|
|
|
|
lng_manage_discussion_group_create
|
|
|
|
) | Info::Profile::ToUpperValue(),
|
|
|
|
st::infoCreateLinkedChatButton);
|
|
|
|
result->addClickHandler([=] {
|
2019-05-24 11:14:02 +00:00
|
|
|
const auto guarded = crl::guard(parent, callback);
|
|
|
|
Ui::show(
|
|
|
|
Box<GroupInfoBox>(
|
|
|
|
GroupInfoBox::Type::Megagroup,
|
|
|
|
channel->name + " Chat",
|
|
|
|
guarded),
|
|
|
|
LayerOption::KeepOther);
|
2019-05-24 10:32:43 +00:00
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
object_ptr<Ui::RpWidget> SetupUnlink(
|
|
|
|
not_null<QWidget*> parent,
|
|
|
|
not_null<ChannelData*> channel,
|
|
|
|
Fn<void(ChannelData*)> callback) {
|
|
|
|
auto result = object_ptr<Info::Profile::Button>(
|
|
|
|
parent,
|
|
|
|
Lang::Viewer(channel->isBroadcast()
|
|
|
|
? lng_manage_discussion_group_unlink
|
|
|
|
: lng_manage_linked_channel_unlink
|
|
|
|
) | Info::Profile::ToUpperValue(),
|
|
|
|
st::infoUnlinkChatButton);
|
|
|
|
result->addClickHandler([=] {
|
|
|
|
callback(nullptr);
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-05-30 10:54:10 +00:00
|
|
|
object_ptr<BoxContent> EditLinkedChatBox(
|
2019-05-23 21:38:49 +00:00
|
|
|
not_null<ChannelData*> channel,
|
|
|
|
ChannelData *chat,
|
2019-05-30 13:12:10 +00:00
|
|
|
std::vector<not_null<PeerData*>> &&chats,
|
2019-06-01 08:27:05 +00:00
|
|
|
bool canEdit,
|
2019-05-23 21:38:49 +00:00
|
|
|
Fn<void(ChannelData*)> callback) {
|
2019-06-01 08:27:05 +00:00
|
|
|
Expects((channel->isBroadcast() && canEdit) || (chat != nullptr));
|
2019-05-23 21:38:49 +00:00
|
|
|
|
2019-05-30 10:54:10 +00:00
|
|
|
const auto init = [=](not_null<PeerListBox*> box) {
|
|
|
|
auto above = object_ptr<Ui::VerticalLayout>(box);
|
|
|
|
above->add(
|
|
|
|
SetupAbout(above, channel, chat),
|
|
|
|
st::linkedChatAboutPadding);
|
|
|
|
if (!chat) {
|
|
|
|
above->add(SetupCreateGroup(above, channel, callback));
|
|
|
|
}
|
|
|
|
box->peerListSetAboveWidget(std::move(above));
|
|
|
|
|
|
|
|
auto below = object_ptr<Ui::VerticalLayout>(box);
|
2019-06-01 08:27:05 +00:00
|
|
|
if (chat && canEdit) {
|
2019-05-30 10:54:10 +00:00
|
|
|
below->add(SetupUnlink(below, channel, callback));
|
|
|
|
}
|
|
|
|
below->add(
|
|
|
|
SetupFooter(below, channel),
|
|
|
|
st::linkedChatAboutPadding);
|
|
|
|
box->peerListSetBelowWidget(std::move(below));
|
|
|
|
|
|
|
|
box->setTitle(langFactory(channel->isBroadcast()
|
|
|
|
? lng_manage_discussion_group
|
|
|
|
: lng_manage_linked_channel));
|
|
|
|
box->addButton(langFactory(lng_close), [=] { box->closeBox(); });
|
|
|
|
};
|
|
|
|
auto controller = std::make_unique<Controller>(
|
|
|
|
channel,
|
|
|
|
chat,
|
|
|
|
std::move(chats),
|
|
|
|
std::move(callback));
|
|
|
|
return Box<PeerListBox>(std::move(controller), init);
|
2019-05-23 21:38:49 +00:00
|
|
|
}
|
|
|
|
|
2019-05-30 10:54:10 +00:00
|
|
|
} // namespace
|
2019-05-23 21:38:49 +00:00
|
|
|
|
2019-05-30 10:54:10 +00:00
|
|
|
object_ptr<BoxContent> EditLinkedChatBox(
|
|
|
|
not_null<ChannelData*> channel,
|
2019-05-30 13:12:10 +00:00
|
|
|
std::vector<not_null<PeerData*>> &&chats,
|
2019-05-30 10:54:10 +00:00
|
|
|
Fn<void(ChannelData*)> callback) {
|
2019-06-01 08:27:05 +00:00
|
|
|
return EditLinkedChatBox(
|
|
|
|
channel,
|
|
|
|
nullptr,
|
|
|
|
std::move(chats),
|
|
|
|
true,
|
|
|
|
callback);
|
2019-05-30 10:54:10 +00:00
|
|
|
}
|
2019-05-23 21:38:49 +00:00
|
|
|
|
2019-05-30 10:54:10 +00:00
|
|
|
object_ptr<BoxContent> EditLinkedChatBox(
|
|
|
|
not_null<ChannelData*> channel,
|
|
|
|
not_null<ChannelData*> chat,
|
2019-06-01 08:27:05 +00:00
|
|
|
bool canEdit,
|
2019-05-30 10:54:10 +00:00
|
|
|
Fn<void(ChannelData*)> callback) {
|
2019-06-01 08:27:05 +00:00
|
|
|
return EditLinkedChatBox(channel, chat, {}, canEdit, callback);
|
2019-05-23 21:38:49 +00:00
|
|
|
}
|