Add td_api::chatPermissions support.

GitOrigin-RevId: 38cc232035e54665e140772b13316c31ecc38df6
This commit is contained in:
levlam 2019-03-20 15:28:06 +03:00
parent ada302aaf2
commit 454d8d3987
9 changed files with 271 additions and 167 deletions

View File

@ -317,6 +317,18 @@ userProfilePhotos total_count:int32 photos:vector<userProfilePhoto> = UserProfil
users total_count:int32 user_ids:vector<int32> = Users; users total_count:int32 user_ids:vector<int32> = Users;
//@description Describes actions permitted to be done by a user in a chat
//@can_send_messages True, if the user can send text messages, contacts, locations, and venues
//@can_send_media_messages True, if the user can send audio files, documents, photos, videos, video notes, and voice notes. Implies can_send_messages permissions
//@can_send_polls True, if the user can send polls. Implies can_send_messages permissions
//@can_send_other_messages True, if the user can send animations, games, and stickers and use inline bots. Implies can_send_media_messages permissions
//@can_add_web_page_previews True, if the user may add a web page preview to his messages. Implies can_send_messages permissions
//@can_change_info True, if the user can change the chat title, photo, and other settings
//@can_invite_users True, if the user can invite new users to the chat
//@can_pin_messages True, if the user can pin messages
chatPermissions can_send_messages:Bool can_send_media_messages:Bool can_send_polls:Bool can_send_other_messages:Bool can_add_web_page_previews:Bool can_change_info:Bool can_invite_users:Bool can_pin_messages:Bool = ChatPermissions;
//@class ChatMemberStatus @description Provides information about the status of a member in a chat //@class ChatMemberStatus @description Provides information about the status of a member in a chat
//@description The user is the creator of a chat and has all the administrator privileges @is_member True, if the user is a member of the chat //@description The user is the creator of a chat and has all the administrator privileges @is_member True, if the user is a member of the chat
@ -340,15 +352,8 @@ chatMemberStatusMember = ChatMemberStatus;
//@description The user is under certain restrictions in the chat. Not supported in basic groups and channels //@description The user is under certain restrictions in the chat. Not supported in basic groups and channels
//@is_member True, if the user is a member of the chat //@is_member True, if the user is a member of the chat
//@restricted_until_date Point in time (Unix timestamp) when restrictions will be lifted from the user; 0 if never. If the user is restricted for more than 366 days or for less than 30 seconds from the current time, the user is considered to be restricted forever //@restricted_until_date Point in time (Unix timestamp) when restrictions will be lifted from the user; 0 if never. If the user is restricted for more than 366 days or for less than 30 seconds from the current time, the user is considered to be restricted forever
//@can_send_messages True, if the user can send text messages, contacts, locations, and venues //@permissions User permissions in the chat
//@can_send_media_messages True, if the user can send audio files, documents, photos, videos, video notes, and voice notes. Implies can_send_messages permissions chatMemberStatusRestricted is_member:Bool restricted_until_date:int32 permissions:chatPermissions = ChatMemberStatus;
//@can_send_polls True, if the user can send polls. Implies can_send_messages permissions
//@can_send_other_messages True, if the user can send animations, games, and stickers and use inline bots. Implies can_send_media_messages permissions
//@can_add_web_page_previews True, if the user may add a web page preview to his messages. Implies can_send_messages permissions
//@can_change_info True, if the user can change the chat title, photo, and other settings; applicable to groups only
//@can_invite_users True, if the user can invite new users to the chat; applicable to groups only
//@can_pin_messages True, if the user can pin messages; applicable to groups only
chatMemberStatusRestricted is_member:Bool restricted_until_date:int32 can_send_messages:Bool can_send_media_messages:Bool can_send_polls:Bool can_send_other_messages:Bool can_add_web_page_previews:Bool can_change_info:Bool can_invite_users:Bool can_pin_messages:Bool = ChatMemberStatus;
//@description The user is not a chat member //@description The user is not a chat member
chatMemberStatusLeft = ChatMemberStatus; chatMemberStatusLeft = ChatMemberStatus;
@ -412,10 +417,9 @@ supergroupMembersFilterBots = SupergroupMembersFilter;
//@id Group identifier //@id Group identifier
//@member_count Number of members in the group //@member_count Number of members in the group
//@status Status of the current user in the group //@status Status of the current user in the group
//@everyone_is_administrator True, if all members have been granted administrator rights in the group
//@is_active True, if the group is active //@is_active True, if the group is active
//@upgraded_to_supergroup_id Identifier of the supergroup to which this group was upgraded; 0 if none //@upgraded_to_supergroup_id Identifier of the supergroup to which this group was upgraded; 0 if none
basicGroup id:int32 member_count:int32 status:ChatMemberStatus everyone_is_administrator:Bool is_active:Bool upgraded_to_supergroup_id:int32 = BasicGroup; basicGroup id:int32 member_count:int32 status:ChatMemberStatus is_active:Bool upgraded_to_supergroup_id:int32 = BasicGroup;
//@description Contains full information about a basic group @param_description Group description @creator_user_id User identifier of the creator of the group; 0 if unknown @members Group members @invite_link Invite link for this group; available only for the group creator and only after it has been generated at least once //@description Contains full information about a basic group @param_description Group description @creator_user_id User identifier of the creator of the group; 0 if unknown @members Group members @invite_link Invite link for this group; available only for the group creator and only after it has been generated at least once
basicGroupFullInfo description:string creator_user_id:int32 members:vector<chatMember> invite_link:string = BasicGroupFullInfo; basicGroupFullInfo description:string creator_user_id:int32 members:vector<chatMember> invite_link:string = BasicGroupFullInfo;
@ -427,13 +431,12 @@ basicGroupFullInfo description:string creator_user_id:int32 members:vector<chatM
//@date Point in time (Unix timestamp) when the current user joined, or the point in time when the supergroup or channel was created, in case the user is not a member //@date Point in time (Unix timestamp) when the current user joined, or the point in time when the supergroup or channel was created, in case the user is not a member
//@status Status of the current user in the supergroup or channel //@status Status of the current user in the supergroup or channel
//@member_count Member count; 0 if unknown. Currently it is guaranteed to be known only if the supergroup or channel was found through SearchPublicChats //@member_count Member count; 0 if unknown. Currently it is guaranteed to be known only if the supergroup or channel was found through SearchPublicChats
//@anyone_can_invite True, if any member of the supergroup can invite other members. This field has no meaning for channels
//@sign_messages True, if messages sent to the channel should contain information about the sender. This field is only applicable to channels //@sign_messages True, if messages sent to the channel should contain information about the sender. This field is only applicable to channels
//@is_channel True, if the supergroup is a channel //@is_channel True, if the supergroup is a channel
//@is_verified True, if the supergroup or channel is verified //@is_verified True, if the supergroup or channel is verified
//@restriction_reason If non-empty, contains the reason why access to this supergroup or channel must be restricted. Format of the string is "{type}: {description}". //@restriction_reason If non-empty, contains the reason why access to this supergroup or channel must be restricted. Format of the string is "{type}: {description}".
//-{type} Contains the type of the restriction and at least one of the suffixes "-all", "-ios", "-android", or "-wp", which describe the platforms on which access should be restricted. (For example, "terms-ios-android". {description} contains a human-readable description of the restriction, which can be shown to the user) //-{type} Contains the type of the restriction and at least one of the suffixes "-all", "-ios", "-android", or "-wp", which describe the platforms on which access should be restricted. (For example, "terms-ios-android". {description} contains a human-readable description of the restriction, which can be shown to the user)
supergroup id:int32 username:string date:int32 status:ChatMemberStatus member_count:int32 anyone_can_invite:Bool sign_messages:Bool is_channel:Bool is_verified:Bool restriction_reason:string = Supergroup; supergroup id:int32 username:string date:int32 status:ChatMemberStatus member_count:int32 sign_messages:Bool is_channel:Bool is_verified:Bool restriction_reason:string = Supergroup;
//@description Contains full information about a supergroup or channel //@description Contains full information about a supergroup or channel
//@param_description Supergroup or channel description //@param_description Supergroup or channel description
@ -595,6 +598,7 @@ chatTypeSecret secret_chat_id:int32 user_id:int32 = ChatType;
//@type Type of the chat //@type Type of the chat
//@title Chat title //@title Chat title
//@photo Chat photo; may be null //@photo Chat photo; may be null
//@permissions Actions permitted for non-administrator chat members
//@last_message Last message in the chat; may be null //@last_message Last message in the chat; may be null
//@order Descending parameter by which chats are sorted in the main chat list. If the order number of two chats is the same, they must be sorted in descending order by ID. If 0, the position of the chat in the list is undetermined //@order Descending parameter by which chats are sorted in the main chat list. If the order number of two chats is the same, they must be sorted in descending order by ID. If 0, the position of the chat in the list is undetermined
//@is_pinned True, if the chat is pinned //@is_pinned True, if the chat is pinned
@ -613,7 +617,7 @@ chatTypeSecret secret_chat_id:int32 user_id:int32 = ChatType;
//@reply_markup_message_id Identifier of the message from which reply markup needs to be used; 0 if there is no default custom reply markup in the chat //@reply_markup_message_id Identifier of the message from which reply markup needs to be used; 0 if there is no default custom reply markup in the chat
//@draft_message A draft of a message in the chat; may be null //@draft_message A draft of a message in the chat; may be null
//@client_data Contains client-specific data associated with the chat. (For example, the chat position or local chat notification settings can be stored here.) Persistent if a message database is used //@client_data Contains client-specific data associated with the chat. (For example, the chat position or local chat notification settings can be stored here.) Persistent if a message database is used
chat id:int53 type:ChatType title:string photo:chatPhoto last_message:message order:int64 is_pinned:Bool is_marked_as_unread:Bool is_sponsored:Bool can_be_deleted_only_for_self:Bool can_be_deleted_for_all_users:Bool can_be_reported:Bool default_disable_notification:Bool unread_count:int32 last_read_inbox_message_id:int53 last_read_outbox_message_id:int53 unread_mention_count:int32 notification_settings:chatNotificationSettings pinned_message_id:int53 reply_markup_message_id:int53 draft_message:draftMessage client_data:string = Chat; chat id:int53 type:ChatType title:string photo:chatPhoto permissions:chatPermissions last_message:message order:int64 is_pinned:Bool is_marked_as_unread:Bool is_sponsored:Bool can_be_deleted_only_for_self:Bool can_be_deleted_for_all_users:Bool can_be_reported:Bool default_disable_notification:Bool unread_count:int32 last_read_inbox_message_id:int53 last_read_outbox_message_id:int53 unread_mention_count:int32 notification_settings:chatNotificationSettings pinned_message_id:int53 reply_markup_message_id:int53 draft_message:draftMessage client_data:string = Chat;
//@description Represents a list of chats @chat_ids List of chat identifiers //@description Represents a list of chats @chat_ids List of chat identifiers
chats chat_ids:vector<int53> = Chats; chats chat_ids:vector<int53> = Chats;
@ -2468,6 +2472,9 @@ updateChatTitle chat_id:int53 title:string = Update;
//@description A chat photo was changed @chat_id Chat identifier @photo The new chat photo; may be null //@description A chat photo was changed @chat_id Chat identifier @photo The new chat photo; may be null
updateChatPhoto chat_id:int53 photo:chatPhoto = Update; updateChatPhoto chat_id:int53 photo:chatPhoto = Update;
//@description Chat permissions was changed @chat_id Chat identifier @permissions The new chat permissions
updateChatPermissions chat_id:int53 permissions:chatPermissions = Update;
//@description The last message of a chat was changed. If last_message is null then the last message in the chat became unknown. Some new unknown messages might be added to the chat in this case @chat_id Chat identifier @last_message The new last message in the chat; may be null @order New value of the chat order //@description The last message of a chat was changed. If last_message is null then the last message in the chat became unknown. Some new unknown messages might be added to the chat in this case @chat_id Chat identifier @last_message The new last message in the chat; may be null @order New value of the chat order
updateChatLastMessage chat_id:int53 last_message:message order:int64 = Update; updateChatLastMessage chat_id:int53 last_message:message order:int64 = Update;

