diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 5b0784284..334110cac 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -5457,6 +5457,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "ayu_SemiTransparentDeletedMessages" = "Translucent Deleted Messages"; "ayu_HideNotificationCounters" = "Hide Notification Counters"; "ayu_HideAllChats" = "Hide \"All Chats\" Tab"; +"ayu_ChannelBottomButton" = "Channel Bottom Button"; +"ayu_ChannelBottomButtonHide" = "Hide"; +"ayu_ChannelBottomButtonMute" = "Mute"; +"ayu_ChannelBottomButtonDiscuss" = "Discuss"; "ayu_SettingsShowID" = "Show Peer ID"; "ayu_SettingsShowID_Hide" = "Hide"; "ayu_SettingsShowMessageShot" = "Show Message Shot"; diff --git a/Telegram/SourceFiles/ayu/ayu_settings.cpp b/Telegram/SourceFiles/ayu/ayu_settings.cpp index 56b6b83ac..887900ed8 100644 --- a/Telegram/SourceFiles/ayu/ayu_settings.cpp +++ b/Telegram/SourceFiles/ayu/ayu_settings.cpp @@ -251,6 +251,13 @@ AyuGramSettings::AyuGramSettings() { hideNotificationCounters = false; hideAllChatsFolder = false; + /* + * channelBottomButton = 0 means "Hide" + * channelBottomButton = 1 means "Mute"/"Unmute" + * channelBottomButton = 2 means "Discuss" + fallback to "Mute"/"Unmute" + */ + channelBottomButton = 2; + /* * showPeerId = 0 means no ID shown * showPeerId = 1 means ID shown as for Telegram API devs @@ -448,6 +455,10 @@ void AyuGramSettings::set_hideAllChatsFolder(bool val) { hideAllChatsFolder = val; } +void AyuGramSettings::set_channelBottomButton(int val) { + channelBottomButton = val; +} + void AyuGramSettings::set_showMessageSeconds(bool val) { showMessageSeconds = val; } diff --git a/Telegram/SourceFiles/ayu/ayu_settings.h b/Telegram/SourceFiles/ayu/ayu_settings.h index ab2b85149..c89b26f19 100644 --- a/Telegram/SourceFiles/ayu/ayu_settings.h +++ b/Telegram/SourceFiles/ayu/ayu_settings.h @@ -69,6 +69,8 @@ public: bool hideNotificationCounters; bool hideAllChatsFolder; + int channelBottomButton; + int showPeerId; bool showMessageSeconds; bool showMessageShot; @@ -131,6 +133,8 @@ public: void set_hideNotificationCounters(bool val); void set_hideAllChatsFolder(bool val); + void set_channelBottomButton(int val); + void set_showPeerId(int val); void set_showMessageSeconds(bool val); void set_showMessageShot(bool val); @@ -181,6 +185,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT( monoFont, hideNotificationCounters, hideAllChatsFolder, + channelBottomButton, showPeerId, showMessageSeconds, showMessageShot, diff --git a/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp b/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp index 9c1b010f7..b56bae7c9 100644 --- a/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp +++ b/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp @@ -343,13 +343,14 @@ void AddCollapsibleToggle(not_null container, raw->lifetime()); } -void AddChooseButtonWithIconAndRightText(not_null container, +void AddChooseButtonWithIconAndRightTextInner(not_null container, not_null controller, int initialState, std::vector options, rpl::producer text, rpl::producer boxTitle, - const style::icon &icon, + const style::SettingsButton & st, + Settings::IconDescriptor && descriptor, const Fn &setter) { auto reactiveVal = container->lifetime().make_state>(initialState); @@ -363,8 +364,8 @@ void AddChooseButtonWithIconAndRightText(not_null container container, std::move(text), rightTextReactive, - st::settingsButton, - {&icon})->addClickHandler( + st, + std::move(descriptor))->addClickHandler( [=] { controller->show(Box( @@ -387,6 +388,45 @@ void AddChooseButtonWithIconAndRightText(not_null container }); } +void AddChooseButtonWithIconAndRightText(not_null container, + not_null controller, + int initialState, + std::vector options, + rpl::producer text, + rpl::producer boxTitle, + const style::icon &icon, + const Fn &setter) { + AddChooseButtonWithIconAndRightTextInner( + container, + controller, + initialState, + options, + std::move(text), + std::move(boxTitle), + st::settingsButton, + {&icon}, + setter); +} + +void AddChooseButtonWithIconAndRightText(not_null container, + not_null controller, + int initialState, + std::vector options, + rpl::producer text, + rpl::producer boxTitle, + const Fn &setter) { + AddChooseButtonWithIconAndRightTextInner( + container, + controller, + initialState, + options, + std::move(text), + std::move(boxTitle), + st::settingsButtonNoIcon, + {}, + setter); +} + namespace Settings { rpl::producer Ayu::title() { @@ -1205,6 +1245,29 @@ void SetupFolderSettings(not_null container) { container->lifetime()); } +void SetupChannelSettings(not_null container, not_null controller) { + auto settings = &AyuSettings::getInstance(); + + const auto options = std::vector{ + tr::ayu_ChannelBottomButtonHide(tr::now), + tr::ayu_ChannelBottomButtonMute(tr::now), + tr::ayu_ChannelBottomButtonDiscuss(tr::now), + }; + + AddChooseButtonWithIconAndRightText( + container, + controller, + settings->channelBottomButton, + options, + tr::ayu_ChannelBottomButton(), + tr::ayu_ChannelBottomButton(), + [=](int index) + { + settings->set_channelBottomButton(index); + AyuSettings::save(); + }); +} + void SetupNerdSettings(not_null container, not_null controller) { auto settings = &AyuSettings::getInstance(); @@ -1318,6 +1381,11 @@ void SetupCustomization(not_null container, AddSkip(container); AddDivider(container); + AddSkip(container); + SetupChannelSettings(container, controller); + AddSkip(container); + AddDivider(container); + AddSkip(container); SetupNerdSettings(container, controller); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 505c1ed64..7b6f70076 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -262,6 +262,9 @@ HistoryWidget::HistoryWidget( this, tr::lng_channel_mute(tr::now).toUpper(), st::historyComposeButton) +, _discuss(this, + tr::ayu_ChannelBottomButtonDiscuss(tr::now).toUpper(), + st::historyComposeButton) , _reportMessages(this, QString(), st::historyComposeButton) , _attachToggle(this, st::historyAttach) , _tabbedSelectorToggle(this, st::historyAttachEmoji) @@ -353,6 +356,7 @@ HistoryWidget::HistoryWidget( _botStart->addClickHandler([=] { sendBotStartCommand(); }); _joinChannel->addClickHandler([=] { joinChannel(); }); _muteUnmute->addClickHandler([=] { toggleMuteUnmute(); }); + _discuss->addClickHandler([=] { goToDiscussionGroup(); }); _reportMessages->addClickHandler([=] { reportSelectedMessages(); }); _field->submits( ) | rpl::start_with_next([=](Qt::KeyboardModifiers modifiers) { @@ -573,6 +577,7 @@ HistoryWidget::HistoryWidget( _botStart->hide(); _joinChannel->hide(); _muteUnmute->hide(); + _discuss->hide(); _reportMessages->hide(); initVoiceRecordBar(); @@ -2978,12 +2983,23 @@ void HistoryWidget::updateControlsVisibility() { toggle(_reportMessages); } else if (isBlocked()) { toggle(_unblock); + _discuss->hide(); } else if (isJoinChannel()) { toggle(_joinChannel); + _discuss->hide(); } else if (isMuteUnmute()) { toggle(_muteUnmute); + if (hasDiscussionGroup()) { + if (_discuss->isHidden()) { + _discuss->clearState(); + _discuss->show(); + } + } else { + _discuss->hide(); + } } else if (isBotStart()) { toggle(_botStart); + _discuss->hide(); } _kbShown = false; _fieldAutocomplete->hide(); @@ -3035,6 +3051,7 @@ void HistoryWidget::updateControlsVisibility() { _botStart->hide(); _joinChannel->hide(); _muteUnmute->hide(); + _discuss->hide(); _reportMessages->hide(); _send->show(); updateSendButtonType(); @@ -3146,6 +3163,7 @@ void HistoryWidget::updateControlsVisibility() { _botStart->hide(); _joinChannel->hide(); _muteUnmute->hide(); + _discuss->hide(); _reportMessages->hide(); _attachToggle->hide(); if (_silent) { @@ -4346,6 +4364,27 @@ void HistoryWidget::toggleMuteUnmute() { session().data().notifySettings().update(_peer, muteForSeconds); } +void HistoryWidget::goToDiscussionGroup() { + const auto channel = _peer ? _peer->asChannel() : nullptr; + const auto chat = channel ? channel->linkedChat() : nullptr; + if (!chat) { + return; + } + controller()->showPeerHistory(chat, Window::SectionShow::Way::Forward); +} + +bool HistoryWidget::hasDiscussionGroup() const { + const auto settings = &AyuSettings::getInstance(); + if (settings->channelBottomButton != 2) { + return false; + } + + const auto channel = _peer ? _peer->asChannel() : nullptr; + return channel + && channel->isBroadcast() + && (channel->flags() & ChannelDataFlag::HasLink); +} + void HistoryWidget::reportSelectedMessages() { if (!_list || !_chooseForReport || !_list->getSelectionState().count) { return; @@ -4884,6 +4923,11 @@ bool HistoryWidget::isChoosingTheme() const { } bool HistoryWidget::isMuteUnmute() const { + const auto settings = &AyuSettings::getInstance(); + if (settings->channelBottomButton == 0) { + return false; + } + return _peer && ((_peer->isBroadcast() && !_peer->asChannel()->canPostMessages()) || (_peer->isGigagroup() && !Data::CanSendAnything(_peer)) @@ -5392,6 +5436,7 @@ void HistoryWidget::moveFieldControls() { _unblock->setGeometry(fullWidthButtonRect); _joinChannel->setGeometry(fullWidthButtonRect); _muteUnmute->setGeometry(fullWidthButtonRect); + _discuss->setGeometry(fullWidthButtonRect); _reportMessages->setGeometry(fullWidthButtonRect); if (_sendRestriction) { _sendRestriction->setGeometry(fullWidthButtonRect); @@ -5842,6 +5887,7 @@ void HistoryWidget::handleHistoryChange(not_null history) { const auto botStart = isBotStart(); const auto joinChannel = isJoinChannel(); const auto muteUnmute = isMuteUnmute(); + const auto discuss = muteUnmute && hasDiscussionGroup(); const auto reportMessages = isReportMessages(); const auto update = false || (_reportMessages->isHidden() == reportMessages) @@ -5857,7 +5903,7 @@ void HistoryWidget::handleHistoryChange(not_null history) { && !unblock && !botStart && !joinChannel - && _muteUnmute->isHidden() == muteUnmute); + && (_muteUnmute->isHidden() == muteUnmute || _discuss->isHidden() == discuss)); if (update) { updateControlsVisibility(); updateControlsGeometry(); @@ -8009,7 +8055,8 @@ void HistoryWidget::handlePeerUpdate() { } if (!_showAnimation) { if (_unblock->isHidden() == isBlocked() - || (!isBlocked() && _joinChannel->isHidden() == isJoinChannel())) { + || (!isBlocked() && _joinChannel->isHidden() == isJoinChannel()) + || (isMuteUnmute() && _discuss->isHidden() == hasDiscussionGroup())) { resize = true; } if (updateCanSendMessage()) { diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index afe6d8d0e..36c326fae 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -424,6 +424,9 @@ private: void unblockUser(); void sendBotStartCommand(); void joinChannel(); + void goToDiscussionGroup(); + + [[nodiscard]] bool hasDiscussionGroup() const; void supportInitAutocomplete(); void supportInsertText(const QString &text); @@ -755,6 +758,7 @@ private: object_ptr _botStart; object_ptr _joinChannel; object_ptr _muteUnmute; + object_ptr _discuss; object_ptr _reportMessages; struct { object_ptr button = { nullptr };