How to implement ignore blocked users in Telegram groups?

image alt

UPD: thanks to help Tkachovthis article still turned from a request for help into a working instruction. In the comments, he gave a working code for creating an ignore in the Telegram desktop client. Just in case, I’ll put an explanation at the end of the article. Further, the article continues in the same form in which it was written.

* * *

I would like to ask the community for help, because I have completely exhausted all my own possibilities.

One could ask a question on the Q&A service (aka former Toaster) - only I have already done this, and not much has come out of it.

Nevertheless, just asking a question under the guise of an article seems to me not very correct. Therefore, I will try to add the background of the whole process to the text and tell what steps have already been taken.

If you're lucky, someone in the comments will tell you the solution. And then those who find this article in the search engines will also be able to solve this problem.

Problem and Background


As all Telegram users are well aware, in the group chats of this messenger there is no user ignore function. You can block a user who is unpleasant to you, but this just prohibits him from writing you private messages. In group chat - and now group chats seem to accommodate up to 10 thousand users - you simply have to see everything that other members of the group have thrown off.

In the “Black Mirror” there was even a series about it.


Keep watching! Keep watching! Keep watching!

If we try to find a solution to this problem on the Internet, we will encounter a typical war story of a large corporation and a small group of disgruntled people. The stages of this war are clearly visible on Github.

Here is the first request for this feature from 2015.You can find links to the following topics in this thread, people constantly asked for this feature in the following years, but each call turned out to be closed with a rather stupid answer “This is not a client problem, but an API problem”.

It is not even clear for the programmer that the data is shown to the user using the client. And even if the API sends you all the messages from the server - there is no problem hiding some of them on the client side.

But for five years now, every year, and sometimes several times a year, people get to Github with a request to introduce ignore in groups - and each time they are refused and the topic closed. More than six months ago, apparently tired of the constant requirements, the developers posted a non-binding excuse : they say, yes, yes, we will do everything, someday in the distant future.


I heard you! I just voiced it until I’m ready to answer you, let’s say, I understand your position. Come on, call, don't get lost!

There is exactly one benefit from this excuse - now tdesktop administrators on Github refer to this message for all complaints. Say - look, they know everything, they will do everything, I'm sorry, the branch is closed. Over the past six months, a lot of time-consuming changes took place in the telegram, for example, animated stickers and BEAUTIFUL waving forms for polls were added to the chats. But no ignore came even close. I think it will not appear in a year.

At the same time, the situation looks even a little sinister - there is a feeling that it is forbidden to introduce this function with any special instructions for official forks. Telegram has at least a dozen well-known forks (like Unigram) and a hundred little-known forks, but none of them have this feature. I wrote in support of the most popular forks, but received no response.

At the same time manage with blocked users client-side messages can be . This is confirmed by the existence of Telegreat . This is a fork of Telegram, in which the option to ignore blocked users was declared.

Alas, this ignore is not real. All that the option “Ignore blocked users” does is colorizes the text of messages of blocked users in gray. Pictures, videos, music or stickers from blocked users are still visible; In addition, the gray color on dark topics is perfectly readable.

People regularly come to a chat to the developer, where I sat for a while, and ask to make a “real ignore”. Previously, he simply refused; in the last six months, he completely abandoned his project, because he "has no time." Well, this is a common thing for free open source projects.

I mention this project for two reasons.

  • Firstly, it is advertised precisely as a “client with an ignore function” and it is advised by people who read only the description, not knowing how this “ignore” is actually implemented there. As mentioned above, this function does not work.
  • Secondly, it is a living confirmation that in the Telegram client it is possible to determine the message of a blocked user and change it. That is, in fact, ignore on the client side is possible.

However, no one does this.

Best of all, my feelings are conveyed in a commentary on a similar topic on Reddit four years ago:
I'm shocked you can't do it.

Seriously?

If I just don't want to read anything some user writes I should be able to do so ... it's like, one of the very basic features of every communication protocols EVER!

You could do it in the 90s with emails and newsgroups!

Moreover, wherever we talk about the reasons for the absence of a player, the same things are repeated:
- You will not see all the messages and because of this you will not understand what is happening in the chat.
- You will duplicate messages.
- The functionality of the system of “answers” ​​will be violated.

And, again, I use a quote, just to show you - these are not my personal thoughts, this is our common position, people who want to introduce this function:
I can assure you 100.00% of people asking for this feature, are fully aware of the side effects it has, and could not care less about those.

