Improved style of box for editing of linked chat.

This commit is contained in:
23rd 2023-01-07 08:16:35 +03:00 committed by John Preston
parent c99ac0a264
commit 9e0e28dc45
5 changed files with 69 additions and 71 deletions

Binary file not shown.

View File

@ -1332,8 +1332,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_manage_discussion_group_add" = "Add a group";
"lng_manage_linked_channel" = "Linked channel";
"lng_manage_linked_channel_restore" = "Restore linked channel";
"lng_manage_discussion_group_about" = "Select a group chat for discussion that will be displayed in your channel.";
"lng_manage_discussion_group_about_chosen" = "A link to {group} is shown to all subscribers in the bottom panel.";
"lng_manage_discussion_group_about" = "Select a group chat that will host comments from your channel.";
"lng_manage_discussion_group_about_chosen" = "{group} is selected as the group that hosts comments for your channel.";
"lng_manage_discussion_group_create" = "Create a new group";
"lng_manage_discussion_group_unlink" = "Unlink group";
"lng_manage_discussion_group_posted" = "Everything you post in the channel is forwarded to this group.";

View File

@ -9,5 +9,6 @@
<file alias="cloud_password/hint.tgs">../../animations/cloud_password/hint.tgs</file>
<file alias="cloud_password/email.tgs">../../animations/cloud_password/email.tgs</file>
<file alias="ttl.tgs">../../animations/ttl.tgs</file>
<file alias="discussion.tgs">../../animations/discussion.tgs</file>
</qresource>
</RCC>

View File

