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

how to check if a user has the permission to broadcast message to a channel? #2335

Closed Yxue-1906 closed 1 year ago

Yxue-1906 commented 1 year ago

if find although the user is the creator of the channel, chatPermission in chat object returned by getChat indicates the user has no right to send message.

part of the log

[ 3][t 1][1678353734.471293687][Td.cpp:2923][!Td][&td_requests] Receive request 17: getChat {
  chat_id = ***4402
}
[ 3][t 1][1678353734.471417903][MessagesManager.cpp:35006][!GetChatRequest] Search for server message 146 in chat ***4402 found 0xaaaaf2c19c30
[ 3][t 1][1678353734.471545219][Td.cpp:3980][!Td][&td_requests] Sending result for request 17: chat {
  id = ***4402
  type = chatTypeSupergroup {
    supergroup_id = ***4402
    is_channel = true
  }
  title = "test"
  photo = null
  permissions = chatPermissions {
    can_send_messages = false
    can_send_media_messages = false
    can_send_polls = false
    can_send_other_messages = false
    can_add_web_page_previews = false
    can_change_info = false
    can_invite_users = false
    can_pin_messages = false
    can_manage_topics = false
  }
  ...
[ 3][t 1][1678353819.953547954][Td.cpp:2923][!Td][&td_requests] Receive request 18: getSupergroup {
  supergroup_id = ***4402
}
[ 3][t 1][1678353819.953650951][Td.cpp:3980][!Td][&td_requests] Sending result for request 18: supergroup {
  id = ***4402
  usernames = null
  date = 1642844800
  status = chatMemberStatusCreator {
    custom_title = ""
    is_anonymous = false
    is_member = true
  }
  member_count = 2
  has_linked_chat = true
  has_location = false
  sign_messages = false
  join_to_send_messages = true
  join_by_request = false
  is_slow_mode_enabled = false
  is_channel = true
  is_broadcast_group = false
  is_forum = false
  is_verified = false
  restriction_reason = ""
  is_scam = false
  is_fake = false
}
AYMENJD commented 1 year ago

The permissions in chat.permissions is for non-administrator members. If you want to check permissions for a single user you must use getChatMember.

chat.permissions: https://github.com/tdlib/td/blob/1543c41f3411bd6aa74713c8aba4e93fa8d952c7/td/generate/scheme/td_api.tl#L1318

Yxue-1906 commented 1 year ago

The permissions in chat.permissions is for non-administrator members. If you want to check permissions for a single user you must use getChatMember.

chat.permissions:

https://github.com/tdlib/td/blob/1543c41f3411bd6aa74713c8aba4e93fa8d952c7/td/generate/scheme/td_api.tl#L1318

okay, got it. thx for your reply.

levlam commented 1 year ago

For self you can also check that supergroup.status is chatMemberStatusCreator, or it is chatMemberStatusAdministrator and status.rights.can_post_messages == true.