Move get_dialog_participant_status to DialogParticipantStatus constructor.

This commit is contained in:
levlam 2022-03-18 19:13:22 +03:00
parent f8e8bc6035
commit 5d71289b72
3 changed files with 22 additions and 24 deletions

View File

@ -15656,7 +15656,7 @@ void ContactsManager::on_chat_update(telegram_api::chat &chat, const char *sourc
if (is_creator) {
return DialogParticipantStatus::Creator(!has_left, false, string());
} else if (chat.admin_rights_ != nullptr) {
return get_dialog_participant_status(false, std::move(chat.admin_rights_), string());
return DialogParticipantStatus(false, std::move(chat.admin_rights_), string());
} else if (was_kicked) {
return DialogParticipantStatus::Banned(0);
} else if (has_left) {
@ -15838,9 +15838,9 @@ void ContactsManager::on_chat_update(telegram_api::channel &channel, const char
(channel.admin_rights_->flags_ & telegram_api::chatAdminRights::ANONYMOUS_MASK) != 0;
return DialogParticipantStatus::Creator(!has_left, is_anonymous, string());
} else if (channel.admin_rights_ != nullptr) {
return get_dialog_participant_status(false, std::move(channel.admin_rights_), string());
return DialogParticipantStatus(false, std::move(channel.admin_rights_), string());
} else if (channel.banned_rights_ != nullptr) {
return get_dialog_participant_status(!has_left, std::move(channel.banned_rights_));
return DialogParticipantStatus(!has_left, std::move(channel.banned_rights_));
} else if (has_left) {
return DialogParticipantStatus::Left();
} else {

View File

@ -528,9 +528,9 @@ DialogParticipantStatus get_dialog_participant_status(const tl_object_ptr<td_api
}
}
DialogParticipantStatus get_dialog_participant_status(bool can_be_edited,
tl_object_ptr<telegram_api::chatAdminRights> &&admin_rights,
string rank) {
DialogParticipantStatus::DialogParticipantStatus(bool can_be_edited,
tl_object_ptr<telegram_api::chatAdminRights> &&admin_rights,
string rank) {
bool can_change_info = (admin_rights->flags_ & telegram_api::chatAdminRights::CHANGE_INFO_MASK) != 0;
bool can_post_messages = (admin_rights->flags_ & telegram_api::chatAdminRights::POST_MESSAGES_MASK) != 0;
bool can_edit_messages = (admin_rights->flags_ & telegram_api::chatAdminRights::EDIT_MESSAGES_MASK) != 0;
@ -545,18 +545,19 @@ DialogParticipantStatus get_dialog_participant_status(bool can_be_edited,
if (!can_manage_dialog) {
LOG(ERROR) << "Receive wrong other flag in " << to_string(admin_rights);
}
return DialogParticipantStatus::Administrator(is_anonymous, std::move(rank), can_be_edited, can_manage_dialog,
can_change_info, can_post_messages, can_edit_messages,
can_delete_messages, can_invite_users, can_restrict_members,
can_pin_messages, can_promote_members, can_manage_calls);
*this = DialogParticipantStatus::Administrator(is_anonymous, std::move(rank), can_be_edited, can_manage_dialog,
can_change_info, can_post_messages, can_edit_messages,
can_delete_messages, can_invite_users, can_restrict_members,
can_pin_messages, can_promote_members, can_manage_calls);
}
DialogParticipantStatus get_dialog_participant_status(bool is_member,
tl_object_ptr<telegram_api::chatBannedRights> &&banned_rights) {
DialogParticipantStatus::DialogParticipantStatus(bool is_member,
tl_object_ptr<telegram_api::chatBannedRights> &&banned_rights) {
CHECK(banned_rights != nullptr);
bool can_view_messages = (banned_rights->flags_ & telegram_api::chatBannedRights::VIEW_MESSAGES_MASK) == 0;
if (!can_view_messages) {
return DialogParticipantStatus::Banned(banned_rights->until_date_);
*this = DialogParticipantStatus::Banned(banned_rights->until_date_);
return;
}
bool can_send_messages = (banned_rights->flags_ & telegram_api::chatBannedRights::SEND_MESSAGES_MASK) == 0;
bool can_send_media_messages = (banned_rights->flags_ & telegram_api::chatBannedRights::SEND_MEDIA_MASK) == 0;
@ -569,7 +570,7 @@ DialogParticipantStatus get_dialog_participant_status(bool is_member,
bool can_change_info_and_settings = (banned_rights->flags_ & telegram_api::chatBannedRights::CHANGE_INFO_MASK) == 0;
bool can_invite_users = (banned_rights->flags_ & telegram_api::chatBannedRights::INVITE_USERS_MASK) == 0;
bool can_pin_messages = (banned_rights->flags_ & telegram_api::chatBannedRights::PIN_MESSAGES_MASK) == 0;
return DialogParticipantStatus::Restricted(
*this = DialogParticipantStatus::Restricted(
is_member, banned_rights->until_date_, can_send_messages, can_send_media_messages, 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);
@ -679,8 +680,8 @@ DialogParticipant::DialogParticipant(tl_object_ptr<telegram_api::ChannelParticip
case telegram_api::channelParticipantAdmin::ID: {
auto participant = move_tl_object_as<telegram_api::channelParticipantAdmin>(participant_ptr);
*this = {DialogId(UserId(participant->user_id_)), UserId(participant->promoted_by_), participant->date_,
get_dialog_participant_status(participant->can_edit_, std::move(participant->admin_rights_),
std::move(participant->rank_))};
DialogParticipantStatus(participant->can_edit_, std::move(participant->admin_rights_),
std::move(participant->rank_))};
break;
}
case telegram_api::channelParticipantLeft::ID: {
@ -691,7 +692,7 @@ DialogParticipant::DialogParticipant(tl_object_ptr<telegram_api::ChannelParticip
case telegram_api::channelParticipantBanned::ID: {
auto participant = move_tl_object_as<telegram_api::channelParticipantBanned>(participant_ptr);
*this = {DialogId(participant->peer_), UserId(participant->kicked_by_), participant->date_,
get_dialog_participant_status(!participant->left_, std::move(participant->banned_rights_))};
DialogParticipantStatus(!participant->left_, std::move(participant->banned_rights_))};
break;
}
default:

View File

@ -278,6 +278,10 @@ class DialogParticipantStatus {
// legacy rights
static DialogParticipantStatus ChannelAdministrator(bool is_creator, bool is_megagroup);
DialogParticipantStatus(bool can_be_edited, tl_object_ptr<telegram_api::chatAdminRights> &&admin_rights, string rank);
DialogParticipantStatus(bool is_member, tl_object_ptr<telegram_api::chatBannedRights> &&banned_rights);
RestrictedRights get_effective_restricted_rights() const;
DialogParticipantStatus apply_restrictions(RestrictedRights default_restrictions, bool is_bot) const;
@ -596,13 +600,6 @@ StringBuilder &operator<<(StringBuilder &string_builder, const DialogParticipant
DialogParticipantStatus get_dialog_participant_status(const tl_object_ptr<td_api::ChatMemberStatus> &status);
DialogParticipantStatus get_dialog_participant_status(bool can_be_edited,
tl_object_ptr<telegram_api::chatAdminRights> &&admin_rights,
string rank);
DialogParticipantStatus get_dialog_participant_status(bool is_member,
tl_object_ptr<telegram_api::chatBannedRights> &&banned_rights);
RestrictedRights get_restricted_rights(tl_object_ptr<telegram_api::chatBannedRights> &&banned_rights);
RestrictedRights get_restricted_rights(const td_api::object_ptr<td_api::chatPermissions> &permissions);