Add DialogParticipant constructor from telegram_api::ChatParticipant.

This commit is contained in:
levlam 2021-02-19 01:38:16 +03:00
parent b9b6b05bae
commit ad43c83bce
3 changed files with 38 additions and 29 deletions

View File

@ -11108,29 +11108,10 @@ void ContactsManager::on_get_chat_participants(tl_object_ptr<telegram_api::ChatP
new_participants.reserve(participants->participants_.size()); new_participants.reserve(participants->participants_.size());
for (auto &participant_ptr : participants->participants_) { for (auto &participant_ptr : participants->participants_) {
DialogParticipant dialog_participant; DialogParticipant dialog_participant(std::move(participant_ptr), c->date, c->status.is_creator());
switch (participant_ptr->get_id()) { if (!dialog_participant.is_valid()) {
case telegram_api::chatParticipant::ID: { LOG(ERROR) << "Receive invalid " << dialog_participant;
auto participant = move_tl_object_as<telegram_api::chatParticipant>(participant_ptr); continue;
dialog_participant = {UserId(participant->user_id_), UserId(participant->inviter_id_), participant->date_,
DialogParticipantStatus::Member()};
break;
}
case telegram_api::chatParticipantCreator::ID: {
auto participant = move_tl_object_as<telegram_api::chatParticipantCreator>(participant_ptr);
new_creator_user_id = UserId(participant->user_id_);
dialog_participant = {new_creator_user_id, new_creator_user_id, c->date,
DialogParticipantStatus::Creator(true, false, string())};
break;
}
case telegram_api::chatParticipantAdmin::ID: {
auto participant = move_tl_object_as<telegram_api::chatParticipantAdmin>(participant_ptr);
dialog_participant = {UserId(participant->user_id_), UserId(participant->inviter_id_), participant->date_,
DialogParticipantStatus::GroupAdministrator(c->status.is_creator())};
break;
}
default:
UNREACHABLE();
} }
LOG_IF(ERROR, !have_user(dialog_participant.user_id)) LOG_IF(ERROR, !have_user(dialog_participant.user_id))
@ -11143,18 +11124,17 @@ void ContactsManager::on_get_chat_participants(tl_object_ptr<telegram_api::ChatP
<< chat_id << " was created at " << c->date; << chat_id << " was created at " << c->date;
dialog_participant.joined_date = c->date; dialog_participant.joined_date = c->date;
} }
if (dialog_participant.status.is_creator()) {
new_creator_user_id = dialog_participant.user_id;
}
new_participants.push_back(std::move(dialog_participant)); new_participants.push_back(std::move(dialog_participant));
} }
if (new_creator_user_id.is_valid()) { if (chat_full->creator_user_id != new_creator_user_id) {
LOG_IF(ERROR, !have_user(new_creator_user_id)) if (new_creator_user_id.is_valid() && chat_full->creator_user_id.is_valid()) {
<< "Have no information about group creator " << new_creator_user_id << " in " << chat_id;
if (chat_full->creator_user_id.is_valid() && chat_full->creator_user_id != new_creator_user_id) {
LOG(ERROR) << "Group creator has changed from " << chat_full->creator_user_id << " to " << new_creator_user_id LOG(ERROR) << "Group creator has changed from " << chat_full->creator_user_id << " to " << new_creator_user_id
<< " in " << chat_id; << " in " << chat_id;
} }
}
if (chat_full->creator_user_id != new_creator_user_id) {
chat_full->creator_user_id = new_creator_user_id; chat_full->creator_user_id = new_creator_user_id;
chat_full->is_changed = true; chat_full->is_changed = true;
} }

View File

@ -643,6 +643,32 @@ DialogParticipant::DialogParticipant(UserId user_id, UserId inviter_user_id, int
} }
} }
DialogParticipant::DialogParticipant(tl_object_ptr<telegram_api::ChatParticipant> &&participant_ptr,
int32 chat_creation_date, bool is_creator) {
switch (participant_ptr->get_id()) {
case telegram_api::chatParticipant::ID: {
auto participant = move_tl_object_as<telegram_api::chatParticipant>(participant_ptr);
*this = {UserId(participant->user_id_), UserId(participant->inviter_id_), participant->date_,
DialogParticipantStatus::Member()};
break;
}
case telegram_api::chatParticipantCreator::ID: {
auto participant = move_tl_object_as<telegram_api::chatParticipantCreator>(participant_ptr);
*this = {UserId(participant->user_id_), UserId(participant->user_id_), chat_creation_date,
DialogParticipantStatus::Creator(true, false, string())};
break;
}
case telegram_api::chatParticipantAdmin::ID: {
auto participant = move_tl_object_as<telegram_api::chatParticipantAdmin>(participant_ptr);
*this = {UserId(participant->user_id_), UserId(participant->inviter_id_), participant->date_,
DialogParticipantStatus::GroupAdministrator(is_creator)};
break;
}
default:
UNREACHABLE();
}
}
DialogParticipant::DialogParticipant(tl_object_ptr<telegram_api::ChannelParticipant> &&participant_ptr, DialogParticipant::DialogParticipant(tl_object_ptr<telegram_api::ChannelParticipant> &&participant_ptr,
DialogParticipantStatus my_status) { DialogParticipantStatus my_status) {
CHECK(participant_ptr != nullptr); CHECK(participant_ptr != nullptr);

View File

@ -383,6 +383,9 @@ struct DialogParticipant {
DialogParticipant(UserId user_id, UserId inviter_user_id, int32 joined_date, DialogParticipantStatus status); DialogParticipant(UserId user_id, UserId inviter_user_id, int32 joined_date, DialogParticipantStatus status);
DialogParticipant(tl_object_ptr<telegram_api::ChatParticipant> &&participant_ptr, int32 chat_creation_date,
bool is_creator);
DialogParticipant(tl_object_ptr<telegram_api::ChannelParticipant> &&participant_ptr, DialogParticipant(tl_object_ptr<telegram_api::ChannelParticipant> &&participant_ptr,
DialogParticipantStatus my_status); DialogParticipantStatus my_status);