diff --git a/Telegram/SourceFiles/ayu/ayu_settings.cpp b/Telegram/SourceFiles/ayu/ayu_settings.cpp index c440f9fa3..7021e0135 100644 --- a/Telegram/SourceFiles/ayu/ayu_settings.cpp +++ b/Telegram/SourceFiles/ayu/ayu_settings.cpp @@ -195,6 +195,9 @@ AyuGramSettings::AyuGramSettings() { saveDeletedMessages = true; saveMessagesHistory = true; + // ~ Message filters + hideFromBlocked = false; + // ~ QoL toggles disableAds = true; disableStories = false; @@ -241,7 +244,7 @@ AyuGramSettings::AyuGramSettings() { * showPeerId = 0 means no ID shown * showPeerId = 1 means ID shown as for Telegram API devs * showPeerId = 2 means ID shown as for Bot API devs (-100) - */ + */ showPeerId = 2; showMessageSeconds = false; showMessageShot = true; @@ -307,6 +310,10 @@ void AyuGramSettings::set_saveMessagesHistory(bool val) { saveMessagesHistory = val; } +void AyuGramSettings::set_hideFromBlocked(bool val) { + hideFromBlocked = val; +} + void AyuGramSettings::set_disableAds(bool val) { disableAds = val; } diff --git a/Telegram/SourceFiles/ayu/ayu_settings.h b/Telegram/SourceFiles/ayu/ayu_settings.h index a7d954e86..dfede8802 100644 --- a/Telegram/SourceFiles/ayu/ayu_settings.h +++ b/Telegram/SourceFiles/ayu/ayu_settings.h @@ -29,6 +29,8 @@ public: bool saveDeletedMessages; bool saveMessagesHistory; + bool hideFromBlocked; + bool disableAds; bool disableStories; bool disableCustomBackgrounds; @@ -87,6 +89,8 @@ public: void set_saveDeletedMessages(bool val); void set_saveMessagesHistory(bool val); + void set_hideFromBlocked(bool val); + void set_disableAds(bool val); void set_disableStories(bool val); void set_disableCustomBackgrounds(bool val); @@ -143,6 +147,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT( useScheduledMessages, saveDeletedMessages, saveMessagesHistory, + hideFromBlocked, disableAds, disableStories, disableCustomBackgrounds, diff --git a/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp b/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp index 431b1f382..2b92fb568 100644 --- a/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp +++ b/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp @@ -563,6 +563,31 @@ void SetupSpyEssentials(not_null container) { container->lifetime()); } +void SetupMessageFilters(not_null container) { + auto settings = &AyuSettings::getInstance(); + + AddSubsectionTitle(container, tr::ayu_RegexFilters()); + + AddButtonWithIcon( + container, + tr::ayu_FiltersHideFromBlocked(), + st::settingsButtonNoIcon + )->toggleOn( + rpl::single(settings->hideFromBlocked) + )->toggledValue( + ) | rpl::filter( + [=](bool enabled) + { + return (enabled != settings->hideFromBlocked); + }) | start_with_next( + [=](bool enabled) + { + settings->set_hideFromBlocked(enabled); + AyuSettings::save(); + }, + container->lifetime()); +} + void SetupQoLToggles(not_null container) { auto settings = &AyuSettings::getInstance(); @@ -1317,6 +1342,12 @@ void SetupAyuGramSettings(not_null container, AddDivider(container); + AddSkip(container); + SetupMessageFilters(container); + AddSkip(container); + + AddDivider(container); + AddSkip(container); SetupQoLToggles(container); AddSkip(container); diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 0301d74a2..3365c807a 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -2422,10 +2422,6 @@ void Session::registerMessage(not_null item) { const auto list = messagesListForInsert(peerId); const auto itemId = item->id; - if (AyuState::isHidden(item)) { - return; - } - const auto i = list->find(itemId); if (i != list->end()) { LOG(("App Error: Trying to re-registerMessage().")); diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index 6eb9d43bb..aa8a5fa1c 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -1312,10 +1312,6 @@ void History::viewReplaced(not_null was, Element *now) { void History::addItemToBlock(not_null item) { Expects(!item->mainView()); - if (AyuState::isHidden(item)) { - return; - } - auto block = prepareBlockForAddingItem(); block->messages.push_back(item->createView(_delegateMixin->delegate())); diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index 22b513730..223aa7aad 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -54,6 +54,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include +// AyuGram includes +#include "ayu/ayu_settings.h" + + namespace { const auto kPsaForwardedPrefix = "cloud_lng_forwarded_psa_"; @@ -436,16 +440,27 @@ void HistoryMessageReply::updateData( && (asExternal || _fields.manualQuote); _multiline = !_fields.storyId && (asExternal || nonEmptyQuote); + const auto settings = &AyuSettings::getInstance(); + const auto author = resolvedMessage + ? resolvedMessage->from().get() + : resolvedStory + ? resolvedStory->peer().get() + : nullptr; + const auto blocked = settings->hideFromBlocked + && author + && author->isUser() + && author->asUser()->isBlocked(); + const auto displaying = resolvedMessage || resolvedStory || ((nonEmptyQuote || _fields.externalMedia) && (!_fields.messageId || force)); - _displaying = displaying ? 1 : 0; + _displaying = displaying && !blocked ? 1 : 0; const auto unavailable = !resolvedMessage && !resolvedStory && ((!_fields.storyId && !_fields.messageId) || force); - _unavailable = unavailable ? 1 : 0; + _unavailable = unavailable && !blocked ? 1 : 0; if (force) { if (!_displaying && (_fields.messageId || _fields.storyId)) { diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index 742034bbe..5546b3361 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -49,6 +49,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_chat.h" // AyuGram includes +#include "ayu/ayu_settings.h" +#include "ayu/ayu_state.h" #include "ayu/features/messageshot/message_shot.h" @@ -713,6 +715,17 @@ bool Element::isHiddenByGroup() const { } bool Element::isHidden() const { + if (AyuState::isHidden(data())) { + return true; + } + const auto settings = &AyuSettings::getInstance(); + if (settings->hideFromBlocked) { + if (data()->from()->isUser() && + data()->from()->asUser()->isBlocked()) { + return true; + } + } + return isHiddenByGroup(); } diff --git a/Telegram/SourceFiles/main/main_session.cpp b/Telegram/SourceFiles/main/main_session.cpp index fcadbefe0..f9c1c61fd 100644 --- a/Telegram/SourceFiles/main/main_session.cpp +++ b/Telegram/SourceFiles/main/main_session.cpp @@ -53,6 +53,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL // AyuGram includes #include "ayu/ayu_settings.h" +#include "api/api_blocked_peers.h" namespace Main { @@ -79,6 +80,43 @@ constexpr auto kTmpPasswordReserveTime = TimeId(10); return MTP::ConfigFields().internalLinksDomain; } +void InitializeBlockedPeers(not_null session) { + const auto offset = std::make_shared(0); + const auto allLoaded = std::make_shared(false); + const auto applySlice = [=]( + const Api::BlockedPeers::Slice &slice, + auto self) -> void { + if (slice.list.empty()) { + *allLoaded = true; + } + + *offset += slice.list.size(); + for (const auto &item : slice.list) { + if (const auto peer = session->data().peerLoaded(item.id)) { + peer->setIsBlocked(true); + } + } + if (*offset >= slice.total) { + *allLoaded = true; + } + + if (!*allLoaded) { + session->api().blockedPeers().request( + *offset, + [=](const Api::BlockedPeers::Slice &slice) { + self(slice, self); + }); + } + }; + + session->api().blockedPeers().slice( + ) | rpl::take( + 1 + ) | rpl::start_with_next([=](const Api::BlockedPeers::Slice &result) { + applySlice(result, applySlice); + }, session->lifetime()); +} + } // namespace Session::Session( @@ -189,6 +227,8 @@ Session::Session( _api->requestNotifySettings(MTP_inputNotifyBroadcasts()); Core::App().downloadManager().trackSession(this); + + InitializeBlockedPeers(this); } void Session::setTmpPassword(const QByteArray &password, TimeId validUntil) {