Update recent reaction choosers in setMessageReaction.
This commit is contained in:
parent
bad018bc32
commit
5edc92dd72
|
@ -142,7 +142,7 @@ class GetMessageReactionsListQuery final : public Td::ResultHandler {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void MessageReaction::set_is_chosen(bool is_chosen, DialogId chooser_dialog_id) {
|
void MessageReaction::set_is_chosen(bool is_chosen, DialogId chooser_dialog_id, bool can_see_all_choosers) {
|
||||||
if (is_chosen_ == is_chosen) {
|
if (is_chosen_ == is_chosen) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,15 @@ void MessageReaction::set_is_chosen(bool is_chosen, DialogId chooser_dialog_id)
|
||||||
|
|
||||||
if (chooser_dialog_id.is_valid()) {
|
if (chooser_dialog_id.is_valid()) {
|
||||||
choose_count_ += is_chosen_ ? 1 : -1;
|
choose_count_ += is_chosen_ ? 1 : -1;
|
||||||
// TODO update recent_chooser_dialog_ids_, but only if not broadcast
|
if (can_see_all_choosers) {
|
||||||
|
td::remove(recent_chooser_dialog_ids_, chooser_dialog_id);
|
||||||
|
if (is_chosen_) {
|
||||||
|
recent_chooser_dialog_ids_.insert(recent_chooser_dialog_ids_.begin(), chooser_dialog_id);
|
||||||
|
if (recent_chooser_dialog_ids_.size() > MAX_RECENT_CHOOSERS) {
|
||||||
|
recent_chooser_dialog_ids_.resize(MAX_RECENT_CHOOSERS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,7 +276,7 @@ void MessageReactions::update_from(const MessageReactions &old_reactions) {
|
||||||
if (old_reaction.is_chosen()) {
|
if (old_reaction.is_chosen()) {
|
||||||
for (auto &reaction : reactions_) {
|
for (auto &reaction : reactions_) {
|
||||||
if (reaction.get_reaction() == old_reaction.get_reaction()) {
|
if (reaction.get_reaction() == old_reaction.get_reaction()) {
|
||||||
reaction.set_is_chosen(true);
|
reaction.set_is_chosen(true, DialogId(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -277,20 +285,21 @@ void MessageReactions::update_from(const MessageReactions &old_reactions) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageReactions::sort(const std::unordered_map<string, size_t> &active_reaction_pos) {
|
void MessageReactions::sort(const std::unordered_map<string, size_t> &active_reaction_pos) {
|
||||||
std::sort(reactions_.begin(), reactions_.end(), [&active_reaction_pos](const MessageReaction &lhs, const MessageReaction &rhs) {
|
std::sort(reactions_.begin(), reactions_.end(),
|
||||||
if (lhs.get_choose_count() != rhs.get_choose_count()) {
|
[&active_reaction_pos](const MessageReaction &lhs, const MessageReaction &rhs) {
|
||||||
return lhs.get_choose_count() > rhs.get_choose_count();
|
if (lhs.get_choose_count() != rhs.get_choose_count()) {
|
||||||
}
|
return lhs.get_choose_count() > rhs.get_choose_count();
|
||||||
auto lhs_it = active_reaction_pos.find(lhs.get_reaction());
|
}
|
||||||
auto lhs_pos = lhs_it != active_reaction_pos.end() ? lhs_it->second : active_reaction_pos.size();
|
auto lhs_it = active_reaction_pos.find(lhs.get_reaction());
|
||||||
auto rhs_it = active_reaction_pos.find(rhs.get_reaction());
|
auto lhs_pos = lhs_it != active_reaction_pos.end() ? lhs_it->second : active_reaction_pos.size();
|
||||||
auto rhs_pos = rhs_it != active_reaction_pos.end() ? rhs_it->second : active_reaction_pos.size();
|
auto rhs_it = active_reaction_pos.find(rhs.get_reaction());
|
||||||
if (lhs_pos != rhs_pos) {
|
auto rhs_pos = rhs_it != active_reaction_pos.end() ? rhs_it->second : active_reaction_pos.size();
|
||||||
return lhs_pos < rhs_pos;
|
if (lhs_pos != rhs_pos) {
|
||||||
}
|
return lhs_pos < rhs_pos;
|
||||||
|
}
|
||||||
|
|
||||||
return lhs.get_reaction() < rhs.get_reaction();
|
return lhs.get_reaction() < rhs.get_reaction();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MessageReactions::need_update_message_reactions(const MessageReactions *old_reactions,
|
bool MessageReactions::need_update_message_reactions(const MessageReactions *old_reactions,
|
||||||
|
|
|
@ -63,7 +63,7 @@ class MessageReaction {
|
||||||
return is_chosen_;
|
return is_chosen_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_is_chosen(bool is_chosen, DialogId chooser_dialog_id = DialogId());
|
void set_is_chosen(bool is_chosen, DialogId chooser_dialog_id, bool can_see_all_choosers);
|
||||||
|
|
||||||
int32 get_choose_count() const {
|
int32 get_choose_count() const {
|
||||||
return choose_count_;
|
return choose_count_;
|
||||||
|
|
|
@ -23739,8 +23739,7 @@ void MessagesManager::set_message_reaction(FullMessageId full_message_id, string
|
||||||
return promise.set_error(Status::Error(400, "Message not found"));
|
return promise.set_error(Status::Error(400, "Message not found"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (full_message_id.get_dialog_id().get_type() == DialogType::SecretChat || !m->message_id.is_valid() ||
|
if (dialog_id.get_type() == DialogType::SecretChat || !m->message_id.is_valid() || !m->message_id.is_server()) {
|
||||||
!m->message_id.is_server()) {
|
|
||||||
return promise.set_error(Status::Error(400, "Message can't have reactions"));
|
return promise.set_error(Status::Error(400, "Message can't have reactions"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23748,12 +23747,14 @@ void MessagesManager::set_message_reaction(FullMessageId full_message_id, string
|
||||||
return promise.set_error(Status::Error(400, "Invalid reaction specified"));
|
return promise.set_error(Status::Error(400, "Invalid reaction specified"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool can_see_all_choosers = !is_broadcast_channel(dialog_id);
|
||||||
if (m->reactions == nullptr) {
|
if (m->reactions == nullptr) {
|
||||||
if (reaction.empty()) {
|
if (reaction.empty()) {
|
||||||
return promise.set_value(Unit());
|
return promise.set_value(Unit());
|
||||||
}
|
}
|
||||||
|
|
||||||
m->reactions = make_unique<MessageReactions>();
|
m->reactions = make_unique<MessageReactions>();
|
||||||
|
m->reactions->can_see_all_choosers_ = can_see_all_choosers;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_found = false;
|
bool is_found = false;
|
||||||
|
@ -23764,14 +23765,14 @@ void MessagesManager::set_message_reaction(FullMessageId full_message_id, string
|
||||||
// double set removes reaction
|
// double set removes reaction
|
||||||
reaction = string();
|
reaction = string();
|
||||||
}
|
}
|
||||||
message_reaction.set_is_chosen(false);
|
message_reaction.set_is_chosen(false, get_my_dialog_id(), can_see_all_choosers);
|
||||||
if (message_reaction.is_empty()) {
|
if (message_reaction.is_empty()) {
|
||||||
it = m->reactions->reactions_.erase(it);
|
it = m->reactions->reactions_.erase(it);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (message_reaction.get_reaction() == reaction) {
|
if (message_reaction.get_reaction() == reaction) {
|
||||||
message_reaction.set_is_chosen(true);
|
message_reaction.set_is_chosen(true, get_my_dialog_id(), can_see_all_choosers);
|
||||||
is_found = true;
|
is_found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user