summarylogtreecommitdiffstats
path: root/0001-Add-an-option-to-hide-messages-from-blocked-users-in.patch
blob: 5698362efc4d38cd974f31118ad845e321b1ee2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
From 51ec84e88a3c60d6ba65ba2400d76eea97ef7745 Mon Sep 17 00:00:00 2001
From: Ilya Fedin <fedin-ilja2010@ya.ru>
Date: Sun, 14 Jun 2020 03:25:53 +0400
Subject: [PATCH] Add an option to hide messages from blocked users in groups

---
 Telegram/Resources/langs/rewrites/en.json     |  1 +
 Telegram/Resources/langs/rewrites/ru.json     |  1 +
 .../history/history_item_components.cpp       |  9 ++++-
 .../SourceFiles/history/history_widget.cpp    | 30 ++++++++++++++
 .../history/view/history_view_element.cpp     |  7 ++++
 .../SourceFiles/kotato/kotato_settings.cpp    |  3 ++
 .../kotato/kotato_settings_menu.cpp           |  1 +
 Telegram/SourceFiles/main/main_session.cpp    | 40 +++++++++++++++++++
 8 files changed, 90 insertions(+), 2 deletions(-)

diff --git a/Telegram/Resources/langs/rewrites/en.json b/Telegram/Resources/langs/rewrites/en.json
index e50ac3e25..bd67e4d27 100644
--- a/Telegram/Resources/langs/rewrites/en.json
+++ b/Telegram/Resources/langs/rewrites/en.json
@@ -167,6 +167,7 @@
 	"ktg_admin_log_banned_send_games": "Send games",
 	"ktg_admin_log_banned_use_inline": "Use inline bots",
 	"ktg_forward_go_to_chat": "Go to chat",
+	"ktg_settings_block_users_in_groups": "Block users in groups",
 	"ktg_settings_forward": "Forward",
 	"ktg_settings_forward_retain_selection": "Retain selection after forward",
 	"ktg_settings_forward_chat_on_click": "Open chat on click",
diff --git a/Telegram/Resources/langs/rewrites/ru.json b/Telegram/Resources/langs/rewrites/ru.json
index 5f4c7e775..cb1509722 100644
--- a/Telegram/Resources/langs/rewrites/ru.json
+++ b/Telegram/Resources/langs/rewrites/ru.json
@@ -167,6 +167,7 @@
 	"ktg_admin_log_banned_send_games": "Отправка игр",
 	"ktg_admin_log_banned_use_inline": "Отправка через ботов",
 	"ktg_forward_go_to_chat": "Перейти в чат",
+	"ktg_settings_block_users_in_groups": "Блокировать пользователей в группах",
 	"ktg_settings_forward": "Пересылка",
 	"ktg_settings_forward_retain_selection": "Сохранять выделение после пересылки",
 	"ktg_settings_forward_chat_on_click": "Открывать чат по клику",
diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp
index 09e2fe34e..1939d3570 100644
--- a/Telegram/SourceFiles/history/history_item_components.cpp
+++ b/Telegram/SourceFiles/history/history_item_components.cpp
@@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 */
 #include "history/history_item_components.h"
 
+#include "kotato/kotato_settings.h"
 #include "kotato/kotato_lang.h"
 #include "base/qt/qt_key_modifiers.h"
 #include "lang/lang_keys.h"
@@ -334,7 +335,11 @@ void HistoryMessageReply::paint(
 	p.fillRect(rbar, bar);
 
 	if (w > st::msgReplyBarSkip) {
-		if (replyToMsg) {
+		auto blocked = replyToMsg
+			&& replyToMsg->from()->isUser()
+			&& replyToMsg->from()->asUser()->isBlocked();
+		const auto blockUsersInGroups = ::Kotato::JsonSettings::GetBool("block_users_in_groups");
+		if (replyToMsg && (!blocked || !blockUsersInGroups)) {
 			auto hasPreview = replyToMsg->media() ? replyToMsg->media()->hasReplyPreview() : false;
 			if (hasPreview && w < st::msgReplyBarSkip + st::msgReplyBarSize.height()) {
 				hasPreview = false;
@@ -380,7 +385,7 @@ void HistoryMessageReply::paint(
 			p.setPen(inBubble
 				? stm->msgDateFg
 				: st->msgDateImgFg());
-			p.drawTextLeft(x + st::msgReplyBarSkip, y + st::msgReplyPadding.top() + (st::msgReplyBarSize.height() - st::msgDateFont->height) / 2, w + 2 * x, st::msgDateFont->elided(replyToMsgId ? tr::lng_profile_loading(tr::now) : tr::lng_deleted_message(tr::now), w - st::msgReplyBarSkip));
+			p.drawTextLeft(x + st::msgReplyBarSkip, y + st::msgReplyPadding.top() + (st::msgReplyBarSize.height() - st::msgDateFont->height) / 2, w + 2 * x, st::msgDateFont->elided((replyToMsgId && (!blocked || !blockUsersInGroups)) ? tr::lng_profile_loading(tr::now) : tr::lng_deleted_message(tr::now), w - st::msgReplyBarSkip));
 		}
 	}
 }
diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp
index c09939134..79e020277 100644
--- a/Telegram/SourceFiles/history/history_widget.cpp
+++ b/Telegram/SourceFiles/history/history_widget.cpp
@@ -682,6 +682,36 @@ HistoryWidget::HistoryWidget(
 		});
 	}, lifetime());
 