Yes just not show it at all. Yes including if it's a reply. Yes if the admin needs to see everything to moderate, then they don't have the luxury of using ignore. And most certainly we can compare TG groups to IRC, because they are both a mechanism for accomplishing the same thing, namely multi-user communication.
Here is just a life example regarding duplication - I sit in several telegram chats and during the day several users always throw the same news / funny screenshot / fresh popular meme into the chat. Despite the fact that before them it was already. Despite the fact that there is no ignore, they still just do not read the chat history and duplicate messages. About how people do not know how to use the search on the forums, and repeatedly repeat the same questions - I will not even mention it, most readers probably have come across this. Again, without any ignorance, this problem already exists. And ignore her will not aggravate.

So why does this function really not exist?

Well, the conspiracy thesis says that the main goal of the Telegram is to collect personal data and user interaction graphs. In this sense, each telegram group allows you to fix a typical small group, which the user can at least withstand, and which can withstand it. Otherwise, either he is thrown out of the group, or he leaves himself. The introduction of ignore will violate the purity of the experiment.

The marketing version is a little easier.

When Khaled Mardam Bay created mIRC in 1995, he wrote a program for people. I mean, for independent people who know what they want, they choose what they think is right and are responsible for the consequences of their actions. On the one hand, this caused problems, for example, with scripted vulnerabilities - you run a line with commands and that's it, you are hacked. On the other hand, it was a messenger that was used by adults and responsible people. And they knew how to exist in a chat with ignore, where some of the messages are simply not visible.

When in 2013 Pasha Durov made Telegram, he made the program “for housewives”. For a dumb mass user who needs a good guardian. Hence, all this registration by phone number, sending messages to everyone on the phone book, flags and prohibitions from all sides. After all, they “press something and everything disappears!”. And then they will write complaints in support! Hence such stupid excuses - "because if you turn on ignore, then you will not see other people's messages." When you make a mass product - you are forced to limit any functionality. The product for the fool must have protection against the fool.

Here comes the crown argument, which is always given at the end: "Do not like it - don’t use it like that." I will not explain what is wrong with him, this is an ethical question of the format “why people should not be eaten” - whoever asks him is meaningless to explain.

But in the case of Telegram, this argument is slightly modified: "I do not like it - do it as you like, it's open source . "

Attempt to solve


Tired of many years of searching, I decided to really try to change something on my own. It seemed to me a good idea to make my own assembly of the Telegram. Not in the sense of a public assembly, with a website and placement in the application store, but simply compiling the application for yourself and using it yourself.

In this sense, I would not be bothered by any possible “brakes” from hiding messages, nor the “problem of losing context in the conversation”, nor the problem of “how to administer the chat if you do not see part of the messages”. All this did not interest me.

It seemed obvious to me that just adding a line like this:
if message.author.isBlocked == true then message.value = 'The message from blocked user'
Sorry for the pseudo-code, but it seems to me that it conveys the idea correctly. I just wanted to catch any message at the very early stage, when it only comes from the server, and replace it with a line about blocking. Thus, the problem would be solved with pictures / stickers / gifs - they would also be replaced with such a message and they would not be visible. And even if someone replied to or quoted a message, it would still be replaced.

But where to start?

After asking friends of programmers, I found out that there are two ways. The first is to use the native Telegram client, and the second is to use a third-party client that is written using the newer TDLib library. I went to the question service mentioned at the beginning of the article and asked a question there. As you can see, the line of respondents is not lined up. The only thread led to the Kotatogram messenger.

I talked with the creator of this messenger, and he gave me two useful tips.
Firstly, he said that messages in the native client are displayed in the usual way, and are not generated (I, however, suspected this with the Telegreat example) - therefore, you can use the native client as the source.
Secondly, he told where to look for the message output itself - in the history_message block.

Unfortunately, he, like the creator of Telegreat, also did not have free time to independently add the ignore function, which is to his client, which is for me.

How did I proceed next? Assembly instructions exist on Github, but it does not reflect all stages of work. I will describe them here, in case someone else comes to the article who is not particularly familiar with programming, but who wants to make the same client with ignore for himself:

  1. I decided to do everything in a virtual machine. To do this, I installed Oracle VM Virtual Box for myself and downloaded their official virtual machine with preinstalled Windows 10 and Visual Studio 2019 from the official Microsoft website
  2. Visual Studio. , C++, Visual Studio Installer . Modify C++, . QT .
  3. Git c git-scm.com
  4. . !

