feat: hide messages from blocked users

Co-authored-by: Ilya Fedin <fedin-ilja2010@ya.ru>
This commit is contained in:
AlexeyZavar 2024-04-19 00:05:00 +03:00
parent b4c5963a1a
commit 1c85a81f1f
8 changed files with 114 additions and 11 deletions

View file

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

View file

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

View file

@ -563,6 +563,31 @@ void SetupSpyEssentials(not_null<Ui::VerticalLayout*> container) {
container->lifetime());
}
void SetupMessageFilters(not_null<Ui::VerticalLayout*> 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<Ui::VerticalLayout*> container) {
auto settings = &AyuSettings::getInstance();
@ -1317,6 +1342,12 @@ void SetupAyuGramSettings(not_null<Ui::VerticalLayout*> container,
AddDivider(container);
AddSkip(container);
SetupMessageFilters(container);
AddSkip(container);
AddDivider(container);
AddSkip(container);
SetupQoLToggles(container);
AddSkip(container);

View file

@ -2422,10 +2422,6 @@ void Session::registerMessage(not_null<HistoryItem*> 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()."));

View file

@ -1312,10 +1312,6 @@ void History::viewReplaced(not_null<const Element*> was, Element *now) {
void History::addItemToBlock(not_null<HistoryItem*> item) {
Expects(!item->mainView());
if (AyuState::isHidden(item)) {
return;
}
auto block = prepareBlockForAddingItem();
block->messages.push_back(item->createView(_delegateMixin->delegate()));

View file

@ -54,6 +54,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtGui/QGuiApplication>
// 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)) {

View file

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

View file

@ -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<Main::Session*> session) {
const auto offset = std::make_shared<int>(0);
const auto allLoaded = std::make_shared<bool>(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) {