Adding a setting to disable reactions in a channels and groups

This commit is contained in:
Neurotoxin001 2025-06-25 00:53:37 +03:00
parent 3be793032f
commit dc75f155cd
9 changed files with 119 additions and 16 deletions

View file

@ -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";

View file

@ -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 <ayu/ayu_settings.h>
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) {

View file

@ -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);
}

View file

@ -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,

View file

@ -846,6 +846,44 @@ void SetupQoLToggles(not_null<Ui::VerticalLayout*> 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<Ui::VerticalLayout*> container) {

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -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<ReactionId> InlineList::computeTagsList() const {
if (!areTags()) {
return {};
}
return _buttons | ranges::views::transform(
&Button::id
) | ranges::to_vector;
auto result = std::vector<ReactionId>();
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<not_null<const MessageReaction*>>();
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<Element*> 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<Element*> 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);
}
}
}
}