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..89774cdc39 100644 --- a/Telegram/SourceFiles/api/api_unread_things.cpp +++ b/Telegram/SourceFiles/api/api_unread_things.cpp @@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_item.h" #include "history/history_unread_things.h" #include "apiwrap.h" +#include namespace Api { namespace { @@ -36,7 +37,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 e3ea5e76ec..7568b52bd9 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(QString val) { settings->appIcon = std::move(val); } diff --git a/Telegram/SourceFiles/ayu/ayu_settings.h b/Telegram/SourceFiles/ayu/ayu_settings.h index 6bbf81c7c7..47362440cf 100644 --- a/Telegram/SourceFiles/ayu/ayu_settings.h +++ b/Telegram/SourceFiles/ayu/ayu_settings.h @@ -49,6 +49,8 @@ public: bool disableNotificationsDelay; bool localPremium; + bool hideChannelReactions; + bool hideGroupReactions; QString appIcon; bool simpleQuotesAndReplies; @@ -131,6 +133,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(QString val); void set_simpleQuotesAndReplies(bool val); @@ -205,6 +209,8 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT( disableNotificationsDelay, localPremium, appIcon, + hideChannelReactions, + hideGroupReactions, simpleQuotesAndReplies, replaceBottomInfoWithIcons, deletedMark, diff --git a/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp b/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp index 9ace785559..90e96261e4 100644 --- a/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp +++ b/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp @@ -846,6 +846,44 @@ void SetupQoLToggles(not_null container) { AyuSettings::save(); }, container->lifetime()); + + 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..2153a15df9 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -2278,8 +2278,12 @@ Dialogs::UnreadState History::computeUnreadState() const { result.messages = count; result.chats = count ? 1 : 0; result.marks = mark ? 1 : 0; - result.mentions = unreadMentions().has() ? 1 : 0; - result.reactions = unreadReactions().has() ? 1 : 0; + result.mentions = unreadMentions().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..e4d6f7ae3e 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -103,6 +103,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL // AyuGram includes #include "ayu/ui/context_menu/context_menu.h" #include "ayu/utils/telegram_helpers.h" +#include "ayu/ayu_settings.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 050dee1005..8501b94b7d 100644 --- a/Telegram/SourceFiles/history/history_item_helpers.cpp +++ b/Telegram/SourceFiles/history/history_item_helpers.cpp @@ -1081,7 +1081,14 @@ void CheckReactionNotificationSchedule( if (!item->hasUnreadReaction()) { return; } - for (const auto &[emoji, reactions] : item->recentReactions()) { + 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) { continue; diff --git a/Telegram/SourceFiles/history/view/reactions/history_view_reactions.cpp b/Telegram/SourceFiles/history/view/reactions/history_view_reactions.cpp index 1935119101..a2820a1c96 100644 --- a/Telegram/SourceFiles/history/view/reactions/history_view_reactions.cpp +++ b/Telegram/SourceFiles/history/view/reactions/history_view_reactions.cpp @@ -30,6 +30,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL // AyuGram includes #include "ayu/features/messageshot/message_shot.h" +#include "ayu/ayu_settings.h" namespace HistoryView::Reactions { @@ -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); + } } } }