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_discussion_group_add" = "Add a group";
"lng_manage_linked_channel" = "Linked channel"; "lng_manage_linked_channel" = "Linked channel";
"lng_manage_linked_channel_restore" = "Restore 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" = "Select a group chat that will host comments from 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_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_create" = "Create a new group";
"lng_manage_discussion_group_unlink" = "Unlink group"; "lng_manage_discussion_group_unlink" = "Unlink group";
"lng_manage_discussion_group_posted" = "Everything you post in the channel is forwarded to this 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/hint.tgs">../../animations/cloud_password/hint.tgs</file>
<file alias="cloud_password/email.tgs">../../animations/cloud_password/email.tgs</file> <file alias="cloud_password/email.tgs">../../animations/cloud_password/email.tgs</file>
<file alias="ttl.tgs">../../animations/ttl.tgs</file> <file alias="ttl.tgs">../../animations/ttl.tgs</file>
<file alias="discussion.tgs">../../animations/discussion.tgs</file>
</qresource> </qresource>
</RCC> </RCC>

View file

@ -10,6 +10,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 "data/data_chat.h"
#include "settings/settings_common.h"
#include "data/data_changes.h" #include "data/data_changes.h"
#include "ui/widgets/labels.h" #include "ui/widgets/labels.h"
#include "ui/widgets/buttons.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_layers.h"
#include "styles/style_boxes.h" #include "styles/style_boxes.h"
#include "styles/style_info.h" #include "styles/style_info.h"
#include "styles/style_settings.h"
namespace { namespace {
@ -208,47 +210,24 @@ void Controller::choose(not_null<ChatData*> chat) {
Ui::LayerOption::KeepOther); Ui::LayerOption::KeepOther);
} }
object_ptr<Ui::RpWidget> SetupAbout( [[nodiscard]] rpl::producer<TextWithEntities> About(
not_null<QWidget*> parent,
not_null<ChannelData*> channel, not_null<ChannelData*> channel,
ChannelData *chat) { ChannelData *chat) {
auto about = object_ptr<Ui::FlatLabel>( if (!channel->isBroadcast()) {
parent, return tr::lng_manage_linked_channel_about(
QString(), lt_channel,
st::linkedChatAbout); rpl::single(Ui::Text::Bold(chat->name())),
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,
Ui::Text::WithEntities); Ui::Text::WithEntities);
}()); } else if (chat != nullptr) {
return about; 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( [[nodiscard]] object_ptr<Ui::RpWidget> SetupCreateGroup(
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(
not_null<QWidget*> parent, not_null<QWidget*> parent,
not_null<Window::SessionNavigation*> navigation, not_null<Window::SessionNavigation*> navigation,
not_null<ChannelData*> channel, not_null<ChannelData*> channel,
@ -273,23 +252,7 @@ object_ptr<Ui::RpWidget> SetupCreateGroup(
return result; return result;
} }
object_ptr<Ui::RpWidget> SetupUnlink( [[nodiscard]] object_ptr<Ui::BoxContent> EditLinkedChatBox(
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(
not_null<Window::SessionNavigation*> navigation, not_null<Window::SessionNavigation*> navigation,
not_null<ChannelData*> channel, not_null<ChannelData*> channel,
ChannelData *chat, ChannelData *chat,
@ -298,27 +261,61 @@ object_ptr<Ui::BoxContent> EditLinkedChatBox(
Fn<void(ChannelData*)> callback) { Fn<void(ChannelData*)> callback) {
Expects((channel->isBroadcast() && canEdit) || (chat != nullptr)); 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); auto above = object_ptr<Ui::VerticalLayout>(box);
above->add( Settings::AddDividerTextWithLottie(
SetupAbout(above, channel, chat), above,
st::linkedChatAboutPadding); box->showFinishes(),
About(channel, chat),
u"discussion"_q);
if (!chat) { if (!chat) {
above->add(SetupCreateGroup( above->add(
above, SetupCreateGroup(above, navigation, channel, callback));
navigation,
channel,
callback));
} }
box->peerListSetAboveWidget(std::move(above)); box->peerListSetAboveWidget(std::move(above));
auto below = object_ptr<Ui::VerticalLayout>(box); auto below = object_ptr<Ui::VerticalLayout>(box);
if (chat && canEdit) { 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( Settings::AddDividerText(
SetupFooter(below, channel), below,
st::linkedChatAboutPadding); (channel->isBroadcast()
? tr::lng_manage_discussion_group_posted
: tr::lng_manage_linked_channel_posted)());
box->peerListSetBelowWidget(std::move(below)); box->peerListSetBelowWidget(std::move(below));
box->setTitle(channel->isBroadcast() box->setTitle(channel->isBroadcast()
@ -339,7 +336,7 @@ object_ptr<Ui::BoxContent> EditLinkedChatBox(
std::move(chats), std::move(chats),
std::move(callback), std::move(callback),
std::move(showHistoryCallback)); std::move(showHistoryCallback));
return Box<PeerListBox>(std::move(controller), init); return Box<ListBox>(std::move(controller), init);
} }
} // namespace } // namespace

View file

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