Add MessageReactions logging.

This commit is contained in:
levlam 2022-01-30 13:24:27 +03:00
parent abb2c1a105
commit fe4232ca79
4 changed files with 33 additions and 15 deletions

View File

@ -192,7 +192,7 @@ class GetMessageReactionsListQuery final : public Td::ResultHandler {
} }
}; };
void MessageReaction::set_is_chosen(bool is_chosen, DialogId chooser_dialog_id, bool can_see_all_choosers) { void MessageReaction::set_is_chosen(bool is_chosen, DialogId chooser_dialog_id, bool can_get_added_reactions) {
if (is_chosen_ == is_chosen) { if (is_chosen_ == is_chosen) {
return; return;
} }
@ -201,7 +201,7 @@ 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;
if (can_see_all_choosers) { if (can_get_added_reactions) {
td::remove(recent_chooser_dialog_ids_, chooser_dialog_id); td::remove(recent_chooser_dialog_ids_, chooser_dialog_id);
if (is_chosen_) { if (is_chosen_) {
recent_chooser_dialog_ids_.insert(recent_chooser_dialog_ids_.begin(), chooser_dialog_id); recent_chooser_dialog_ids_.insert(recent_chooser_dialog_ids_.begin(), chooser_dialog_id);
@ -263,7 +263,7 @@ unique_ptr<MessageReactions> MessageReactions::get_message_reactions(
} }
auto result = make_unique<MessageReactions>(); auto result = make_unique<MessageReactions>();
result->can_see_all_choosers_ = reactions->can_see_list_; result->can_get_added_reactions_ = reactions->can_see_list_;
result->is_min_ = reactions->min_; result->is_min_ = reactions->min_;
std::unordered_set<string> reaction_strings; std::unordered_set<string> reaction_strings;
@ -396,7 +396,7 @@ bool MessageReactions::need_update_message_reactions(const MessageReactions *old
// unread_reactions_ are updated independently; compare all other fields // unread_reactions_ are updated independently; compare all other fields
return old_reactions->reactions_ != new_reactions->reactions_ || old_reactions->is_min_ != new_reactions->is_min_ || return old_reactions->reactions_ != new_reactions->reactions_ || old_reactions->is_min_ != new_reactions->is_min_ ||
old_reactions->can_see_all_choosers_ != new_reactions->can_see_all_choosers_ || old_reactions->can_get_added_reactions_ != new_reactions->can_get_added_reactions_ ||
old_reactions->need_polling_ != new_reactions->need_polling_; old_reactions->need_polling_ != new_reactions->need_polling_;
} }
@ -408,6 +408,19 @@ bool MessageReactions::need_update_unread_reactions(const MessageReactions *old_
return new_reactions == nullptr || old_reactions->unread_reactions_ != new_reactions->unread_reactions_; return new_reactions == nullptr || old_reactions->unread_reactions_ != new_reactions->unread_reactions_;
} }
StringBuilder &operator<<(StringBuilder &string_builder, const MessageReactions &reactions) {
return string_builder << (reactions.is_min_ ? "Min" : "") << "MessageReactions{" << reactions.reactions_
<< " with unread " << reactions.unread_reactions_
<< " and can_get_added_reactions = " << reactions.can_get_added_reactions_;
}
StringBuilder &operator<<(StringBuilder &string_builder, const unique_ptr<MessageReactions> &reactions) {
if (reactions == nullptr) {
return string_builder << "null";
}
return string_builder << *reactions;
}
void reload_message_reactions(Td *td, DialogId dialog_id, vector<MessageId> &&message_ids) { void reload_message_reactions(Td *td, DialogId dialog_id, vector<MessageId> &&message_ids) {
if (!td->messages_manager_->have_input_peer(dialog_id, AccessRights::Read) || message_ids.empty()) { if (!td->messages_manager_->have_input_peer(dialog_id, AccessRights::Read) || message_ids.empty()) {
return; return;

View File

@ -64,7 +64,7 @@ class MessageReaction {
return is_chosen_; return is_chosen_;
} }
void set_is_chosen(bool is_chosen, DialogId chooser_dialog_id, bool can_see_all_choosers); void set_is_chosen(bool is_chosen, DialogId chooser_dialog_id, bool can_get_added_reactions);
int32 get_choose_count() const { int32 get_choose_count() const {
return choose_count_; return choose_count_;
@ -133,7 +133,7 @@ struct MessageReactions {
vector<UnreadMessageReaction> unread_reactions_; vector<UnreadMessageReaction> unread_reactions_;
bool is_min_ = false; bool is_min_ = false;
bool need_polling_ = true; bool need_polling_ = true;
bool can_see_all_choosers_ = false; bool can_get_added_reactions_ = false;
MessageReactions() = default; MessageReactions() = default;
@ -162,6 +162,10 @@ struct MessageReactions {
void parse(ParserT &parser); void parse(ParserT &parser);
}; };
StringBuilder &operator<<(StringBuilder &string_builder, const MessageReactions &reactions);
StringBuilder &operator<<(StringBuilder &string_builder, const unique_ptr<MessageReactions> &reactions);
void reload_message_reactions(Td *td, DialogId dialog_id, vector<MessageId> &&message_ids); void reload_message_reactions(Td *td, DialogId dialog_id, vector<MessageId> &&message_ids);
void set_message_reaction(Td *td, FullMessageId full_message_id, string reaction, bool is_big, Promise<Unit> &&promise); void set_message_reaction(Td *td, FullMessageId full_message_id, string reaction, bool is_big, Promise<Unit> &&promise);

View File

@ -78,7 +78,7 @@ void MessageReactions::store(StorerT &storer) const {
BEGIN_STORE_FLAGS(); BEGIN_STORE_FLAGS();
STORE_FLAG(is_min_); STORE_FLAG(is_min_);
STORE_FLAG(need_polling_); STORE_FLAG(need_polling_);
STORE_FLAG(can_see_all_choosers_); STORE_FLAG(can_get_added_reactions_);
STORE_FLAG(has_unread_reactions); STORE_FLAG(has_unread_reactions);
STORE_FLAG(has_reactions); STORE_FLAG(has_reactions);
END_STORE_FLAGS(); END_STORE_FLAGS();
@ -97,7 +97,7 @@ void MessageReactions::parse(ParserT &parser) {
BEGIN_PARSE_FLAGS(); BEGIN_PARSE_FLAGS();
PARSE_FLAG(is_min_); PARSE_FLAG(is_min_);
PARSE_FLAG(need_polling_); PARSE_FLAG(need_polling_);
PARSE_FLAG(can_see_all_choosers_); PARSE_FLAG(can_get_added_reactions_);
PARSE_FLAG(has_unread_reactions); PARSE_FLAG(has_unread_reactions);
PARSE_FLAG(has_reactions); PARSE_FLAG(has_reactions);
END_PARSE_FLAGS(); END_PARSE_FLAGS();

View File

@ -7112,8 +7112,8 @@ bool MessagesManager::update_message_interaction_info(DialogId dialog_id, Messag
if (view_count > m->view_count || forward_count > m->forward_count || need_update_reply_info || if (view_count > m->view_count || forward_count > m->forward_count || need_update_reply_info ||
need_update_reactions || need_update_unread_reactions) { need_update_reactions || need_update_unread_reactions) {
LOG(DEBUG) << "Update interaction info of " << FullMessageId{dialog_id, m->message_id} << " from " << m->view_count LOG(DEBUG) << "Update interaction info of " << FullMessageId{dialog_id, m->message_id} << " from " << m->view_count
<< '/' << m->forward_count << "/" << m->reply_info << " to " << view_count << '/' << forward_count << "/" << '/' << m->forward_count << '/' << m->reply_info << '/' << m->reactions << " to " << view_count << '/'
<< reply_info; << forward_count << '/' << reply_info << '/' << reactions;
bool need_update = false; bool need_update = false;
if (view_count > m->view_count) { if (view_count > m->view_count) {
m->view_count = view_count; m->view_count = view_count;
@ -24121,14 +24121,14 @@ void MessagesManager::set_message_reaction(FullMessageId full_message_id, string
return promise.set_error(Status::Error(400, "The reaction isn't available for the message")); return promise.set_error(Status::Error(400, "The reaction isn't available for the message"));
} }
bool can_see_all_choosers = !is_broadcast_channel(dialog_id); bool can_get_added_reactions = !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; m->reactions->can_get_added_reactions_ = can_get_added_reactions;
} }
bool is_found = false; bool is_found = false;
@ -24139,14 +24139,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, get_my_dialog_id(), can_see_all_choosers); message_reaction.set_is_chosen(false, get_my_dialog_id(), can_get_added_reactions);
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, get_my_dialog_id(), can_see_all_choosers); message_reaction.set_is_chosen(true, get_my_dialog_id(), can_get_added_reactions);
is_found = true; is_found = true;
} }
} }
@ -24413,7 +24413,8 @@ tl_object_ptr<td_api::message> MessagesManager::get_message_object(DialogId dial
auto can_be_saved = can_save_message(dialog_id, m); auto can_be_saved = can_save_message(dialog_id, m);
auto can_be_edited = for_event_log ? false : can_edit_message(dialog_id, m, false, td_->auth_manager_->is_bot()); auto can_be_edited = for_event_log ? false : can_edit_message(dialog_id, m, false, td_->auth_manager_->is_bot());
auto can_be_forwarded = for_event_log ? false : can_forward_message(dialog_id, m) && can_be_saved; auto can_be_forwarded = for_event_log ? false : can_forward_message(dialog_id, m) && can_be_saved;
auto can_get_added_reactions = for_event_log ? false : m->reactions != nullptr && m->reactions->can_see_all_choosers_; auto can_get_added_reactions =
for_event_log ? false : m->reactions != nullptr && m->reactions->can_get_added_reactions_;
auto can_get_statistics = for_event_log ? false : can_get_message_statistics(dialog_id, m); auto can_get_statistics = for_event_log ? false : can_get_message_statistics(dialog_id, m);
auto can_get_message_thread = for_event_log ? false : get_top_thread_full_message_id(dialog_id, m).is_ok(); auto can_get_message_thread = for_event_log ? false : get_top_thread_full_message_id(dialog_id, m).is_ok();
auto can_get_viewers = for_event_log ? false : can_get_message_viewers(dialog_id, m).is_ok(); auto can_get_viewers = for_event_log ? false : can_get_message_viewers(dialog_id, m).is_ok();