Add DialogParticipant validness checks.
GitOrigin-RevId: 74ca340bd890f0bd913a9f0d7aeb3e81f3829cf7
This commit is contained in:
parent
7a12f49d61
commit
06bd4fa734
@ -2492,8 +2492,12 @@ 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");
|
||||
promise_.set_value(
|
||||
td->contacts_manager_->get_dialog_participant(channel_id_, std::move(participant->participant_)));
|
||||
auto result = td->contacts_manager_->get_dialog_participant(channel_id_, std::move(participant->participant_));
|
||||
if (!result.is_valid()) {
|
||||
LOG(ERROR) << "Receive invalid " << result;
|
||||
return promise_.set_error(Status::Error(500, "Receive invalid chat member"));
|
||||
}
|
||||
promise_.set_value(std::move(result));
|
||||
}
|
||||
|
||||
void on_error(uint64 id, Status status) override {
|
||||
@ -2609,9 +2613,8 @@ class GetChannelAdministratorsQuery : public Td::ResultHandler {
|
||||
for (auto &participant : participants->participants_) {
|
||||
DialogParticipant dialog_participant =
|
||||
td->contacts_manager_->get_dialog_participant(channel_id_, std::move(participant));
|
||||
if (!dialog_participant.user_id.is_valid() || !dialog_participant.status.is_administrator()) {
|
||||
LOG(ERROR) << "Receive " << dialog_participant.user_id << " with status " << dialog_participant.status
|
||||
<< " as an administrator of " << channel_id_;
|
||||
if (!dialog_participant.is_valid() || !dialog_participant.status.is_administrator()) {
|
||||
LOG(ERROR) << "Receive " << dialog_participant << " as an administrator of " << channel_id_;
|
||||
continue;
|
||||
}
|
||||
administrators.emplace_back(dialog_participant.user_id, dialog_participant.status.get_rank(),
|
||||
@ -10106,16 +10109,17 @@ void ContactsManager::on_get_channel_participants_success(
|
||||
for (auto &participant_ptr : participants) {
|
||||
auto debug_participant = to_string(participant_ptr);
|
||||
result.push_back(get_dialog_participant(channel_id, std::move(participant_ptr)));
|
||||
if ((filter.is_bots() && !is_user_bot(result.back().user_id)) ||
|
||||
(filter.is_administrators() && !result.back().status.is_administrator()) ||
|
||||
((filter.is_recent() || filter.is_contacts() || filter.is_search()) && !result.back().status.is_member()) ||
|
||||
(filter.is_contacts() && !is_user_contact(result.back().user_id)) ||
|
||||
(filter.is_restricted() && !result.back().status.is_restricted()) ||
|
||||
(filter.is_banned() && !result.back().status.is_banned())) {
|
||||
bool skip_error = (filter.is_administrators() && is_user_deleted(result.back().user_id)) ||
|
||||
(filter.is_contacts() && result.back().user_id == get_my_id());
|
||||
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()) ||
|
||||
((filter.is_recent() || filter.is_contacts() || filter.is_search()) && !participant.status.is_member()) ||
|
||||
(filter.is_contacts() && !is_user_contact(participant.user_id)) ||
|
||||
(filter.is_restricted() && !participant.status.is_restricted()) ||
|
||||
(filter.is_banned() && !participant.status.is_banned())) {
|
||||
bool skip_error = (filter.is_administrators() && is_user_deleted(participant.user_id)) ||
|
||||
(filter.is_contacts() && participant.user_id == get_my_id());
|
||||
if (!skip_error) {
|
||||
LOG(ERROR) << "Receive " << result.back() << ", while searching for " << filter << " in " << channel_id
|
||||
LOG(ERROR) << "Receive " << participant << ", while searching for " << filter << " in " << channel_id
|
||||
<< " with offset " << offset << " and limit " << limit << ": " << oneline(debug_participant);
|
||||
}
|
||||
result.pop_back();
|
||||
|
@ -605,8 +605,22 @@ RestrictedRights get_restricted_rights(const td_api::object_ptr<td_api::chatPerm
|
||||
permissions->can_pin_messages_);
|
||||
}
|
||||
|
||||
DialogParticipant::DialogParticipant(UserId user_id, UserId inviter_user_id, int32 joined_date,
|
||||
DialogParticipantStatus status)
|
||||
: user_id(user_id), inviter_user_id(inviter_user_id), joined_date(joined_date), status(status) {
|
||||
if (!inviter_user_id.is_valid() && inviter_user_id != UserId()) {
|
||||
LOG(ERROR) << "Receive inviter " << inviter_user_id;
|
||||
inviter_user_id = UserId();
|
||||
}
|
||||
if (joined_date < 0) {
|
||||
LOG(ERROR) << "Receive date " << joined_date;
|
||||
joined_date = 0;
|
||||
}
|
||||
}
|
||||
|
||||
DialogParticipant::DialogParticipant(tl_object_ptr<telegram_api::ChannelParticipant> &&participant_ptr,
|
||||
DialogParticipantStatus my_status) {
|
||||
CHECK(participant_ptr != nullptr);
|
||||
switch (participant_ptr->get_id()) {
|
||||
case telegram_api::channelParticipant::ID: {
|
||||
auto participant = move_tl_object_as<telegram_api::channelParticipant>(participant_ptr);
|
||||
@ -646,6 +660,16 @@ DialogParticipant::DialogParticipant(tl_object_ptr<telegram_api::ChannelParticip
|
||||
}
|
||||
}
|
||||
|
||||
bool DialogParticipant::is_valid() const {
|
||||
if (!user_id.is_valid() || joined_date < 0) {
|
||||
return false;
|
||||
}
|
||||
if (status.is_restricted() || status.is_banned() || (status.is_administrator() && !status.is_creator())) {
|
||||
return inviter_user_id.is_valid();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -365,13 +365,13 @@ struct DialogParticipant {
|
||||
|
||||
DialogParticipant() = default;
|
||||
|
||||
DialogParticipant(UserId user_id, UserId inviter_user_id, int32 joined_date, DialogParticipantStatus status)
|
||||
: user_id(user_id), inviter_user_id(inviter_user_id), joined_date(joined_date), status(status) {
|
||||
}
|
||||
DialogParticipant(UserId user_id, UserId inviter_user_id, int32 joined_date, DialogParticipantStatus status);
|
||||
|
||||
DialogParticipant(tl_object_ptr<telegram_api::ChannelParticipant> &&participant_ptr,
|
||||
DialogParticipantStatus my_status);
|
||||
|
||||
bool is_valid() const;
|
||||
|
||||
template <class StorerT>
|
||||
void store(StorerT &storer) const {
|
||||
td::store(user_id, storer);
|
||||
|
@ -27802,6 +27802,10 @@ tl_object_ptr<td_api::ChatEventAction> MessagesManager::get_chat_event_action_ob
|
||||
case telegram_api::channelAdminLogEventActionParticipantInvite::ID: {
|
||||
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionParticipantInvite>(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;
|
||||
return nullptr;
|
||||
}
|
||||
return make_tl_object<td_api::chatEventMemberInvited>(
|
||||
td_->contacts_manager_->get_user_id_object(member.user_id, "chatEventMemberInvited"),
|
||||
member.status.get_chat_member_status_object());
|
||||
@ -27815,6 +27819,10 @@ tl_object_ptr<td_api::ChatEventAction> MessagesManager::get_chat_event_action_ob
|
||||
LOG(ERROR) << old_member.user_id << " VS " << new_member.user_id;
|
||||
return nullptr;
|
||||
}
|
||||
if (!old_member.is_valid() || !new_member.is_valid()) {
|
||||
LOG(ERROR) << "Wrong restrict: " << old_member << " -> " << new_member;
|
||||
return nullptr;
|
||||
}
|
||||
return make_tl_object<td_api::chatEventMemberRestricted>(
|
||||
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());
|
||||
@ -27828,6 +27836,10 @@ tl_object_ptr<td_api::ChatEventAction> MessagesManager::get_chat_event_action_ob
|
||||
LOG(ERROR) << old_member.user_id << " VS " << new_member.user_id;
|
||||
return nullptr;
|
||||
}
|
||||
if (!old_member.is_valid() || !new_member.is_valid()) {
|
||||
LOG(ERROR) << "Wrong edit administrator: " << old_member << " -> " << new_member;
|
||||
return nullptr;
|
||||
}
|
||||
return make_tl_object<td_api::chatEventMemberPromoted>(
|
||||
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());
|
||||
|
Loading…
Reference in New Issue
Block a user