Binary file not shown.

View File

@ -2547,7 +2547,7 @@ void ContactsManager::Chat::store(StorerT &storer) const {
store(migrated_to_channel_id, storer); store(migrated_to_channel_id, storer);
store(version, storer); store(version, storer);
store(status, storer); store(status, storer);
store(default_restricted_rights, storer); store(default_permissions, storer);
} }
template <class ParserT> template <class ParserT>
@ -2583,7 +2583,7 @@ void ContactsManager::Chat::parse(ParserT &parser) {
parse(version, parser); parse(version, parser);
if (use_new_rights) { if (use_new_rights) {
parse(status, parser); parse(status, parser);
parse(default_restricted_rights, parser); parse(default_permissions, parser);
} else { } else {
if (kicked || !is_active) { if (kicked || !is_active) {
status = DialogParticipantStatus::Banned(0); status = DialogParticipantStatus::Banned(0);
@ -2596,8 +2596,7 @@ void ContactsManager::Chat::parse(ParserT &parser) {
} else { } else {
status = DialogParticipantStatus::Member(); status = DialogParticipantStatus::Member();
} }
default_restricted_rights = default_permissions = RestrictedRights(true, true, true, true, true, true, true, true, everyone_is_administrator,
RestrictedRights(true, true, true, true, true, true, true, true, everyone_is_administrator,
everyone_is_administrator, everyone_is_administrator); everyone_is_administrator, everyone_is_administrator);
} }
} }
@ -2609,7 +2608,7 @@ void ContactsManager::Channel::store(StorerT &storer) const {
bool has_username = !username.empty(); bool has_username = !username.empty();
bool is_restricted = !restriction_reason.empty(); bool is_restricted = !restriction_reason.empty();
bool use_new_rights = true; bool use_new_rights = true;
bool have_default_restricted_rights = true; bool have_default_permissions = true;
bool have_participant_count = participant_count != 0; bool have_participant_count = participant_count != 0;
BEGIN_STORE_FLAGS(); BEGIN_STORE_FLAGS();
STORE_FLAG(false); STORE_FLAG(false);
@ -2626,7 +2625,7 @@ void ContactsManager::Channel::store(StorerT &storer) const {
STORE_FLAG(is_restricted); STORE_FLAG(is_restricted);
STORE_FLAG(use_new_rights); STORE_FLAG(use_new_rights);
STORE_FLAG(have_participant_count); STORE_FLAG(have_participant_count);
STORE_FLAG(have_default_restricted_rights); STORE_FLAG(have_default_permissions);
END_STORE_FLAGS(); END_STORE_FLAGS();
store(status, storer); store(status, storer);
@ -2646,7 +2645,7 @@ void ContactsManager::Channel::store(StorerT &storer) const {
store(participant_count, storer); store(participant_count, storer);
} }
if (is_megagroup) { if (is_megagroup) {
store(default_restricted_rights, storer); store(default_permissions, storer);
} }
} }
@ -2664,7 +2663,7 @@ void ContactsManager::Channel::parse(ParserT &parser) {
bool anyone_can_invite; bool anyone_can_invite;
bool use_new_rights; bool use_new_rights;
bool have_participant_count; bool have_participant_count;
bool have_default_restricted_rights; bool have_default_permissions;
BEGIN_PARSE_FLAGS(); BEGIN_PARSE_FLAGS();
PARSE_FLAG(left); PARSE_FLAG(left);
PARSE_FLAG(kicked); PARSE_FLAG(kicked);
@ -2680,7 +2679,7 @@ void ContactsManager::Channel::parse(ParserT &parser) {
PARSE_FLAG(is_restricted); PARSE_FLAG(is_restricted);
PARSE_FLAG(use_new_rights); PARSE_FLAG(use_new_rights);
PARSE_FLAG(have_participant_count); PARSE_FLAG(have_participant_count);
PARSE_FLAG(have_default_restricted_rights); PARSE_FLAG(have_default_permissions);
END_PARSE_FLAGS(); END_PARSE_FLAGS();
if (use_new_rights) { if (use_new_rights) {
@ -2714,10 +2713,10 @@ void ContactsManager::Channel::parse(ParserT &parser) {
parse(participant_count, parser); parse(participant_count, parser);
} }
if (is_megagroup) { if (is_megagroup) {
if (have_default_restricted_rights) { if (have_default_permissions) {
parse(default_restricted_rights, parser); parse(default_permissions, parser);
} else { } else {
default_restricted_rights = default_permissions =
RestrictedRights(true, true, true, true, true, true, true, true, false, anyone_can_invite, false); RestrictedRights(true, true, true, true, true, true, true, true, false, anyone_can_invite, false);
} }
} }
@ -3014,6 +3013,40 @@ string ContactsManager::get_secret_chat_title(SecretChatId secret_chat_id) const
return get_user_title(c->user_id); return get_user_title(c->user_id);
} }
RestrictedRights ContactsManager::get_user_default_permissions(UserId user_id) const {
auto u = get_user(user_id);
if (u == nullptr) {
return RestrictedRights(false, false, false, false, false, false, false, false, false, false, false);
}
bool can_pin_messages = user_id == get_my_id(); /* TODO */
return RestrictedRights(true, true, true, true, true, true, true, true, false, false, can_pin_messages);
}
RestrictedRights ContactsManager::get_chat_default_permissions(ChatId chat_id) const {
auto c = get_chat(chat_id);
if (c == nullptr) {
return RestrictedRights(false, false, false, false, false, false, false, false, false, false, false);
}
return c->default_permissions;
}
RestrictedRights ContactsManager::get_channel_default_permissions(ChannelId channel_id) const {
auto c = get_channel(channel_id);
if (c == nullptr) {
return RestrictedRights(false, false, false, false, false, false, false, false, false, false, false);
}
return c->default_permissions;
}
RestrictedRights ContactsManager::get_secret_chat_default_permissions(SecretChatId secret_chat_id) const {
auto c = get_secret_chat(secret_chat_id);
if (c == nullptr) {
return RestrictedRights(false, false, false, false, false, false, false, false, false, false, false);
}
return RestrictedRights(true, true, true, true, true, true, true, true, false, false, false);
}
int32 ContactsManager::get_secret_chat_date(SecretChatId secret_chat_id) const { int32 ContactsManager::get_secret_chat_date(SecretChatId secret_chat_id) const {
auto c = get_secret_chat(secret_chat_id); auto c = get_secret_chat(secret_chat_id);
if (c == nullptr) { if (c == nullptr) {
@ -6252,8 +6285,12 @@ void ContactsManager::update_chat(Chat *c, ChatId chat_id, bool from_binlog, boo
if (c->is_title_changed) { if (c->is_title_changed) {
td_->messages_manager_->on_dialog_title_updated(DialogId(chat_id)); td_->messages_manager_->on_dialog_title_updated(DialogId(chat_id));
} }
if (c->is_default_permissions_changed) {
td_->messages_manager_->on_dialog_permissions_updated(DialogId(chat_id));
}
c->is_photo_changed = false; c->is_photo_changed = false;
c->is_title_changed = false; c->is_title_changed = false;
c->is_default_permissions_changed = false;
LOG(DEBUG) << "Update " << chat_id << ": is_changed = " << c->is_changed LOG(DEBUG) << "Update " << chat_id << ": is_changed = " << c->is_changed
<< ", need_send_update = " << c->need_send_update; << ", need_send_update = " << c->need_send_update;
@ -6319,8 +6356,12 @@ void ContactsManager::update_channel(Channel *c, ChannelId channel_id, bool from
} }
} }
} }
if (c->is_default_permissions_changed) {
td_->messages_manager_->on_dialog_permissions_updated(DialogId(channel_id));
}
c->is_photo_changed = false; c->is_photo_changed = false;
c->is_title_changed = false; c->is_title_changed = false;
c->is_default_permissions_changed = false;
c->is_status_changed = false; c->is_status_changed = false;
c->is_username_changed = false; c->is_username_changed = false;
@ -8246,12 +8287,14 @@ void ContactsManager::on_update_chat_status(Chat *c, ChatId chat_id, DialogParti
} }
} }
void ContactsManager::on_update_chat_default_restricted_rights(Chat *c, ChatId chat_id, RestrictedRights rights) { void ContactsManager::on_update_chat_default_permissions(Chat *c, ChatId chat_id,
if (c->default_restricted_rights != rights) { RestrictedRights default_permissions) {
LOG(INFO) << "Update " << chat_id << " default restricted rights from " << c->default_restricted_rights << " to " if (c->default_permissions != default_permissions) {
<< rights; LOG(INFO) << "Update " << chat_id << " default permissions from " << c->default_permissions << " to "
c->default_restricted_rights = rights; << default_permissions;
c->need_send_update = true; c->default_permissions = default_permissions;
c->is_default_permissions_changed = true;
c->is_changed = true;
} }
} }
@ -8451,13 +8494,14 @@ void ContactsManager::on_update_channel_status(Channel *c, ChannelId channel_id,
} }
} }
void ContactsManager::on_update_channel_default_restricted_rights(Channel *c, ChannelId channel_id, void ContactsManager::on_update_channel_default_permissions(Channel *c, ChannelId channel_id,
RestrictedRights rights) { RestrictedRights default_permissions) {
if (c->default_restricted_rights != rights) { if (c->default_permissions != default_permissions) {
LOG(INFO) << "Update " << channel_id << " default restricted rights from " << c->default_restricted_rights << " to " LOG(INFO) << "Update " << channel_id << " default permissions from " << c->default_permissions << " to "
<< rights; << default_permissions;
c->default_restricted_rights = rights; c->default_permissions = default_permissions;
c->need_send_update = true; c->is_default_permissions_changed = true;
c->is_changed = true;
} }
} }
@ -9819,7 +9863,7 @@ void ContactsManager::on_chat_update(telegram_api::chat &chat, const char *sourc
c->is_changed = true; c->is_changed = true;
} }
on_update_chat_status(c, chat_id, std::move(status)); on_update_chat_status(c, chat_id, std::move(status));
on_update_chat_default_restricted_rights(c, chat_id, get_restricted_rights(std::move(chat.default_banned_rights_))); on_update_chat_default_permissions(c, chat_id, get_restricted_rights(std::move(chat.default_banned_rights_)));
on_update_chat_photo(c, chat_id, std::move(chat.photo_)); on_update_chat_photo(c, chat_id, std::move(chat.photo_));
on_update_chat_active(c, chat_id, is_active); on_update_chat_active(c, chat_id, is_active);
on_update_chat_migrated_to_channel_id(c, chat_id, migrated_to_channel_id); on_update_chat_migrated_to_channel_id(c, chat_id, migrated_to_channel_id);
@ -9918,7 +9962,7 @@ void ContactsManager::on_chat_update(telegram_api::channel &channel, const char
on_update_channel_title(c, channel_id, std::move(channel.title_)); on_update_channel_title(c, channel_id, std::move(channel.title_));
on_update_channel_username(c, channel_id, std::move(channel.username_)); on_update_channel_username(c, channel_id, std::move(channel.username_));
on_update_channel_photo(c, channel_id, std::move(channel.photo_)); on_update_channel_photo(c, channel_id, std::move(channel.photo_));
on_update_channel_default_restricted_rights(c, channel_id, on_update_channel_default_permissions(c, channel_id,
get_restricted_rights(std::move(channel.default_banned_rights_))); get_restricted_rights(std::move(channel.default_banned_rights_)));
if (c->is_megagroup != is_megagroup || c->is_verified != is_verified) { if (c->is_megagroup != is_megagroup || c->is_verified != is_verified) {
@ -9956,7 +10000,7 @@ void ContactsManager::on_chat_update(telegram_api::channel &channel, const char
on_update_channel_photo(c, channel_id, std::move(channel.photo_)); on_update_channel_photo(c, channel_id, std::move(channel.photo_));
on_update_channel_status(c, channel_id, std::move(status)); on_update_channel_status(c, channel_id, std::move(status));
on_update_channel_username(c, channel_id, std::move(channel.username_)); // uses status, must be called after on_update_channel_username(c, channel_id, std::move(channel.username_)); // uses status, must be called after
on_update_channel_default_restricted_rights(c, channel_id, on_update_channel_default_permissions(c, channel_id,
get_restricted_rights(std::move(channel.default_banned_rights_))); get_restricted_rights(std::move(channel.default_banned_rights_)));
if (participant_count != 0 && participant_count != c->participant_count) { if (participant_count != 0 && participant_count != c->participant_count) {
@ -10012,7 +10056,7 @@ void ContactsManager::on_chat_update(telegram_api::channelForbidden &channel, co
int32 unban_date = (channel.flags_ & CHANNEL_FLAG_HAS_UNBAN_DATE) != 0 ? channel.until_date_ : 0; int32 unban_date = (channel.flags_ & CHANNEL_FLAG_HAS_UNBAN_DATE) != 0 ? channel.until_date_ : 0;
on_update_channel_status(c, channel_id, DialogParticipantStatus::Banned(unban_date)); on_update_channel_status(c, channel_id, DialogParticipantStatus::Banned(unban_date));
on_update_channel_username(c, channel_id, ""); // don't know if channel username is empty, but update it anyway on_update_channel_username(c, channel_id, ""); // don't know if channel username is empty, but update it anyway
on_update_channel_default_restricted_rights(c, channel_id, get_restricted_rights(nullptr)); on_update_channel_default_permissions(c, channel_id, get_restricted_rights(nullptr));
bool sign_messages = false; bool sign_messages = false;
bool is_megagroup = (channel.flags_ & CHANNEL_FLAG_IS_MEGAGROUP) != 0; bool is_megagroup = (channel.flags_ & CHANNEL_FLAG_IS_MEGAGROUP) != 0;
@ -10185,10 +10229,9 @@ int32 ContactsManager::get_basic_group_id_object(ChatId chat_id, const char *sou
if (chat_id.is_valid() && get_chat(chat_id) == nullptr && unknown_chats_.count(chat_id) == 0) { if (chat_id.is_valid() && get_chat(chat_id) == nullptr && unknown_chats_.count(chat_id) == 0) {
LOG(ERROR) << "Have no info about " << chat_id << " from " << source; LOG(ERROR) << "Have no info about " << chat_id << " from " << source;
unknown_chats_.insert(chat_id); unknown_chats_.insert(chat_id);
send_closure( send_closure(G()->td(), &Td::send_update,
G()->td(), &Td::send_update,
td_api::make_object<td_api::updateBasicGroup>(td_api::make_object<td_api::basicGroup>( td_api::make_object<td_api::updateBasicGroup>(td_api::make_object<td_api::basicGroup>(
chat_id.get(), 0, DialogParticipantStatus::Banned(0).get_chat_member_status_object(), true, true, 0))); chat_id.get(), 0, DialogParticipantStatus::Banned(0).get_chat_member_status_object(), true, 0)));
} }
return chat_id.get(); return chat_id.get();
} }
@ -10209,11 +10252,8 @@ tl_object_ptr<td_api::basicGroup> ContactsManager::get_basic_group_object(ChatId
tl_object_ptr<td_api::basicGroup> ContactsManager::get_basic_group_object_const(ChatId chat_id, tl_object_ptr<td_api::basicGroup> ContactsManager::get_basic_group_object_const(ChatId chat_id,
const Chat *chat) const { const Chat *chat) const {
auto everyone_is_administrator = chat->default_restricted_rights ==
RestrictedRights(true, true, true, true, true, true, true, true, true, true, true);
return make_tl_object<td_api::basicGroup>( return make_tl_object<td_api::basicGroup>(
chat_id.get(), chat->participant_count, get_chat_status(chat).get_chat_member_status_object(), chat_id.get(), chat->participant_count, get_chat_status(chat).get_chat_member_status_object(), chat->is_active,
everyone_is_administrator, chat->is_active,
get_supergroup_id_object(chat->migrated_to_channel_id, "get_basic_group_object")); get_supergroup_id_object(chat->migrated_to_channel_id, "get_basic_group_object"));
} }
@ -10238,7 +10278,7 @@ int32 ContactsManager::get_supergroup_id_object(ChannelId channel_id, const char
send_closure(G()->td(), &Td::send_update, send_closure(G()->td(), &Td::send_update,
td_api::make_object<td_api::updateSupergroup>(td_api::make_object<td_api::supergroup>( td_api::make_object<td_api::updateSupergroup>(td_api::make_object<td_api::supergroup>(
channel_id.get(), string(), 0, DialogParticipantStatus::Banned(0).get_chat_member_status_object(), channel_id.get(), string(), 0, DialogParticipantStatus::Banned(0).get_chat_member_status_object(),
0, false, false, true, false, ""))); 0, false, true, false, "")));
} }
return channel_id.get(); return channel_id.get();
} }
@ -10252,10 +10292,10 @@ tl_object_ptr<td_api::supergroup> ContactsManager::get_supergroup_object(Channel
if (channel == nullptr) { if (channel == nullptr) {
return nullptr; return nullptr;
} }
return make_tl_object<td_api::supergroup>( return make_tl_object<td_api::supergroup>(channel_id.get(), channel->username, channel->date,
channel_id.get(), channel->username, channel->date, get_channel_status(channel).get_chat_member_status_object(), get_channel_status(channel).get_chat_member_status_object(),
channel->participant_count, channel->default_restricted_rights.can_invite_users(), channel->sign_messages, channel->participant_count, channel->sign_messages, !channel->is_megagroup,
!channel->is_megagroup, channel->is_verified, channel->restriction_reason); channel->is_verified, channel->restriction_reason);
} }
tl_object_ptr<td_api::supergroupFullInfo> ContactsManager::get_supergroup_full_info_object(ChannelId channel_id) const { tl_object_ptr<td_api::supergroupFullInfo> ContactsManager::get_supergroup_full_info_object(ChannelId channel_id) const {

View File

@ -98,6 +98,11 @@ class ContactsManager : public Actor {
string get_channel_title(ChannelId channel_id) const; string get_channel_title(ChannelId channel_id) const;
string get_secret_chat_title(SecretChatId secret_chat_id) const; string get_secret_chat_title(SecretChatId secret_chat_id) const;
RestrictedRights get_user_default_permissions(UserId user_id) const;
RestrictedRights get_chat_default_permissions(ChatId chat_id) const;
RestrictedRights get_channel_default_permissions(ChannelId channel_id) const;
RestrictedRights get_secret_chat_default_permissions(SecretChatId secret_chat_id) const;
bool is_update_about_username_change_received(UserId user_id) const; bool is_update_about_username_change_received(UserId user_id) const;
string get_user_username(UserId user_id) const; string get_user_username(UserId user_id) const;
@ -566,13 +571,13 @@ class ContactsManager : public Actor {
ChannelId migrated_to_channel_id; ChannelId migrated_to_channel_id;
DialogParticipantStatus status = DialogParticipantStatus::Banned(0); DialogParticipantStatus status = DialogParticipantStatus::Banned(0);
RestrictedRights default_restricted_rights{false, false, false, false, false, false, RestrictedRights default_permissions{false, false, false, false, false, false, false, false, false, false, false};
false, false, false, false, false};
bool is_active = false; bool is_active = false;
bool is_title_changed = true; bool is_title_changed = true;
bool is_photo_changed = true; bool is_photo_changed = true;
bool is_default_permissions_changed = true;
bool is_changed = true; // have new changes not sent to the database except changes visible to the client bool is_changed = true; // have new changes not sent to the database except changes visible to the client
bool need_send_update = true; // have new changes not sent to the client bool need_send_update = true; // have new changes not sent to the client
@ -607,8 +612,7 @@ class ContactsManager : public Actor {
string username; string username;
string restriction_reason; string restriction_reason;
DialogParticipantStatus status = DialogParticipantStatus::Banned(0); DialogParticipantStatus status = DialogParticipantStatus::Banned(0);
RestrictedRights default_restricted_rights{false, false, false, false, false, false, RestrictedRights default_permissions{false, false, false, false, false, false, false, false, false, false, false};
false, false, false, false, false};
int32 date = 0; int32 date = 0;
int32 participant_count = 0; int32 participant_count = 0;
@ -620,6 +624,7 @@ class ContactsManager : public Actor {
bool is_title_changed = true; bool is_title_changed = true;
bool is_username_changed = true; bool is_username_changed = true;
bool is_photo_changed = true; bool is_photo_changed = true;
bool is_default_permissions_changed = true;
bool is_status_changed = true; bool is_status_changed = true;
bool had_read_access = true; bool had_read_access = true;
bool was_member = false; bool was_member = false;
@ -879,7 +884,7 @@ class ContactsManager : public Actor {
void invalidate_user_full(UserId user_id); void invalidate_user_full(UserId user_id);
void on_update_chat_status(Chat *c, ChatId chat_id, DialogParticipantStatus status); void on_update_chat_status(Chat *c, ChatId chat_id, DialogParticipantStatus status);
void on_update_chat_default_restricted_rights(Chat *c, ChatId chat_id, RestrictedRights rights); void on_update_chat_default_permissions(Chat *c, ChatId chat_id, RestrictedRights default_permissions);
void on_update_chat_participant_count(Chat *c, ChatId chat_id, int32 participant_count, int32 version, void on_update_chat_participant_count(Chat *c, ChatId chat_id, int32 participant_count, int32 version,
const string &debug_str); const string &debug_str);
void on_update_chat_photo(Chat *c, ChatId chat_id, tl_object_ptr<telegram_api::ChatPhoto> &&chat_photo_ptr); void on_update_chat_photo(Chat *c, ChatId chat_id, tl_object_ptr<telegram_api::ChatPhoto> &&chat_photo_ptr);
@ -898,7 +903,7 @@ class ContactsManager : public Actor {
void on_update_channel_title(Channel *c, ChannelId channel_id, string &&title); void on_update_channel_title(Channel *c, ChannelId channel_id, string &&title);
void on_update_channel_username(Channel *c, ChannelId channel_id, string &&username); void on_update_channel_username(Channel *c, ChannelId channel_id, string &&username);
void on_update_channel_status(Channel *c, ChannelId channel_id, DialogParticipantStatus &&status); void on_update_channel_status(Channel *c, ChannelId channel_id, DialogParticipantStatus &&status);
void on_update_channel_default_restricted_rights(Channel *c, ChannelId channel_id, RestrictedRights rights); void on_update_channel_default_permissions(Channel *c, ChannelId channel_id, RestrictedRights default_permissions);
void on_update_channel_full_invite_link(ChannelFull *channel_full, void on_update_channel_full_invite_link(ChannelFull *channel_full,
tl_object_ptr<telegram_api::ExportedChatInvite> &&invite_link_ptr); tl_object_ptr<telegram_api::ExportedChatInvite> &&invite_link_ptr);

View File

@ -93,6 +93,12 @@ DialogParticipantStatus DialogParticipantStatus::ChannelAdministrator(bool is_cr
} }
} }
RestrictedRights DialogParticipantStatus::get_restricted_rights() const {
return RestrictedRights(can_send_messages(), can_send_media(), can_send_stickers(), can_send_animations(),
can_send_games(), can_use_inline_bots(), can_add_web_page_previews(), can_send_polls(),
can_change_info_and_settings(), can_invite_users(), can_pin_messages());
}
tl_object_ptr<td_api::ChatMemberStatus> DialogParticipantStatus::get_chat_member_status_object() const { tl_object_ptr<td_api::ChatMemberStatus> DialogParticipantStatus::get_chat_member_status_object() const {
switch (type_) { switch (type_) {
case Type::Creator: case Type::Creator:
@ -104,10 +110,8 @@ tl_object_ptr<td_api::ChatMemberStatus> DialogParticipantStatus::get_chat_member
case Type::Member: case Type::Member:
return make_tl_object<td_api::chatMemberStatusMember>(); return make_tl_object<td_api::chatMemberStatusMember>();
case Type::Restricted: case Type::Restricted:
return make_tl_object<td_api::chatMemberStatusRestricted>( return make_tl_object<td_api::chatMemberStatusRestricted>(is_member(), until_date_,
is_member(), until_date_, can_send_messages(), can_send_media(), can_send_polls(), get_restricted_rights().get_chat_permissions_object());
can_send_stickers() && can_send_animations() && can_send_games() && can_use_inline_bots(),
can_add_web_page_previews(), can_change_info_and_settings(), can_invite_users(), can_pin_messages());
case Type::Left: case Type::Left:
return make_tl_object<td_api::chatMemberStatusLeft>(); return make_tl_object<td_api::chatMemberStatusLeft>();
case Type::Banned: case Type::Banned:
@ -339,13 +343,17 @@ DialogParticipantStatus get_dialog_participant_status(const tl_object_ptr<td_api
return DialogParticipantStatus::Member(); return DialogParticipantStatus::Member();
case td_api::chatMemberStatusRestricted::ID: { case td_api::chatMemberStatusRestricted::ID: {
auto st = static_cast<const td_api::chatMemberStatusRestricted *>(status.get()); auto st = static_cast<const td_api::chatMemberStatusRestricted *>(status.get());
bool can_send_media = auto permissions = st->permissions_.get();
st->can_send_media_messages_ || st->can_send_other_messages_ || st->can_add_web_page_previews_; bool can_send_polls = permissions->can_send_polls_;
bool can_send_media = permissions->can_send_media_messages_ || permissions->can_send_other_messages_ ||
permissions->can_add_web_page_previews_;
bool can_send_messages = permissions->can_send_messages_ || can_send_media || can_send_polls;
return DialogParticipantStatus::Restricted( return DialogParticipantStatus::Restricted(
st->is_member_, st->restricted_until_date_, st->can_send_messages_ || can_send_media, can_send_media, st->is_member_, st->restricted_until_date_, can_send_messages, can_send_media,
st->can_send_other_messages_, st->can_send_other_messages_, st->can_send_other_messages_, permissions->can_send_other_messages_, permissions->can_send_other_messages_,
st->can_send_other_messages_, st->can_add_web_page_previews_, st->can_send_polls_, st->can_change_info_, permissions->can_send_other_messages_, permissions->can_send_other_messages_,
st->can_invite_users_, st->can_pin_messages_); permissions->can_add_web_page_previews_, permissions->can_send_polls_, permissions->can_change_info_,
permissions->can_invite_users_, permissions->can_pin_messages_);
} }
case td_api::chatMemberStatusLeft::ID: case td_api::chatMemberStatusLeft::ID:
return DialogParticipantStatus::Left(); return DialogParticipantStatus::Left();
@ -414,6 +422,13 @@ RestrictedRights::RestrictedRights(bool can_send_messages, bool can_send_media,
(static_cast<uint32>(can_pin_messages) * CAN_PIN_MESSAGES); (static_cast<uint32>(can_pin_messages) * CAN_PIN_MESSAGES);
} }
tl_object_ptr<td_api::chatPermissions> RestrictedRights::get_chat_permissions_object() const {
return td_api::make_object<td_api::chatPermissions>(
can_send_messages(), can_send_media(), can_send_polls(),
can_send_stickers() && can_send_animations() && can_send_games() && can_use_inline_bots(),
can_add_web_page_previews(), can_change_info_and_settings(), can_invite_users(), can_pin_messages());
}
tl_object_ptr<telegram_api::chatBannedRights> RestrictedRights::get_chat_banned_rights() const { tl_object_ptr<telegram_api::chatBannedRights> RestrictedRights::get_chat_banned_rights() const {
int32 flags = 0; int32 flags = 0;
if (!can_send_messages()) { if (!can_send_messages()) {

View File

@ -17,6 +17,95 @@
namespace td { namespace td {
class RestrictedRights {
static constexpr uint32 CAN_SEND_MESSAGES = 1 << 16;
static constexpr uint32 CAN_SEND_MEDIA = 1 << 17;
static constexpr uint32 CAN_SEND_STICKERS = 1 << 18;
static constexpr uint32 CAN_SEND_ANIMATIONS = 1 << 19;
static constexpr uint32 CAN_SEND_GAMES = 1 << 20;
static constexpr uint32 CAN_USE_INLINE_BOTS = 1 << 21;
static constexpr uint32 CAN_ADD_WEB_PAGE_PREVIEWS = 1 << 22;
static constexpr uint32 CAN_SEND_POLLS = 1 << 23;
static constexpr uint32 CAN_CHANGE_INFO_AND_SETTINGS = 1 << 24;
static constexpr uint32 CAN_INVITE_USERS = 1 << 25;
static constexpr uint32 CAN_PIN_MESSAGES = 1 << 26;
uint32 flags_;
public:
RestrictedRights(bool can_send_messages, bool can_send_media, bool can_send_stickers, bool can_send_animations,
bool can_send_games, bool can_use_inline_bots, bool can_add_web_page_previews, bool can_send_polls,
bool can_change_info_and_settings, bool can_invite_users, bool can_pin_messages);
td_api::object_ptr<td_api::chatPermissions> get_chat_permissions_object() const;
tl_object_ptr<telegram_api::chatBannedRights> get_chat_banned_rights() const;
bool can_change_info_and_settings() const {
return (flags_ & CAN_CHANGE_INFO_AND_SETTINGS) != 0;
}
bool can_invite_users() const {
return (flags_ & CAN_INVITE_USERS);
}
bool can_pin_messages() const {
return (flags_ & CAN_PIN_MESSAGES) != 0;
}
bool can_send_messages() const {
return (flags_ & CAN_SEND_MESSAGES) != 0;
}
bool can_send_media() const {
return (flags_ & CAN_SEND_MEDIA) != 0;
}
bool can_send_stickers() const {
return (flags_ & CAN_SEND_STICKERS) != 0;
}
bool can_send_animations() const {
return (flags_ & CAN_SEND_ANIMATIONS) != 0;
}
bool can_send_games() const {
return (flags_ & CAN_SEND_GAMES) != 0;
}
bool can_use_inline_bots() const {
return (flags_ & CAN_USE_INLINE_BOTS) != 0;
}
bool can_add_web_page_previews() const {
return (flags_ & CAN_ADD_WEB_PAGE_PREVIEWS) != 0;
}
bool can_send_polls() const {
return (flags_ & CAN_SEND_POLLS) != 0;
}
template <class StorerT>
void store(StorerT &storer) const {
td::store(flags_, storer);
}
template <class ParserT>
void parse(ParserT &parser) {
td::parse(flags_, parser);
}
friend bool operator==(const RestrictedRights &lhs, const RestrictedRights &rhs);
friend StringBuilder &operator<<(StringBuilder &string_builder, const RestrictedRights &status);
};
bool operator==(const RestrictedRights &lhs, const RestrictedRights &rhs);
bool operator!=(const RestrictedRights &lhs, const RestrictedRights &rhs);
StringBuilder &operator<<(StringBuilder &string_builder, const RestrictedRights &status);
class DialogParticipantStatus { class DialogParticipantStatus {
static constexpr uint32 CAN_CHANGE_INFO_AND_SETTINGS_ADMIN = 1 << 0; static constexpr uint32 CAN_CHANGE_INFO_AND_SETTINGS_ADMIN = 1 << 0;
static constexpr uint32 CAN_POST_MESSAGES = 1 << 1; static constexpr uint32 CAN_POST_MESSAGES = 1 << 1;
@ -96,6 +185,8 @@ class DialogParticipantStatus {
// legacy rights // legacy rights
static DialogParticipantStatus ChannelAdministrator(bool is_creator, bool is_megagroup); static DialogParticipantStatus ChannelAdministrator(bool is_creator, bool is_megagroup);
RestrictedRights get_restricted_rights() const;
tl_object_ptr<td_api::ChatMemberStatus> get_chat_member_status_object() const; tl_object_ptr<td_api::ChatMemberStatus> get_chat_member_status_object() const;
tl_object_ptr<telegram_api::chatAdminRights> get_chat_admin_rights() const; tl_object_ptr<telegram_api::chatAdminRights> get_chat_admin_rights() const;
@ -244,93 +335,6 @@ bool operator!=(const DialogParticipantStatus &lhs, const DialogParticipantStatu
StringBuilder &operator<<(StringBuilder &string_builder, const DialogParticipantStatus &status); StringBuilder &operator<<(StringBuilder &string_builder, const DialogParticipantStatus &status);
class RestrictedRights {
static constexpr uint32 CAN_SEND_MESSAGES = 1 << 16;
static constexpr uint32 CAN_SEND_MEDIA = 1 << 17;
static constexpr uint32 CAN_SEND_STICKERS = 1 << 18;
static constexpr uint32 CAN_SEND_ANIMATIONS = 1 << 19;
static constexpr uint32 CAN_SEND_GAMES = 1 << 20;
static constexpr uint32 CAN_USE_INLINE_BOTS = 1 << 21;
static constexpr uint32 CAN_ADD_WEB_PAGE_PREVIEWS = 1 << 22;
static constexpr uint32 CAN_SEND_POLLS = 1 << 23;
static constexpr uint32 CAN_CHANGE_INFO_AND_SETTINGS = 1 << 24;
static constexpr uint32 CAN_INVITE_USERS = 1 << 25;
static constexpr uint32 CAN_PIN_MESSAGES = 1 << 26;
uint32 flags_;
public:
RestrictedRights(bool can_send_messages, bool can_send_media, bool can_send_stickers, bool can_send_animations,
bool can_send_games, bool can_use_inline_bots, bool can_add_web_page_previews, bool can_send_polls,
bool can_change_info_and_settings, bool can_invite_users, bool can_pin_messages);
tl_object_ptr<telegram_api::chatBannedRights> get_chat_banned_rights() const;
bool can_change_info_and_settings() const {
return (flags_ & CAN_CHANGE_INFO_AND_SETTINGS) != 0;
}
bool can_invite_users() const {
return (flags_ & CAN_INVITE_USERS);
}
bool can_pin_messages() const {
return (flags_ & CAN_PIN_MESSAGES) != 0;
}
bool can_send_messages() const {
return (flags_ & CAN_SEND_MESSAGES) != 0;
}
bool can_send_media() const {
return (flags_ & CAN_SEND_MEDIA) != 0;
}
bool can_send_stickers() const {
return (flags_ & CAN_SEND_STICKERS) != 0;
}
bool can_send_animations() const {
return (flags_ & CAN_SEND_ANIMATIONS) != 0;
}
bool can_send_games() const {
return (flags_ & CAN_SEND_GAMES) != 0;
}
bool can_use_inline_bots() const {
return (flags_ & CAN_USE_INLINE_BOTS) != 0;
}
bool can_add_web_page_previews() const {
return (flags_ & CAN_ADD_WEB_PAGE_PREVIEWS) != 0;
}
bool can_send_polls() const {
return (flags_ & CAN_SEND_POLLS) != 0;
}
template <class StorerT>
void store(StorerT &storer) const {
td::store(flags_, storer);
}
template <class ParserT>
void parse(ParserT &parser) {
td::parse(flags_, parser);
}
friend bool operator==(const RestrictedRights &lhs, const RestrictedRights &rhs);
friend StringBuilder &operator<<(StringBuilder &string_builder, const RestrictedRights &status);
};
bool operator==(const RestrictedRights &lhs, const RestrictedRights &rhs);
bool operator!=(const RestrictedRights &lhs, const RestrictedRights &rhs);
StringBuilder &operator<<(StringBuilder &string_builder, const RestrictedRights &status);
struct DialogParticipant { struct DialogParticipant {
UserId user_id; UserId user_id;
UserId inviter_user_id; UserId inviter_user_id;

View File

@ -13387,6 +13387,7 @@ tl_object_ptr<td_api::chat> MessagesManager::get_chat_object(const Dialog *d) co
return make_tl_object<td_api::chat>( return make_tl_object<td_api::chat>(
d->dialog_id.get(), get_chat_type_object(d->dialog_id), get_dialog_title(d->dialog_id), d->dialog_id.get(), get_chat_type_object(d->dialog_id), get_dialog_title(d->dialog_id),
get_chat_photo_object(td_->file_manager_.get(), get_dialog_photo(d->dialog_id)), get_chat_photo_object(td_->file_manager_.get(), get_dialog_photo(d->dialog_id)),
get_dialog_permissions(d->dialog_id).get_chat_permissions_object(),
get_message_object(d->dialog_id, get_message(d, d->last_message_id)), get_message_object(d->dialog_id, get_message(d, d->last_message_id)),
DialogDate(d->order, d->dialog_id) <= last_dialog_date_ ? d->order : 0, d->pinned_order != DEFAULT_ORDER, DialogDate(d->order, d->dialog_id) <= last_dialog_date_ ? d->order : 0, d->pinned_order != DEFAULT_ORDER,
d->is_marked_as_unread, d->order == SPONSORED_DIALOG_ORDER, can_delete_for_self, can_delete_for_all_users, d->is_marked_as_unread, d->order == SPONSORED_DIALOG_ORDER, can_delete_for_self, can_delete_for_all_users,
@ -20699,6 +20700,15 @@ void MessagesManager::on_dialog_title_updated(DialogId dialog_id) {
} }
} }
void MessagesManager::on_dialog_permissions_updated(DialogId dialog_id) {
auto d = get_dialog(dialog_id); // called from update_user, must not create the dialog
if (d != nullptr && d->is_update_new_chat_sent) {
send_closure(G()->td(), &Td::send_update,
td_api::make_object<td_api::updateChatPermissions>(
dialog_id.get(), get_dialog_permissions(dialog_id).get_chat_permissions_object()));
}
}
DialogId MessagesManager::resolve_dialog_username(const string &username) { DialogId MessagesManager::resolve_dialog_username(const string &username) {
auto it = resolved_usernames_.find(clean_username(username)); auto it = resolved_usernames_.find(clean_username(username));
if (it != resolved_usernames_.end()) { if (it != resolved_usernames_.end()) {
@ -21019,6 +21029,23 @@ string MessagesManager::get_dialog_username(DialogId dialog_id) const {
} }
} }
RestrictedRights MessagesManager::get_dialog_permissions(DialogId dialog_id) const {
switch (dialog_id.get_type()) {
case DialogType::User:
return td_->contacts_manager_->get_user_default_permissions(dialog_id.get_user_id());
case DialogType::Chat:
return td_->contacts_manager_->get_chat_default_permissions(dialog_id.get_chat_id());
case DialogType::Channel:
return td_->contacts_manager_->get_channel_default_permissions(dialog_id.get_channel_id());
case DialogType::SecretChat:
return td_->contacts_manager_->get_secret_chat_default_permissions(dialog_id.get_secret_chat_id());
case DialogType::None:
default:
UNREACHABLE();
return RestrictedRights(false, false, false, false, false, false, false, false, false, false, false);
}
}
void MessagesManager::send_dialog_action(DialogId dialog_id, const tl_object_ptr<td_api::ChatAction> &action, void MessagesManager::send_dialog_action(DialogId dialog_id, const tl_object_ptr<td_api::ChatAction> &action,
Promise<Unit> &&promise) { Promise<Unit> &&promise) {
if (action == nullptr) { if (action == nullptr) {

View File

@ -616,6 +616,7 @@ class MessagesManager : public Actor {
void on_dialog_photo_updated(DialogId dialog_id); void on_dialog_photo_updated(DialogId dialog_id);
void on_dialog_title_updated(DialogId dialog_id); void on_dialog_title_updated(DialogId dialog_id);
void on_dialog_username_updated(DialogId dialog_id, const string &old_username, const string &new_username); void on_dialog_username_updated(DialogId dialog_id, const string &old_username, const string &new_username);
void on_dialog_permissions_updated(DialogId dialog_id);
void on_resolved_username(const string &username, DialogId dialog_id); void on_resolved_username(const string &username, DialogId dialog_id);
void drop_username(const string &username); void drop_username(const string &username);
@ -1949,6 +1950,8 @@ class MessagesManager : public Actor {
string get_dialog_username(DialogId dialog_id) const; string get_dialog_username(DialogId dialog_id) const;
RestrictedRights get_dialog_permissions(DialogId dialog_id) const;
static int64 get_dialog_order(MessageId message_id, int32 message_date); static int64 get_dialog_order(MessageId message_id, int32 message_date);
bool update_dialog_draft_message(Dialog *d, unique_ptr<DraftMessage> &&draft_message, bool from_update, bool update_dialog_draft_message(Dialog *d, unique_ptr<DraftMessage> &&draft_message, bool from_update,

View File

@ -3232,16 +3232,19 @@ class CliClient final : public Actor {
false, false, false); false, false, false);
} else if (status_str == "rest") { } else if (status_str == "rest") {
status = td_api::make_object<td_api::chatMemberStatusRestricted>( status = td_api::make_object<td_api::chatMemberStatusRestricted>(
true, static_cast<int32>(120 + std::time(nullptr)), false, false, false, false, false, false, false, false); true, static_cast<int32>(120 + std::time(nullptr)),
td_api::make_object<td_api::chatPermissions>(false, false, false, false, false, false, false, false));
} else if (status_str == "restkick") { } else if (status_str == "restkick") {
status = td_api::make_object<td_api::chatMemberStatusRestricted>( status = td_api::make_object<td_api::chatMemberStatusRestricted>(
false, static_cast<int32>(120 + std::time(nullptr)), true, false, false, false, false, false, false, false); false, static_cast<int32>(120 + std::time(nullptr)),
td_api::make_object<td_api::chatPermissions>(true, false, false, false, false, false, false, false));
} else if (status_str == "restunkick") { } else if (status_str == "restunkick") {
status = td_api::make_object<td_api::chatMemberStatusRestricted>( status = td_api::make_object<td_api::chatMemberStatusRestricted>(
true, static_cast<int32>(120 + std::time(nullptr)), true, false, false, false, false, false, false, false); true, static_cast<int32>(120 + std::time(nullptr)),
td_api::make_object<td_api::chatPermissions>(true, false, false, false, false, false, false, false));
} else if (status_str == "unrest") { } else if (status_str == "unrest") {
status = td_api::make_object<td_api::chatMemberStatusRestricted>(true, 0, true, true, true, true, true, true, status = td_api::make_object<td_api::chatMemberStatusRestricted>(
true, true); true, 0, td_api::make_object<td_api::chatPermissions>(true, true, true, true, true, true, true, true));
} }
if (status != nullptr) { if (status != nullptr) {
send_request(td_api::make_object<td_api::setChatMemberStatus>(as_chat_id(chat_id), as_user_id(user_id), send_request(td_api::make_object<td_api::setChatMemberStatus>(as_chat_id(chat_id), as_user_id(user_id),