Add DialogParticipant constructor from telegram_api.

GitOrigin-RevId: 8d3080993b029028eb59c561f1fc700db87eb970
This commit is contained in:
levlam 2020-06-30 16:43:44 +03:00
parent e78831cd2b
commit 7a12f49d61
3 changed files with 45 additions and 32 deletions

View File

@ -10004,38 +10004,7 @@ const DialogParticipant *ContactsManager::get_chat_participant(const ChatFull *c
DialogParticipant ContactsManager::get_dialog_participant(
ChannelId channel_id, tl_object_ptr<telegram_api::ChannelParticipant> &&participant_ptr) const {
switch (participant_ptr->get_id()) {
case telegram_api::channelParticipant::ID: {
auto participant = move_tl_object_as<telegram_api::channelParticipant>(participant_ptr);
return {UserId(participant->user_id_), UserId(), participant->date_, DialogParticipantStatus::Member()};
}
case telegram_api::channelParticipantSelf::ID: {
auto participant = move_tl_object_as<telegram_api::channelParticipantSelf>(participant_ptr);
return {UserId(participant->user_id_), UserId(participant->inviter_id_), participant->date_,
get_channel_status(channel_id)};
}
case telegram_api::channelParticipantCreator::ID: {
auto participant = move_tl_object_as<telegram_api::channelParticipantCreator>(participant_ptr);
return {UserId(participant->user_id_), UserId(), 0,
DialogParticipantStatus::Creator(true, std::move(participant->rank_))};
}
case telegram_api::channelParticipantAdmin::ID: {
auto participant = move_tl_object_as<telegram_api::channelParticipantAdmin>(participant_ptr);
bool can_be_edited = (participant->flags_ & telegram_api::channelParticipantAdmin::CAN_EDIT_MASK) != 0;
return {UserId(participant->user_id_), UserId(participant->promoted_by_), participant->date_,
get_dialog_participant_status(can_be_edited, std::move(participant->admin_rights_),
std::move(participant->rank_))};
}
case telegram_api::channelParticipantBanned::ID: {
auto participant = move_tl_object_as<telegram_api::channelParticipantBanned>(participant_ptr);
auto is_member = (participant->flags_ & telegram_api::channelParticipantBanned::LEFT_MASK) == 0;
return {UserId(participant->user_id_), UserId(participant->kicked_by_), participant->date_,
get_dialog_participant_status(is_member, std::move(participant->banned_rights_))};
}
default:
UNREACHABLE();
return DialogParticipant();
}
return DialogParticipant(std::move(participant_ptr), get_channel_status(channel_id));
}
tl_object_ptr<td_api::chatMember> ContactsManager::get_chat_member_object(

View File

@ -605,6 +605,47 @@ RestrictedRights get_restricted_rights(const td_api::object_ptr<td_api::chatPerm
permissions->can_pin_messages_);
}
DialogParticipant::DialogParticipant(tl_object_ptr<telegram_api::ChannelParticipant> &&participant_ptr,
DialogParticipantStatus my_status) {
switch (participant_ptr->get_id()) {
case telegram_api::channelParticipant::ID: {
auto participant = move_tl_object_as<telegram_api::channelParticipant>(participant_ptr);
*this = {UserId(participant->user_id_), UserId(), participant->date_, DialogParticipantStatus::Member()};
break;
}
case telegram_api::channelParticipantSelf::ID: {
auto participant = move_tl_object_as<telegram_api::channelParticipantSelf>(participant_ptr);
*this = {UserId(participant->user_id_), UserId(participant->inviter_id_), participant->date_,
std::move(my_status)};
break;
}
case telegram_api::channelParticipantCreator::ID: {
auto participant = move_tl_object_as<telegram_api::channelParticipantCreator>(participant_ptr);
*this = {UserId(participant->user_id_), UserId(), 0,
DialogParticipantStatus::Creator(true, std::move(participant->rank_))};
break;
}
case telegram_api::channelParticipantAdmin::ID: {
auto participant = move_tl_object_as<telegram_api::channelParticipantAdmin>(participant_ptr);
bool can_be_edited = (participant->flags_ & telegram_api::channelParticipantAdmin::CAN_EDIT_MASK) != 0;
*this = {UserId(participant->user_id_), UserId(participant->promoted_by_), participant->date_,
get_dialog_participant_status(can_be_edited, std::move(participant->admin_rights_),
std::move(participant->rank_))};
break;
}
case telegram_api::channelParticipantBanned::ID: {
auto participant = move_tl_object_as<telegram_api::channelParticipantBanned>(participant_ptr);
auto is_member = (participant->flags_ & telegram_api::channelParticipantBanned::LEFT_MASK) == 0;
*this = {UserId(participant->user_id_), UserId(participant->kicked_by_), participant->date_,
get_dialog_participant_status(is_member, std::move(participant->banned_rights_))};
break;
}
default:
UNREACHABLE();
break;
}
}
StringBuilder &operator<<(StringBuilder &string_builder, const DialogParticipant &dialog_participant) {
return string_builder << '[' << dialog_participant.user_id << " invited by " << dialog_participant.inviter_user_id
<< " at " << dialog_participant.joined_date << " with status " << dialog_participant.status

View File

@ -369,6 +369,9 @@ struct DialogParticipant {
: user_id(user_id), inviter_user_id(inviter_user_id), joined_date(joined_date), status(status) {
}
DialogParticipant(tl_object_ptr<telegram_api::ChannelParticipant> &&participant_ptr,
DialogParticipantStatus my_status);
template <class StorerT>
void store(StorerT &storer) const {
td::store(user_id, storer);