+	::Kotato::JsonSettings::Events(
+		"block_users_in_groups"
+	) | rpl::start_with_next([=] {
+		crl::on_main(this, [=] {
+			if (_history) {
+				_history->forceFullResize();
+				if (_migrated) {
+					_migrated->forceFullResize();
+				}
+				updateHistoryGeometry();
+				update();
+			}
+		});
+	}, lifetime());
+
+	session().changes().peerUpdates(
+		Data::PeerUpdate::Flag::IsBlocked
+	) | rpl::start_with_next([=] {
+		crl::on_main(this, [=] {
+			if (_history) {
+				_history->forceFullResize();
+				if (_migrated) {
+					_migrated->forceFullResize();
+				}
+				updateHistoryGeometry();
+				update();
+			}
+		});
+	}, lifetime());
+
 	session().data().animationPlayInlineRequest(
 	) | rpl::start_with_next([=](not_null<HistoryItem*> item) {
 		if (const auto view = item->mainView()) {
diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp
index f6938da0c..975d502ae 100644
--- a/Telegram/SourceFiles/history/view/history_view_element.cpp
+++ b/Telegram/SourceFiles/history/view/history_view_element.cpp
@@ -35,6 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "ui/toast/toast.h"
 #include "ui/toasts/common_toasts.h"
 #include "data/data_session.h"
+#include "data/data_user.h"
 #include "data/data_groups.h"
 #include "data/data_media_types.h"
 #include "data/data_sponsored_messages.h"
@@ -521,6 +522,12 @@ bool Element::isHiddenByGroup() const {
 }
 
 bool Element::isHidden() const {
+	if (::Kotato::JsonSettings::GetBool("block_users_in_groups")
+		&& data()->from()->isUser()
+		&& data()->from()->asUser()->isBlocked()) {
+		return true;
+	}
+
 	return isHiddenByGroup();
 }
 
diff --git a/Telegram/SourceFiles/kotato/kotato_settings.cpp b/Telegram/SourceFiles/kotato/kotato_settings.cpp
index 9b0513d82..ebceb4f8f 100644
--- a/Telegram/SourceFiles/kotato/kotato_settings.cpp
+++ b/Telegram/SourceFiles/kotato/kotato_settings.cpp
@@ -326,6 +326,9 @@ const std::map<QString, Definition, std::greater<QString>> DefinitionMap {
 	{ "big_emoji_outline", {
 		.type = SettingType::BoolSetting,
 		.defaultValue = true, }},
+	{ "block_users_in_groups", {
+		.type = SettingType::BoolSetting,
+		.defaultValue = true, }},
 	{ "sticker_height", {
 		.type = SettingType::IntSetting,
 		.defaultValue = 170,
diff --git a/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp b/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp
index 88249d0d3..73ef1f8a2 100644
--- a/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp
+++ b/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp
@@ -472,6 +472,7 @@ void SetupKotatoMessages(not_null<Ui::VerticalLayout*> container) {
 	}
 
 	SettingsMenuJsonSwitch(ktg_settings_emoji_outline, big_emoji_outline);
+	SettingsMenuJsonSwitch(ktg_settings_block_users_in_groups, block_users_in_groups);
 
 	AddSkip(container);
 }
diff --git a/Telegram/SourceFiles/main/main_session.cpp b/Telegram/SourceFiles/main/main_session.cpp
index 084137b82..cf882a238 100644
--- a/Telegram/SourceFiles/main/main_session.cpp
+++ b/Telegram/SourceFiles/main/main_session.cpp
@@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "api/api_updates.h"
 #include "api/api_send_progress.h"
 #include "api/api_user_privacy.h"
+#include "api/api_blocked_peers.h"
 #include "main/main_account.h"
 #include "main/main_domain.h"
 #include "main/main_session_settings.h"
@@ -68,6 +69,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(
@@ -158,6 +196,8 @@ Session::Session(
 	_api->requestNotifySettings(MTP_inputNotifyUsers());
 	_api->requestNotifySettings(MTP_inputNotifyChats());
 	_api->requestNotifySettings(MTP_inputNotifyBroadcasts());
+
+	InitializeBlockedPeers(this);
 }
 
 void Session::setTmpPassword(const QByteArray &password, TimeId validUntil) {
-- 
2.35.1