summarylogtreecommitdiffstats
path: root/0001-Add-an-option-to-hide-messages-from-blocked-users-in.patch
blob: c409e1481e369d2c10872c6bbec777b6c3c98cec (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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
From 1a636ab4e3dce29a08a32c5282441076fa199f23 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       |  7 +++-
 .../SourceFiles/history/history_widget.cpp    | 29 ++++++++++++++
 .../history/view/history_view_element.cpp     |  7 ++++
 Telegram/SourceFiles/kotato/json_settings.cpp |  5 +++
 Telegram/SourceFiles/kotato/settings.cpp      | 11 +++++
 Telegram/SourceFiles/kotato/settings.h        |  4 ++
 Telegram/SourceFiles/kotato/settings_menu.cpp |  1 +
 Telegram/SourceFiles/main/main_session.cpp    | 40 +++++++++++++++++++
 10 files changed, 104 insertions(+), 2 deletions(-)

diff --git a/Telegram/Resources/langs/rewrites/en.json b/Telegram/Resources/langs/rewrites/en.json
index 846807a44..3d3f8205d 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 be0be9f7e..e8085cb45 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 563cc4bcf..6535a7ba9 100644
--- a/Telegram/SourceFiles/history/history_item_components.cpp
+++ b/Telegram/SourceFiles/history/history_item_components.cpp
@@ -355,7 +355,10 @@ void HistoryMessageReply::paint(
 	p.fillRect(rbar, bar);
 
 	if (w > st::msgReplyBarSkip) {
-		if (replyToMsg) {
+		auto blocked = replyToMsg
+			&& replyToMsg->from()->isUser()
+			&& replyToMsg->from()->asUser()->isBlocked();
+		if (replyToMsg && (!blocked || !BlockUsersInGroups())) {
 			auto hasPreview = replyToMsg->media() ? replyToMsg->media()->hasReplyPreview() : false;
 			if (hasPreview && w < st::msgReplyBarSkip + st::msgReplyBarSize.height()) {
 				hasPreview = false;
@@ -402,7 +405,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 4324c7edc..8466e0055 100644
--- a/Telegram/SourceFiles/history/history_widget.cpp
+++ b/Telegram/SourceFiles/history/history_widget.cpp
@@ -641,6 +641,35 @@ HistoryWidget::HistoryWidget(
 		});
 	}, lifetime());
 
+	BlockUsersInGroupsChanges(
+	) | 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());
+
 	HoverEmojiPanelChanges(
 	) | rpl::start_with_next([=] {
 		crl::on_main(this, [=] {
diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp
index e588bdb92..ee8133474 100644
--- a/Telegram/SourceFiles/history/view/history_view_element.cpp
+++ b/Telegram/SourceFiles/history/view/history_view_element.cpp
@@ -28,6 +28,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 "lang/lang_keys.h"
@@ -477,6 +478,12 @@ bool Element::isHiddenByGroup() const {
 }
 
 bool Element::isHidden() const {
+	if (BlockUsersInGroups()
+		&& data()->from()->isUser()
+		&& data()->from()->asUser()->isBlocked()) {
+		return true;
+	}
+
 	return isHiddenByGroup();
 }
 
diff --git a/Telegram/SourceFiles/kotato/json_settings.cpp b/Telegram/SourceFiles/kotato/json_settings.cpp
index 7b1fab50a..37f657bd4 100644
--- a/Telegram/SourceFiles/kotato/json_settings.cpp
+++ b/Telegram/SourceFiles/kotato/json_settings.cpp
@@ -366,6 +366,7 @@ QByteArray GenerateSettingsJson(bool areDefault = false) {
 	settings.insert(qsl("sticker_scale_both"), StickerScaleBoth());
 	settings.insert(qsl("adaptive_bubbles"), AdaptiveBubbles());
 	settings.insert(qsl("big_emoji_outline"), BigEmojiOutline());
+	settings.insert(qsl("block_users_in_groups"), BlockUsersInGroups());
 	settings.insert(qsl("always_show_scheduled"), cAlwaysShowScheduled());
 	settings.insert(qsl("show_chat_id"), ShowChatId());
 	settings.insert(qsl("show_phone_in_drawer"), cShowPhoneInDrawer());
@@ -529,6 +530,10 @@ bool Manager::readCustomFile() {
 		SetBigEmojiOutline(v);
 	});
 
+	ReadBoolOption(settings, "block_users_in_groups", [&](auto v) {
+		SetBlockUsersInGroups(v);
+	});
+
 	ReadBoolOption(settings, "always_show_scheduled", [&](auto v) {
 		cSetAlwaysShowScheduled(v);
 	});
diff --git a/Telegram/SourceFiles/kotato/settings.cpp b/Telegram/SourceFiles/kotato/settings.cpp
index e073d96f6..0b2dd5241 100644
--- a/Telegram/SourceFiles/kotato/settings.cpp
+++ b/Telegram/SourceFiles/kotato/settings.cpp
@@ -79,6 +79,17 @@ rpl::producer<bool> MonospaceLargeBubblesChanges() {
 	return gMonospaceLargeBubbles.changes();
 }
 
+rpl::variable<bool> gBlockUsersInGroups = false;
+void SetBlockUsersInGroups(bool enabled) {
+	gBlockUsersInGroups = enabled;
+}
+bool BlockUsersInGroups() {
+	return gBlockUsersInGroups.current();
+}
+rpl::producer<bool> BlockUsersInGroupsChanges() {
+	return gBlockUsersInGroups.changes();
+}
+
 bool gAlwaysShowScheduled = false;
 
 rpl::variable<int> gShowChatId = 2;
diff --git a/Telegram/SourceFiles/kotato/settings.h b/Telegram/SourceFiles/kotato/settings.h
index 6d3a82d9d..dcc98b319 100644
--- a/Telegram/SourceFiles/kotato/settings.h
+++ b/Telegram/SourceFiles/kotato/settings.h
@@ -62,6 +62,10 @@ void SetMonospaceLargeBubbles(bool enabled);
 [[nodiscard]] bool MonospaceLargeBubbles();
 [[nodiscard]] rpl::producer<bool> MonospaceLargeBubblesChanges();
 
+void SetBlockUsersInGroups(bool enabled);
+[[nodiscard]] bool BlockUsersInGroups();
+[[nodiscard]] rpl::producer<bool> BlockUsersInGroupsChanges();
+
 DeclareSetting(bool, AlwaysShowScheduled);
 
 void SetShowChatId(int chatIdType);
diff --git a/Telegram/SourceFiles/kotato/settings_menu.cpp b/Telegram/SourceFiles/kotato/settings_menu.cpp
index 6c9ab475b..d7760b729 100644
--- a/Telegram/SourceFiles/kotato/settings_menu.cpp
+++ b/Telegram/SourceFiles/kotato/settings_menu.cpp
@@ -444,6 +444,7 @@ void SetupKotatoMessages(not_null<Ui::VerticalLayout*> container) {
 	}
 
 	SettingsMenuSwitch(ktg_settings_emoji_outline, BigEmojiOutline);
+	SettingsMenuSwitch(ktg_settings_block_users_in_groups, BlockUsersInGroups);
 
 	AddSkip(container);
 }
diff --git a/Telegram/SourceFiles/main/main_session.cpp b/Telegram/SourceFiles/main/main_session.cpp
index 99e02e2aa..40d4f8fa1 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"
@@ -61,6 +62,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(
@@ -149,6 +187,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.33.1