Skip to content

Commit f2e36ab

Browse files
committed
Remove self from recent voters when vote is retracted.
1 parent a6cd5eb commit f2e36ab

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

td/telegram/PollManager.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,19 +733,35 @@ td_api::object_ptr<td_api::poll> PollManager::get_poll_object(PollId poll_id, co
733733
int32 initial_date, bool is_real_message_content) const {
734734
auto poll_options = transform(
735735
poll->options_, [td = td_](const PollOption &poll_option) { return poll_option.get_poll_option_object(td); });
736+
auto recent_voters = get_min_message_senders_object(td_, poll->recent_voter_dialog_ids_, "get_poll_object");
736737
int32 voter_count_diff = 0;
737738
auto it = pending_answers_.find(poll_id);
738739
if (it != pending_answers_.end() && !(it->second.is_finished_ && poll->was_saved_)) {
739740
const auto &chosen_options = it->second.options_;
740741
LOG(INFO) << "Have pending chosen options " << chosen_options << " in " << poll_id;
742+
auto remove_self = [&](vector<td_api::object_ptr<td_api::MessageSender>> &voters) {
743+
for (auto voter_it = voters.begin(); voter_it != voters.end(); ++voter_it) {
744+
auto &voter_id = *voter_it;
745+
if (voter_id->get_id() == td_api::messageSenderUser::ID &&
746+
static_cast<const td_api::messageSenderUser *>(voter_id.get())->user_id_ ==
747+
td_->user_manager_->get_my_id().get()) {
748+
voters.erase(voter_it);
749+
break;
750+
}
751+
}
752+
};
741753
for (auto &poll_option : poll_options) {
742754
poll_option->is_being_chosen_ = td::contains(chosen_options, poll_option->id_);
743-
if (poll_option->is_chosen_) {
755+
if (poll_option->is_chosen_ && !poll_option->is_being_chosen_) {
744756
voter_count_diff = -1;
745757
poll_option->voter_count_--;
746758
poll_option->is_chosen_ = false;
759+
remove_self(poll_option->recent_voter_ids_);
747760
}
748761
}
762+
if (chosen_options.empty()) {
763+
remove_self(recent_voters);
764+
}
749765
}
750766
for (const auto &const_poll_option : poll_options) {
751767
if (!check_utf8(const_poll_option->id_)) {
@@ -822,7 +838,6 @@ td_api::object_ptr<td_api::poll> PollManager::get_poll_object(PollId poll_id, co
822838
close_date = 0;
823839
}
824840

825-
auto recent_voters = get_min_message_senders_object(td_, poll->recent_voter_dialog_ids_, "get_poll_object");
826841
vector<int32> option_order;
827842
if (poll->shuffle_answers_ && !poll->is_creator_ && !td_->auth_manager_->is_bot()) {
828843
auto my_user_id = td_->user_manager_->get_my_id().get();

0 commit comments

Comments
 (0)