tdlib / td

Cross-platform library for building Telegram clients
https://core.telegram.org/tdlib
Boost Software License 1.0
7.11k stars 1.44k forks source link

TdApi.Supergroup.isBroadcastGroup always returns false #2770

Closed rufatagayev closed 8 months ago

rufatagayev commented 9 months ago

I'm using the java library in my android app. The TdApi.Supergroup object has a isBroadcastGroup property, indicating that the group is a broadcast group, i.e. only admins can post messages. As I understand, these are groups in the telegram app where you don't have an input field at the bottom to send a message. I have a bunch of such channels which I'm subscribed to. But when I get these channels in my android app and check the isBroadcastGroup property for these channels, they always return false. Why is that? I already check the TdApi.Chat.isChannel property separately, and that returns true for channels, but I want only those channels where only admins can post, not users.

levlam commented 9 months ago

In channels only their administrators can ever write messages. Broadcast groups aren't channels. They are special types of supergroups, which can have more than 200000 members, but can't change chatPermissions to allow ordinary members to write messages. If chat permissions can be changed in the group, then it isn't a broadcast group. You need to checK chat permissions to see what types of messages non-administrator users can send to the chat currently.

rufatagayev commented 9 months ago

I also check for chat.permissions.canSendBasicMessages, but some groups still come through where users can send basic text messages. How do I get only those chats where there is no input field at the bottom in telegram for normal users?

levlam commented 9 months ago

It is up to specific app when it shows or not the input field.

rufatagayev commented 9 months ago

So as I understand only (chat.type as TdApi.ChatTypeSupergroup).isChannel should be the right way to check if only admins can post? If so, why do I still get some channels where users can freely send text messages? This is how I check for channels:

return this.type is TdApi.ChatTypeSupergroup &&
(this.type as TdApi.ChatTypeSupergroup).isChannel &&
this.permissions.canSendBasicMessages.not()
levlam commented 9 months ago

No. Channels and supergroups are very different and have a lot of other differencies. Ordinary users can never post to channels or broadcast groups, but the ability to send messages can be also disabled in regular supergroups via chat permissions.

rufatagayev commented 9 months ago

Ok, I'll try to clarify what I mean: I filter for channels using .isChannel. But I also get one or two groups such as t.me/tdlibchat. In Telegram app, t.me/tdlibchat appears under groups.

levlam commented 9 months ago

tdlibchat isn't a channel. It is a regular supergroup.

rufatagayev commented 9 months ago

Exactly. It is a regular supergroup, but its messages show up in my results even when I filter chats for (this.type as TdApi.ChatTypeSupergroup).isChannel. I can't understand why. By the way, this happens when I first open the app. If I close and reopen, these messages do not show up. It seems to be something related to offline / cache. But I can't figure it out.

levlam commented 9 months ago

This isn't possible. For the tdlibchat type.isChannel is always false.

levlam commented 9 months ago

You can enable TDLib logs with verbosity level 5 and check there that isChannel == false. You can also share the log with https://t.me/tdlib_bot.

rufatagayev commented 8 months ago

These non-channel messages have stopped appearing now. I also added a check for each TdApi.Message to see if message.isChannelPost is true and I think it worked. Closing the issue. Thank you for help!