There are 2 sections of teams. And if the first section contains about a dozen commands that are easy to copy and paste into the command line, then for the second section of several dozen commands, it seems natural to copy all the code into a bat-file and run it. This is a mistake, because the process stops at least twice.

The first stop occurs after the line:

gyp --no-circular-check breakpad_client.gyp --format=ninja

The second is after the fourth line from the end, the long QT configuration instruction:

configure -prefix "%LibrariesPath%\Qt-5.12.5" ....... 

As my friends told me, this is due to the fact that during the execution of these commands other bat-files are launched, in which a direct exit from the process is already registered. As a result, you either need to simply copy and paste the commands, or split the instruction into 3 bat files (but in this case, remember that the commands should continue to be executed from the same directory in which the process stopped!).

Getting your own api_id is also described on Github .

Ultimately, I compiled a fully working Telegram exe file. In total, the assembly takes about three hours (not counting the preliminary downloads and installations), perhaps this time depends on the computer's power.

Hall help (and solution found)


And here finally my request to the habrasociety appears. As readers have already guessed, I do not know what and how to change. It seems to me that I found a place where the message is displayed, but I'm not sure, because I do not know C ++. Not to mention that (perhaps) it would be correct to change something not in history_message, but somewhere in history_item. “Something in Elvish, I can’t read” Maybe someone here has already encountered the Telegram code or just has a very developed skill and can write the very same line with the replacement of any message from a blocked user, and also say where to put it in this code.






I suppose that the telegram’s withdrawal mechanism itself will not suddenly change. So when updating the client, I will just download the updated version from the github and add this line again with a lock before compiling.

UPD: As I mentioned at the beginning of the article, a working version of the code appeared in the comments . I bring it directly to the article.

The first part of the code replaces the text with another message. This is necessary because this text is visible in quotes if another user answers the blocked one, or on the left in the chat window, where the latest messages in group chats are displayed.

In the file History_Message.cpp we find the function just in the same place as in the screenshot above:

HistoryMessage::HistoryMessage(
	not_null<History*> history,
	const MTPDmessage &data,
	MTPDmessage_ClientFlags clientFlags)


And inside we replace the original text:

	if (const auto media = data.vmedia()) {
		setMedia(*media);
	}
	setText({
		TextUtilities::Clean(qs(data.vmessage())),
		Api::EntitiesFromMTP(data.ventities().value_or_empty())
	});


On advanced:


	UserId from = data.vfrom_id().value_or_empty();
	PeerData* pd = from ? history->owner().user(from) : history->peer;
	if (pd->isUser() && pd->asUser()->isBlocked()) {
		setText({
			TextUtilities::Clean(qs("The message from blocked user")),
			Api::EntitiesFromMTP(data.ventities().value_or_empty())
			});
	}
	else {
		//   442-448:
		if (const auto media = data.vmedia()) {
			setMedia(*media);
		}
		setText({
			TextUtilities::Clean(qs(data.vmessage())),
			Api::EntitiesFromMTP(data.ventities().value_or_empty())
			});
	}


If you use only this code, the old messages of blocked users will be visible, but the new ones will no longer be.

Therefore, the second part of the solution mentioned in this comment

adds the following code to the history_view_message.cpp file:

PeerData* pd = item->from();
if (pd->isUser() && pd->asUser()->isBlocked()) return;


UPD: in the new version, the compiler swears on an empty return, so I added the output of QSize (0,0)
PeerData* pd = item->from();
if (pd->isUser() && pd->asUser()->isBlocked()) return QSize(0,0);


Immediately after declaring the item variable in the
QSize Message :: performCountOptimalSize ()
and
void Message :: draw (
Painter & p,
QRect clip,
TextSelection selection,
crl :: time ms) functions,

this will completely prevent the messages from blocked users in the chat log.

Important addition: If suddenly the messages of the blocked user are still visible - you just need to click on his profile, the information that he is blocked will be updated, and all his messages will disappear from the chat log.

For those who wish, he added a compiled application to Dropbox .

UPD: Made a “site” for distributing sites.google.com/view/ignoram

Source: https://habr.com/ru/post/undefined/


All Articles