diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 5ea9519d1..0cc211cd6 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -2931,7 +2931,7 @@ class GetChannelParticipantQuery : public Td::ResultHandler { LOG(INFO) << "Receive result for GetChannelParticipantQuery: " << to_string(participant); td->contacts_manager_->on_get_users(std::move(participant->users_), "GetChannelParticipantQuery"); - auto result = td->contacts_manager_->get_dialog_participant(channel_id_, std::move(participant->participant_)); + DialogParticipant result(std::move(participant->participant_)); if (!result.is_valid()) { LOG(ERROR) << "Receive invalid " << result; return promise_.set_error(Status::Error(500, "Receive invalid chat member")); @@ -3034,8 +3034,7 @@ class GetChannelAdministratorsQuery : public Td::ResultHandler { vector administrators; administrators.reserve(participants->participants_.size()); for (auto &participant : participants->participants_) { - DialogParticipant dialog_participant = - td->contacts_manager_->get_dialog_participant(channel_id_, std::move(participant)); + DialogParticipant dialog_participant(std::move(participant)); if (!dialog_participant.is_valid() || !dialog_participant.status.is_administrator()) { LOG(ERROR) << "Receive " << dialog_participant << " as an administrator of " << channel_id_; continue; @@ -11358,11 +11357,6 @@ const DialogParticipant *ContactsManager::get_chat_participant(const ChatFull *c return nullptr; } -DialogParticipant ContactsManager::get_dialog_participant( - ChannelId channel_id, tl_object_ptr &&participant_ptr) const { - return DialogParticipant(std::move(participant_ptr), get_channel_status(channel_id)); -} - tl_object_ptr ContactsManager::get_chat_member_object( const DialogParticipant &dialog_participant) const { UserId participant_user_id = dialog_participant.user_id; @@ -11464,7 +11458,7 @@ void ContactsManager::on_get_channel_participants( vector result; for (auto &participant_ptr : participants) { auto debug_participant = to_string(participant_ptr); - result.push_back(get_dialog_participant(channel_id, std::move(participant_ptr))); + result.emplace_back(std::move(participant_ptr)); const auto &participant = result.back(); if (!participant.is_valid() || (filter.is_bots() && !is_user_bot(participant.user_id)) || (filter.is_administrators() && !participant.status.is_administrator()) || @@ -13125,14 +13119,14 @@ void ContactsManager::on_update_channel_participant(ChannelId channel_id, UserId DialogParticipant old_dialog_participant; DialogParticipant new_dialog_participant; if (old_participant != nullptr) { - old_dialog_participant = get_dialog_participant(channel_id, std::move(old_participant)); + old_dialog_participant = DialogParticipant(std::move(old_participant)); if (new_participant == nullptr) { new_dialog_participant = DialogParticipant::left(old_dialog_participant.user_id); } else { - new_dialog_participant = get_dialog_participant(channel_id, std::move(new_participant)); + new_dialog_participant = DialogParticipant(std::move(new_participant)); } } else { - new_dialog_participant = get_dialog_participant(channel_id, std::move(new_participant)); + new_dialog_participant = DialogParticipant(std::move(new_participant)); old_dialog_participant = DialogParticipant::left(new_dialog_participant.user_id); } if (old_dialog_participant.user_id != new_dialog_participant.user_id || !old_dialog_participant.is_valid() || diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 041fae8c8..8a34325e4 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -521,9 +521,6 @@ class ContactsManager : public Actor { void ban_dialog_participant(DialogId dialog_id, UserId user_id, int32 banned_until_date, bool revoke_messages, Promise &&promise); - DialogParticipant get_dialog_participant(ChannelId channel_id, - tl_object_ptr &&participant_ptr) const; - DialogParticipant get_dialog_participant(DialogId dialog_id, UserId user_id, int64 &random_id, bool force, Promise &&promise); diff --git a/td/telegram/DialogParticipant.cpp b/td/telegram/DialogParticipant.cpp index 8ba950082..339ea3a37 100644 --- a/td/telegram/DialogParticipant.cpp +++ b/td/telegram/DialogParticipant.cpp @@ -681,8 +681,7 @@ DialogParticipant::DialogParticipant(tl_object_ptr &&participant_ptr, - DialogParticipantStatus my_status) { +DialogParticipant::DialogParticipant(tl_object_ptr &&participant_ptr) { CHECK(participant_ptr != nullptr); switch (participant_ptr->get_id()) { case telegram_api::channelParticipant::ID: { @@ -693,7 +692,7 @@ DialogParticipant::DialogParticipant(tl_object_ptr(participant_ptr); *this = {UserId(participant->user_id_), UserId(participant->inviter_id_), participant->date_, - std::move(my_status)}; + DialogParticipantStatus::Member()}; break; } case telegram_api::channelParticipantCreator::ID: { diff --git a/td/telegram/DialogParticipant.h b/td/telegram/DialogParticipant.h index 9606ab33b..fb022a308 100644 --- a/td/telegram/DialogParticipant.h +++ b/td/telegram/DialogParticipant.h @@ -395,8 +395,7 @@ struct DialogParticipant { DialogParticipant(tl_object_ptr &&participant_ptr, int32 chat_creation_date, bool is_creator); - DialogParticipant(tl_object_ptr &&participant_ptr, - DialogParticipantStatus my_status); + explicit DialogParticipant(tl_object_ptr &&participant_ptr); static DialogParticipant left(UserId user_id) { return {user_id, UserId(), 0, DialogParticipantStatus::Left()}; diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index e35613e95..75a4a3876 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -31223,48 +31223,48 @@ tl_object_ptr MessagesManager::get_chat_event_action_ob return make_tl_object(); case telegram_api::channelAdminLogEventActionParticipantInvite::ID: { auto action = move_tl_object_as(action_ptr); - auto member = td_->contacts_manager_->get_dialog_participant(channel_id, std::move(action->participant_)); - if (!member.is_valid()) { - LOG(ERROR) << "Wrong invite: " << member; + DialogParticipant dialog_participant(std::move(action->participant_)); + if (!dialog_participant.is_valid()) { + LOG(ERROR) << "Wrong invite: " << dialog_participant; return nullptr; } return make_tl_object( - td_->contacts_manager_->get_user_id_object(member.user_id, "chatEventMemberInvited"), - member.status.get_chat_member_status_object()); + td_->contacts_manager_->get_user_id_object(dialog_participant.user_id, "chatEventMemberInvited"), + dialog_participant.status.get_chat_member_status_object()); } case telegram_api::channelAdminLogEventActionParticipantToggleBan::ID: { auto action = move_tl_object_as(action_ptr); - auto old_member = - td_->contacts_manager_->get_dialog_participant(channel_id, std::move(action->prev_participant_)); - auto new_member = td_->contacts_manager_->get_dialog_participant(channel_id, std::move(action->new_participant_)); - if (old_member.user_id != new_member.user_id) { - LOG(ERROR) << old_member.user_id << " VS " << new_member.user_id; + DialogParticipant old_dialog_participant(std::move(action->prev_participant_)); + DialogParticipant new_dialog_participant(std::move(action->new_participant_)); + if (old_dialog_participant.user_id != new_dialog_participant.user_id) { + LOG(ERROR) << old_dialog_participant.user_id << " VS " << new_dialog_participant.user_id; return nullptr; } - if (!old_member.is_valid() || !new_member.is_valid()) { - LOG(ERROR) << "Wrong restrict: " << old_member << " -> " << new_member; + if (!old_dialog_participant.is_valid() || !new_dialog_participant.is_valid()) { + LOG(ERROR) << "Wrong restrict: " << old_dialog_participant << " -> " << new_dialog_participant; return nullptr; } return make_tl_object( - td_->contacts_manager_->get_user_id_object(old_member.user_id, "chatEventMemberRestricted"), - old_member.status.get_chat_member_status_object(), new_member.status.get_chat_member_status_object()); + td_->contacts_manager_->get_user_id_object(old_dialog_participant.user_id, "chatEventMemberRestricted"), + old_dialog_participant.status.get_chat_member_status_object(), + new_dialog_participant.status.get_chat_member_status_object()); } case telegram_api::channelAdminLogEventActionParticipantToggleAdmin::ID: { auto action = move_tl_object_as(action_ptr); - auto old_member = - td_->contacts_manager_->get_dialog_participant(channel_id, std::move(action->prev_participant_)); - auto new_member = td_->contacts_manager_->get_dialog_participant(channel_id, std::move(action->new_participant_)); - if (old_member.user_id != new_member.user_id) { - LOG(ERROR) << old_member.user_id << " VS " << new_member.user_id; + DialogParticipant old_dialog_participant(std::move(action->prev_participant_)); + DialogParticipant new_dialog_participant(std::move(action->new_participant_)); + if (old_dialog_participant.user_id != new_dialog_participant.user_id) { + LOG(ERROR) << old_dialog_participant.user_id << " VS " << new_dialog_participant.user_id; return nullptr; } - if (!old_member.is_valid() || !new_member.is_valid()) { - LOG(ERROR) << "Wrong edit administrator: " << old_member << " -> " << new_member; + if (!old_dialog_participant.is_valid() || !new_dialog_participant.is_valid()) { + LOG(ERROR) << "Wrong edit administrator: " << old_dialog_participant << " -> " << new_dialog_participant; return nullptr; } return make_tl_object( - td_->contacts_manager_->get_user_id_object(old_member.user_id, "chatEventMemberPromoted"), - old_member.status.get_chat_member_status_object(), new_member.status.get_chat_member_status_object()); + td_->contacts_manager_->get_user_id_object(old_dialog_participant.user_id, "chatEventMemberPromoted"), + old_dialog_participant.status.get_chat_member_status_object(), + new_dialog_participant.status.get_chat_member_status_object()); } case telegram_api::channelAdminLogEventActionChangeTitle::ID: { auto action = move_tl_object_as(action_ptr);