summarylogtreecommitdiffstats
path: root/0001-Add-an-option-to-hide-messages-from-blocked-users-in.patch
blob: efc86e7d932de8d9a09140762687b09722b7bd73 (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
From e3a2cbc1f4681221591ac91414b4f2003048ba5f 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/lang.strings         |  2 ++
 Telegram/Resources/langs/rewrites/ru.json     |  3 +-
 .../history/history_item_components.cpp       |  7 +++--
 .../SourceFiles/history/history_widget.cpp    | 28 +++++++++++++++++++
 .../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 +
 9 files changed, 65 insertions(+), 3 deletions(-)

diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings
index 62c9823f4..fd06553ad 100644
--- a/Telegram/Resources/langs/lang.strings
+++ b/Telegram/Resources/langs/lang.strings
@@ -2517,4 +2517,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 
 "ktg_message_id" = "Message ID: {id}";
 
+"ktg_settings_block_users_in_groups" = "Block users in groups";
+
 // Keys finished
diff --git a/Telegram/Resources/langs/rewrites/ru.json b/Telegram/Resources/langs/rewrites/ru.json
index f0c78e924..5aa5988d2 100644
--- a/Telegram/Resources/langs/rewrites/ru.json
+++ b/Telegram/Resources/langs/rewrites/ru.json
@@ -122,5 +122,6 @@
 	"ktg_settings_chat_id_disable": "Скрыть",
 	"ktg_settings_chat_id_telegram": "Telegram API",
 	"ktg_settings_chat_id_bot": "Bot API",
-	"ktg_message_id": "ID сообщения: {id}"
+	"ktg_message_id": "ID сообщения: {id}",
+	"ktg_settings_block_users_in_groups": "Блокировать пользователей в группах"
 }
diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp
index 52be9b67e..0910b5531 100644
--- a/Telegram/SourceFiles/history/history_item_components.cpp
+++ b/Telegram/SourceFiles/history/history_item_components.cpp
@@ -329,7 +329,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;
@@ -370,7 +373,7 @@ void HistoryMessageReply::paint(
 			p.setFont(st::msgDateFont);
 			auto &date = outbg ? (selected ? st::msgOutDateFgSelected : st::msgOutDateFg) : (selected ? st::msgInDateFgSelected : st::msgInDateFg);
 			p.setPen((flags & PaintFlag::InBubble) ? date : 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 b3360f631..99a0731d3 100644
--- a/Telegram/SourceFiles/history/history_widget.cpp
+++ b/Telegram/SourceFiles/history/history_widget.cpp
@@ -543,6 +543,34 @@ HistoryWidget::HistoryWidget(
 		});
 	}, lifetime());
 
+	BlockUsersInGroupsChanges(
+	) | rpl::start_with_next([=] {
+		crl::on_main(this, [=] {
+			if (_history) {
+				_history->forceFullResize();
+				if (_migrated) {
+					_migrated->forceFullResize();
+				}
+				updateHistoryGeometry();
+				update();
+			}
+		});
+	}, lifetime());
+
+	session().api().blockedUsersSlice(
+	) | 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 8d9df51f2..457f66c8c 100644
--- a/Telegram/SourceFiles/history/view/history_view_element.cpp
+++ b/Telegram/SourceFiles/history/view/history_view_element.cpp
@@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "main/main_session.h"
 #include "chat_helpers/stickers_emoji_pack.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"
@@ -339,6 +340,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 15734174a..c1783f91c 100644
--- a/Telegram/SourceFiles/kotato/json_settings.cpp
+++ b/Telegram/SourceFiles/kotato/json_settings.cpp
@@ -179,6 +179,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"), cShowChatId());
 	settings.insert(qsl("show_phone_in_drawer"), cShowPhoneInDrawer());
@@ -315,6 +316,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 7492240f7..1e36bd143 100644
--- a/Telegram/SourceFiles/kotato/settings.cpp
+++ b/Telegram/SourceFiles/kotato/settings.cpp
@@ -64,6 +64,17 @@ rpl::producer<bool> AdaptiveBubblesChanges() {
 	return gAdaptiveBubbles.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;
 int gShowChatId = 0;
 
diff --git a/Telegram/SourceFiles/kotato/settings.h b/Telegram/SourceFiles/kotato/settings.h
index c76b8347b..06710c075 100644
--- a/Telegram/SourceFiles/kotato/settings.h
+++ b/Telegram/SourceFiles/kotato/settings.h
@@ -47,6 +47,10 @@ void SetAdaptiveBubbles(bool enabled);
 [[nodiscard]] bool AdaptiveBubbles();
 [[nodiscard]] rpl::producer<bool> AdaptiveBubblesChanges();
 
+void SetBlockUsersInGroups(bool enabled);
+[[nodiscard]] bool BlockUsersInGroups();
+[[nodiscard]] rpl::producer<bool> BlockUsersInGroupsChanges();
+
 DeclareSetting(bool, AlwaysShowScheduled);
 DeclareSetting(int, ShowChatId);
 
diff --git a/Telegram/SourceFiles/kotato/settings_menu.cpp b/Telegram/SourceFiles/kotato/settings_menu.cpp
index 622252577..2ba2de934 100644
--- a/Telegram/SourceFiles/kotato/settings_menu.cpp
+++ b/Telegram/SourceFiles/kotato/settings_menu.cpp
@@ -313,6 +313,7 @@ void SetupKotatoMessages(not_null<Ui::VerticalLayout*> container) {
 
 	SettingsMenuSwitch(ktg_settings_adaptive_bubbles, AdaptiveBubbles);
 	SettingsMenuSwitch(ktg_settings_emoji_outline, BigEmojiOutline);
+	SettingsMenuSwitch(ktg_settings_block_users_in_groups, BlockUsersInGroups);
 
 	AddSkip(container);
 }
-- 
2.28.0