@ -10,6 +10,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 "settings/settings_common.h"
#include "data/data_changes.h"
#include "ui/widgets/labels.h"
#include "ui/widgets/buttons.h"
@ -25,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_layers.h"
#include "styles/style_boxes.h"
#include "styles/style_info.h"
#include "styles/style_settings.h"
namespace {
@ -208,47 +210,24 @@ void Controller::choose(not_null<ChatData*> chat) {
Ui::LayerOption::KeepOther);
}
object_ptr<Ui::RpWidget> SetupAbout(
not_null<QWidget*> parent,
[[nodiscard]] rpl::producer<TextWithEntities> About(
not_null<ChannelData*> channel,
ChannelData *chat) {
auto about = object_ptr<Ui::FlatLabel>(
parent,
QString(),
st::linkedChatAbout);
about->setMarkedText([&] {
if (!channel->isBroadcast()) {
return tr::lng_manage_linked_channel_about(
tr::now,
lt_channel,
Ui::Text::Bold(chat->name()),
Ui::Text::WithEntities);
} else if (chat != nullptr) {
return tr::lng_manage_discussion_group_about_chosen(
tr::now,
lt_group,
Ui::Text::Bold(chat->name()),
Ui::Text::WithEntities);
}
return tr::lng_manage_discussion_group_about(
tr::now,
if (!channel->isBroadcast()) {
return tr::lng_manage_linked_channel_about(
lt_channel,
rpl::single(Ui::Text::Bold(chat->name())),
Ui::Text::WithEntities);
}());
return about;
} else if (chat != nullptr) {
return tr::lng_manage_discussion_group_about_chosen(
lt_group,
rpl::single(Ui::Text::Bold(chat->name())),
Ui::Text::WithEntities);
}
return tr::lng_manage_discussion_group_about(Ui::Text::WithEntities);
}
object_ptr<Ui::RpWidget> SetupFooter(
not_null<QWidget*> parent,
not_null<ChannelData*> channel) {
return object_ptr<Ui::FlatLabel>(
parent,
(channel->isBroadcast()
? tr::lng_manage_discussion_group_posted
: tr::lng_manage_linked_channel_posted)(),
st::linkedChatAbout);
}
object_ptr<Ui::RpWidget> SetupCreateGroup(
[[nodiscard]] object_ptr<Ui::RpWidget> SetupCreateGroup(
not_null<QWidget*> parent,
not_null<Window::SessionNavigation*> navigation,
not_null<ChannelData*> channel,
@ -273,23 +252,7 @@ object_ptr<Ui::RpWidget> SetupCreateGroup(
return result;
}
object_ptr<Ui::RpWidget> SetupUnlink(
not_null<QWidget*> parent,
not_null<ChannelData*> channel,
Fn<void(ChannelData*)> callback) {
auto result = object_ptr<Ui::SettingsButton>(
parent,
(channel->isBroadcast()
? tr::lng_manage_discussion_group_unlink
: tr::lng_manage_linked_channel_unlink)() | Ui::Text::ToUpper(),
st::infoUnlinkChatButton);
result->addClickHandler([=] {
callback(nullptr);
});
return result;
}
object_ptr<Ui::BoxContent> EditLinkedChatBox(
[[nodiscard]] object_ptr<Ui::BoxContent> EditLinkedChatBox(
not_null<Window::SessionNavigation*> navigation,
not_null<ChannelData*> channel,
ChannelData *chat,
@ -298,27 +261,61 @@ object_ptr<Ui::BoxContent> EditLinkedChatBox(
Fn<void(ChannelData*)> callback) {
Expects((channel->isBroadcast() && canEdit) || (chat != nullptr));
const auto init = [=](not_null<PeerListBox*> box) {
class ListBox final : public PeerListBox {
public:
ListBox(
QWidget *parent,
std::unique_ptr<PeerListController> controller,
Fn<void(not_null<ListBox*>)> init)
: PeerListBox(
parent,
std::move(controller),
[=](not_null<PeerListBox*>) { init(this); }) {
}
void showFinished() override {
_showFinished.fire({});
}
rpl::producer<> showFinishes() const {
return _showFinished.events();
}
private:
rpl::event_stream<> _showFinished;
};
const auto init = [=](not_null<ListBox*> box) {
auto above = object_ptr<Ui::VerticalLayout>(box);
above->add(
SetupAbout(above, channel, chat),
st::linkedChatAboutPadding);
Settings::AddDividerTextWithLottie(
above,
box->showFinishes(),
About(channel, chat),
u"discussion"_q);
if (!chat) {
above->add(SetupCreateGroup(
above,
navigation,
channel,
callback));
above->add(
SetupCreateGroup(above, navigation, channel, callback));
}
box->peerListSetAboveWidget(std::move(above));
auto below = object_ptr<Ui::VerticalLayout>(box);
if (chat && canEdit) {
below->add(SetupUnlink(below, channel, callback));
Settings::AddButton(
below,
(channel->isBroadcast()
? tr::lng_manage_discussion_group_unlink
: tr::lng_manage_linked_channel_unlink)(),
st::infoUnlinkChatButton,
{ &st::settingsIconMinus, Settings::kIconRed }
)->addClickHandler([=] { callback(nullptr); });
Settings::AddSkip(below);
}
below->add(
SetupFooter(below, channel),
st::linkedChatAboutPadding);
Settings::AddDividerText(
below,
(channel->isBroadcast()
? tr::lng_manage_discussion_group_posted
: tr::lng_manage_linked_channel_posted)());
box->peerListSetBelowWidget(std::move(below));
box->setTitle(channel->isBroadcast()
@ -339,7 +336,7 @@ object_ptr<Ui::BoxContent> EditLinkedChatBox(
std::move(chats),
std::move(callback),
std::move(showHistoryCallback));
return Box<PeerListBox>(std::move(controller), init);
return Box<ListBox>(std::move(controller), init);
}
} // namespace

View File

@ -17,14 +17,14 @@ namespace Window {
class SessionNavigation;
} // namespace Window
object_ptr<Ui::BoxContent> EditLinkedChatBox(
[[nodiscard]] object_ptr<Ui::BoxContent> EditLinkedChatBox(
not_null<Window::SessionNavigation*> navigation,
not_null<ChannelData*> channel,
not_null<ChannelData*> chat,
bool canEdit,
Fn<void(ChannelData*)> callback);
object_ptr<Ui::BoxContent> EditLinkedChatBox(
[[nodiscard]] object_ptr<Ui::BoxContent> EditLinkedChatBox(
not_null<Window::SessionNavigation*> navigation,
not_null<ChannelData*> channel,
std::vector<not_null<PeerData*>> &&chats,