From 3bbb9daa34e5c463b6b0656c28d56a163d88c53b Mon Sep 17 00:00:00 2001 From: Neurotoxin001 <39812401+Neurotoxin001@users.noreply.github.com> Date: Sun, 6 Jul 2025 17:22:26 +0300 Subject: [PATCH] feat: disable reactions in channels and groups --- Telegram/Resources/langs/lang.strings | 2 + .../SourceFiles/api/api_unread_things.cpp | 16 ++++++- Telegram/SourceFiles/ayu/ayu_settings.cpp | 10 +++++ Telegram/SourceFiles/ayu/ayu_settings.h | 8 ++++ .../ayu/ui/settings/settings_ayu.cpp | 42 +++++++++++++++++++ Telegram/SourceFiles/history/history.cpp | 6 ++- .../history/history_inner_widget.cpp | 11 ++++- .../history/history_item_helpers.cpp | 7 ++++ .../view/reactions/history_view_reactions.cpp | 38 ++++++++++++----- .../media/stories/media_stories_reactions.cpp | 5 ++- 10 files changed, 129 insertions(+), 16 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 779778df3e..bd31ff3430 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -6643,6 +6643,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "ayu_DisableAds" = "Disable Ads"; "ayu_DisableStories" = "Disable Stories"; "ayu_DisableCustomBackgrounds" = "Disable Custom Backgrounds"; +"ayu_HideChannelReactions" = "Hide Reactions in Channels"; +"ayu_HideGroupReactions" = "Hide Reactions in Groups"; "ayu_DisableNotificationsDelay" = "Disable Notify Delay"; "ayu_LocalPremium" = "Local Telegram Premium"; "ayu_DisplayGhostStatus" = "Display Ghost Mode Status"; diff --git a/Telegram/SourceFiles/api/api_unread_things.cpp b/Telegram/SourceFiles/api/api_unread_things.cpp index dac998dfdc..ba1359caba 100644 --- a/Telegram/SourceFiles/api/api_unread_things.cpp +++ b/Telegram/SourceFiles/api/api_unread_things.cpp @@ -17,6 +17,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_unread_things.h" #include "apiwrap.h" +// AyuGram includes +#include "ayu/ayu_settings.h" + + namespace Api { namespace { @@ -36,7 +40,17 @@ bool UnreadThings::trackMentions(Data::Thread *thread) const { bool UnreadThings::trackReactions(Data::Thread *thread) const { const auto peer = thread ? thread->peer().get() : nullptr; - return peer && (peer->isUser() || peer->isChat() || peer->isMegagroup()); + if (!peer) { + return false; + } + const auto &settings = AyuSettings::getInstance(); + if (peer->isChannel() && !peer->isMegagroup() && !settings.hideChannelReactions) { + return false; + } + if (peer->isMegagroup() && !settings.hideGroupReactions) { + return false; + } + return peer->isUser() || peer->isChat() || peer->isMegagroup(); } void UnreadThings::preloadEnough(Data::Thread *thread) { diff --git a/Telegram/SourceFiles/ayu/ayu_settings.cpp b/Telegram/SourceFiles/ayu/ayu_settings.cpp index f38b86d612..f6bb469bd2 100644 --- a/Telegram/SourceFiles/ayu/ayu_settings.cpp +++ b/Telegram/SourceFiles/ayu/ayu_settings.cpp @@ -231,6 +231,8 @@ AyuGramSettings::AyuGramSettings() { disableNotificationsDelay = false; localPremium = false; + hideChannelReactions = true; + hideGroupReactions = true; // ~ Customization appIcon = @@ -417,6 +419,14 @@ void set_localPremium(bool val) { settings->localPremium = val; } +void set_hideChannelReactions(bool val) { + settings->hideChannelReactions = val; +} + +void set_hideGroupReactions(bool val) { + settings->hideGroupReactions = val; +} + void set_appIcon(const QString &val) { settings->appIcon = val; } diff --git a/Telegram/SourceFiles/ayu/ayu_settings.h b/Telegram/SourceFiles/ayu/ayu_settings.h index 017cf313a1..192e59f2ee 100644 --- a/Telegram/SourceFiles/ayu/ayu_settings.h +++ b/Telegram/SourceFiles/ayu/ayu_settings.h @@ -76,6 +76,8 @@ public: bool disableNotificationsDelay; bool localPremium; + bool hideChannelReactions; + bool hideGroupReactions; QString appIcon; bool simpleQuotesAndReplies; @@ -158,6 +160,8 @@ void set_increaseWebviewWidth(bool val); void set_disableNotificationsDelay(bool val); void set_localPremium(bool val); +void set_hideChannelReactions(bool val); +void set_hideGroupReactions(bool val); void set_appIcon(const QString &val); void set_simpleQuotesAndReplies(bool val); @@ -255,6 +259,8 @@ inline void to_json(nlohmann::json &nlohmann_json_j, const AyuGramSettings &nloh NLOHMANN_JSON_TO(showGhostToggleInTray) NLOHMANN_JSON_TO(showStreamerToggleInTray) NLOHMANN_JSON_TO(monoFont) + NLOHMANN_JSON_TO(hideChannelReactions) + NLOHMANN_JSON_TO(hideGroupReactions) NLOHMANN_JSON_TO(hideNotificationCounters) NLOHMANN_JSON_TO(hideNotificationBadge) NLOHMANN_JSON_TO(hideAllChatsFolder) @@ -318,6 +324,8 @@ inline void from_json(const nlohmann::json &nlohmann_json_j, AyuGramSettings &nl NLOHMANN_JSON_FROM_WITH_DEFAULT(showGhostToggleInTray) NLOHMANN_JSON_FROM_WITH_DEFAULT(showStreamerToggleInTray) NLOHMANN_JSON_FROM_WITH_DEFAULT(monoFont) + NLOHMANN_JSON_FROM_WITH_DEFAULT(hideChannelReactions) + NLOHMANN_JSON_FROM_WITH_DEFAULT(hideGroupReactions) NLOHMANN_JSON_FROM_WITH_DEFAULT(hideNotificationCounters) NLOHMANN_JSON_FROM_WITH_DEFAULT(hideNotificationBadge) NLOHMANN_JSON_FROM_WITH_DEFAULT(hideAllChatsFolder) diff --git a/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp b/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp index 520ea113b9..298bbb667d 100644 --- a/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp +++ b/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp @@ -845,6 +845,48 @@ void SetupQoLToggles(not_null container) { AyuSettings::save(); }, container->lifetime()); + + AddSkip(container); + AddDivider(container); + AddSkip(container); + + AddButtonWithIcon( + container, + tr::ayu_HideChannelReactions(), + st::settingsButtonNoIcon + )->toggleOn( + rpl::single(!settings->hideChannelReactions) + )->toggledValue( + ) | rpl::filter( + [=](bool enabled) + { + return (!enabled != settings->hideChannelReactions); + }) | start_with_next( + [=](bool enabled) + { + AyuSettings::set_hideChannelReactions(!enabled); + AyuSettings::save(); + }, + container->lifetime()); + + AddButtonWithIcon( + container, + tr::ayu_HideGroupReactions(), + st::settingsButtonNoIcon + )->toggleOn( + rpl::single(!settings->hideGroupReactions) + )->toggledValue( + ) | rpl::filter( + [=](bool enabled) + { + return (!enabled != settings->hideGroupReactions); + }) | start_with_next( + [=](bool enabled) + { + AyuSettings::set_hideGroupReactions(!enabled); + AyuSettings::save(); + }, + container->lifetime()); } void SetupAppIcon(not_null container) { diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index 660eecf750..292fdd6cb3 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -2279,7 +2279,11 @@ Dialogs::UnreadState History::computeUnreadState() const { result.chats = count ? 1 : 0; result.marks = mark ? 1 : 0; result.mentions = unreadMentions().has() ? 1 : 0; - result.reactions = unreadReactions().has() ? 1 : 0; + const auto peer = this->peer.get(); + const auto &settings = AyuSettings::getInstance(); + const auto hideReactions = (peer->isChannel() && !peer->isMegagroup() && !settings.hideChannelReactions) + || (peer->isMegagroup() && !settings.hideGroupReactions); + result.reactions = hideReactions ? 0 : (unreadReactions().has() ? 1 : 0); result.messagesMuted = muted ? result.messages : 0; result.chatsMuted = muted ? result.chats : 0; result.marksMuted = muted ? result.marks : 0; diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index c6d4474a41..632fdae1ae 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -101,6 +101,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include // AyuGram includes +#include "ayu/ayu_settings.h" #include "ayu/ui/context_menu/context_menu.h" #include "ayu/utils/telegram_helpers.h" #include "data/data_document_media.h" @@ -1152,7 +1153,15 @@ void HistoryInner::paintEvent(QPaintEvent *e) { readTill = item; } if (markingAsViewed && item->hasUnwatchedEffect()) { - startEffects.emplace(view); + const auto peer = item->history()->peer; + const auto &settings = AyuSettings::getInstance(); + const auto hide = (!settings.hideChannelReactions && peer->isChannel() && !peer->isMegagroup()) || + (!settings.hideGroupReactions && peer->isMegagroup()); + if (!hide) { + startEffects.emplace(view); + } else { + item->markEffectWatched(); + } } if (markingAsViewed && item->hasViews()) { session().api().views().scheduleIncrement(item); diff --git a/Telegram/SourceFiles/history/history_item_helpers.cpp b/Telegram/SourceFiles/history/history_item_helpers.cpp index 715c91095d..923fcbfd23 100644 --- a/Telegram/SourceFiles/history/history_item_helpers.cpp +++ b/Telegram/SourceFiles/history/history_item_helpers.cpp @@ -1081,6 +1081,13 @@ void CheckReactionNotificationSchedule( if (!item->hasUnreadReaction()) { return; } + const auto peer = item->history()->peer; + const auto &settings = AyuSettings::getInstance(); + if ((peer->isChannel() && !peer->isMegagroup() && !settings.hideChannelReactions) + || (peer->isMegagroup() && !settings.hideGroupReactions)) { + item->markEffectWatched(); + return; + } for (const auto &[emoji, reactions] : item->recentReactions()) { for (const auto &reaction : reactions) { if (!reaction.unread) { diff --git a/Telegram/SourceFiles/history/view/reactions/history_view_reactions.cpp b/Telegram/SourceFiles/history/view/reactions/history_view_reactions.cpp index 1935119101..5daa9f48f8 100644 --- a/Telegram/SourceFiles/history/view/reactions/history_view_reactions.cpp +++ b/Telegram/SourceFiles/history/view/reactions/history_view_reactions.cpp @@ -29,6 +29,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_chat_helpers.h" // AyuGram includes +#include "ayu/ayu_settings.h" #include "ayu/features/messageshot/message_shot.h" @@ -101,9 +102,12 @@ std::vector InlineList::computeTagsList() const { if (!areTags()) { return {}; } - return _buttons | ranges::views::transform( - &Button::id - ) | ranges::to_vector; + auto result = std::vector(); + result.reserve(_buttons.size()); + for (const auto &button : _buttons) { + result.push_back(button.id); + } + return result; } bool InlineList::hasCustomEmoji() const { @@ -132,11 +136,11 @@ void InlineList::layoutButtons() { _buttons.clear(); return; } - auto sorted = ranges::views::all( - _data.reactions - ) | ranges::views::transform([](const MessageReaction &reaction) { - return not_null{ &reaction }; - }) | ranges::to_vector; + auto sorted = std::vector>(); + sorted.reserve(_data.reactions.size()); + for (const auto &reaction : _data.reactions) { + sorted.push_back(&reaction); + } const auto tags = areTags(); if (!tags) { const auto &list = _owner->list(::Data::Reactions::Type::All); @@ -830,6 +834,16 @@ void InlineList::continueAnimations(base::flat_map< InlineListData InlineListDataFromMessage(not_null view) { using Flag = InlineListData::Flag; const auto item = view->data(); + const auto &settings = AyuSettings::getInstance(); + if (!settings.hideChannelReactions + && item->history()->peer->isChannel() + && !item->history()->peer->isMegagroup()) { + return InlineListData(); + } + if (!settings.hideGroupReactions + && item->history()->peer->isMegagroup()) { + return InlineListData(); + } auto result = InlineListData(); result.reactions = item->reactionsWithLocal(); if (const auto user = item->history()->peer->asUser()) { @@ -867,9 +881,11 @@ InlineListData InlineListDataFromMessage(not_null view) { if (showUserpics) { result.recent.reserve(recent.size()); for (const auto &[id, list] : recent) { - result.recent.emplace(id).first->second = list - | ranges::views::transform(&Data::RecentReaction::peer) - | ranges::to_vector; + auto &out = result.recent.emplace(id).first->second; + out.reserve(list.size()); + for (const auto &r : list) { + out.push_back(r.peer); + } } } } diff --git a/Telegram/SourceFiles/media/stories/media_stories_reactions.cpp b/Telegram/SourceFiles/media/stories/media_stories_reactions.cpp index e65443b429..e88ed3a34d 100644 --- a/Telegram/SourceFiles/media/stories/media_stories_reactions.cpp +++ b/Telegram/SourceFiles/media/stories/media_stories_reactions.cpp @@ -273,8 +273,9 @@ ReactionView::ReactionView( void ReactionView::setupCustomChatStylePalette() { const auto color = uchar(_data.dark ? 255 : 0); - _chatStyle->historyTextInFg().set(color, color, color, 255); - _chatStyle->applyCustomPalette(_chatStyle.get()); + Ui::ChatStyle custom{_chatStyle.get()}; + custom.historyTextInFg().set(color, color, color, 255); + _chatStyle->applyCustomPalette(&custom); } void ReactionView::setAreaGeometry(QRect geometry, float64 radius) {