From e2f9cc399fdf1824f21bd9956fdb88c3c2d63341 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 4 Apr 2022 16:29:46 +0300 Subject: [PATCH] Pass correct ChannelType to DialogParticipant constructor. --- td/telegram/ContactsManager.cpp | 17 +++++++++++------ td/telegram/DialogEventLog.cpp | 13 ++++++++----- td/telegram/DialogParticipant.h | 3 +-- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 1fcbc2ce2..87325e6cd 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -2772,7 +2772,8 @@ class GetChannelParticipantQuery final : public Td::ResultHandler { td_->contacts_manager_->on_get_users(std::move(participant->users_), "GetChannelParticipantQuery"); td_->contacts_manager_->on_get_chats(std::move(participant->chats_), "GetChannelParticipantQuery"); - DialogParticipant result(std::move(participant->participant_)); + DialogParticipant result(std::move(participant->participant_), + td_->contacts_manager_->get_channel_type(channel_id_)); if (!result.is_valid()) { LOG(ERROR) << "Receive invalid " << result; return promise_.set_error(Status::Error(500, "Receive invalid chat member")); @@ -2875,10 +2876,12 @@ class GetChannelAdministratorsQuery final : public Td::ResultHandler { auto participants = telegram_api::move_object_as(participants_ptr); td_->contacts_manager_->on_get_users(std::move(participants->users_), "GetChannelAdministratorsQuery"); td_->contacts_manager_->on_get_chats(std::move(participants->chats_), "GetChannelAdministratorsQuery"); + + auto channel_type = td_->contacts_manager_->get_channel_type(channel_id_); vector administrators; administrators.reserve(participants->participants_.size()); for (auto &participant : participants->participants_) { - DialogParticipant dialog_participant(std::move(participant)); + DialogParticipant dialog_participant(std::move(participant), channel_type); if (!dialog_participant.is_valid() || !dialog_participant.status_.is_administrator() || dialog_participant.dialog_id_.get_type() != DialogType::User) { LOG(ERROR) << "Receive " << dialog_participant << " as an administrator of " << channel_id_; @@ -12069,10 +12072,11 @@ void ContactsManager::on_get_channel_participants( bool is_full = offset == 0 && static_cast(participants.size()) < limit && total_count < limit; + auto channel_type = get_channel_type(channel_id); vector result; for (auto &participant_ptr : participants) { auto debug_participant = to_string(participant_ptr); - result.emplace_back(std::move(participant_ptr)); + result.emplace_back(std::move(participant_ptr), channel_type); const auto &participant = result.back(); UserId participant_user_id; if (participant.dialog_id_.get_type() == DialogType::User) { @@ -13896,15 +13900,16 @@ void ContactsManager::on_update_channel_participant(ChannelId channel_id, UserId DialogParticipant old_dialog_participant; DialogParticipant new_dialog_participant; + auto channel_type = get_channel_type(channel_id); if (old_participant != nullptr) { - old_dialog_participant = DialogParticipant(std::move(old_participant)); + old_dialog_participant = DialogParticipant(std::move(old_participant), channel_type); if (new_participant == nullptr) { new_dialog_participant = DialogParticipant::left(old_dialog_participant.dialog_id_); } else { - new_dialog_participant = DialogParticipant(std::move(new_participant)); + new_dialog_participant = DialogParticipant(std::move(new_participant), channel_type); } } else { - new_dialog_participant = DialogParticipant(std::move(new_participant)); + new_dialog_participant = DialogParticipant(std::move(new_participant), channel_type); old_dialog_participant = DialogParticipant::left(new_dialog_participant.dialog_id_); } if (old_dialog_participant.dialog_id_ != new_dialog_participant.dialog_id_ || !old_dialog_participant.is_valid() || diff --git a/td/telegram/DialogEventLog.cpp b/td/telegram/DialogEventLog.cpp index 1b6773f91..0c2ca3794 100644 --- a/td/telegram/DialogEventLog.cpp +++ b/td/telegram/DialogEventLog.cpp @@ -65,7 +65,8 @@ static td_api::object_ptr get_chat_event_action_object( return td_api::make_object(); case telegram_api::channelAdminLogEventActionParticipantInvite::ID: { auto action = move_tl_object_as(action_ptr); - DialogParticipant dialog_participant(std::move(action->participant_)); + DialogParticipant dialog_participant(std::move(action->participant_), + td->contacts_manager_->get_channel_type(channel_id)); if (!dialog_participant.is_valid() || dialog_participant.dialog_id_.get_type() != DialogType::User) { LOG(ERROR) << "Wrong invite: " << dialog_participant; return nullptr; @@ -77,8 +78,9 @@ static td_api::object_ptr get_chat_event_action_object( } case telegram_api::channelAdminLogEventActionParticipantToggleBan::ID: { auto action = move_tl_object_as(action_ptr); - DialogParticipant old_dialog_participant(std::move(action->prev_participant_)); - DialogParticipant new_dialog_participant(std::move(action->new_participant_)); + auto channel_type = td->contacts_manager_->get_channel_type(channel_id); + DialogParticipant old_dialog_participant(std::move(action->prev_participant_), channel_type); + DialogParticipant new_dialog_participant(std::move(action->new_participant_), channel_type); if (old_dialog_participant.dialog_id_ != new_dialog_participant.dialog_id_) { LOG(ERROR) << old_dialog_participant.dialog_id_ << " VS " << new_dialog_participant.dialog_id_; return nullptr; @@ -94,8 +96,9 @@ static td_api::object_ptr get_chat_event_action_object( } case telegram_api::channelAdminLogEventActionParticipantToggleAdmin::ID: { auto action = move_tl_object_as(action_ptr); - DialogParticipant old_dialog_participant(std::move(action->prev_participant_)); - DialogParticipant new_dialog_participant(std::move(action->new_participant_)); + auto channel_type = td->contacts_manager_->get_channel_type(channel_id); + DialogParticipant old_dialog_participant(std::move(action->prev_participant_), channel_type); + DialogParticipant new_dialog_participant(std::move(action->new_participant_), channel_type); if (old_dialog_participant.dialog_id_ != new_dialog_participant.dialog_id_) { LOG(ERROR) << old_dialog_participant.dialog_id_ << " VS " << new_dialog_participant.dialog_id_; return nullptr; diff --git a/td/telegram/DialogParticipant.h b/td/telegram/DialogParticipant.h index bcbf3f023..33833a3e3 100644 --- a/td/telegram/DialogParticipant.h +++ b/td/telegram/DialogParticipant.h @@ -501,8 +501,7 @@ struct DialogParticipant { DialogParticipant(tl_object_ptr &&participant_ptr, int32 chat_creation_date, bool is_creator); - DialogParticipant(tl_object_ptr &&participant_ptr, - ChannelType channel_type = ChannelType::Unknown); + DialogParticipant(tl_object_ptr &&participant_ptr, ChannelType channel_type); static DialogParticipant left(DialogId dialog_id) { return {dialog_id, UserId(), 0, DialogParticipantStatus::Left()};