Add enum ReactionListType.

This commit is contained in:
levlam 2024-01-18 20:53:43 +03:00
parent f4388dfc5c
commit 0823ee492e
8 changed files with 175 additions and 265 deletions

View File

@ -460,6 +460,7 @@ set(TDLIB_SOURCE
td/telegram/PrivacyManager.cpp
td/telegram/QueryCombiner.cpp
td/telegram/QueryMerger.cpp
td/telegram/ReactionListType.cpp
td/telegram/ReactionManager.cpp
td/telegram/ReactionType.cpp
td/telegram/RecentDialogList.cpp
@ -782,6 +783,7 @@ set(TDLIB_SOURCE
td/telegram/PublicDialogType.h
td/telegram/QueryCombiner.h
td/telegram/QueryMerger.h
td/telegram/ReactionListType.h
td/telegram/ReactionManager.h
td/telegram/ReactionType.h
td/telegram/RecentDialogList.h

View File

@ -372,6 +372,7 @@ function split_file($file, $chunks, $undo) {
'poll_manager[_(-](?![.]get[(][)])|PollManager' => 'PollManager',
'privacy_manager[_(-](?![.]get[(][)])|PrivacyManager' => 'PrivacyManager',
'PublicDialogType|get_public_dialog_type' => 'PublicDialogType',
'ReactionListType|[a-z_]*_reaction_list_type' => 'ReactionListType',
'reaction_manager[_(-](?![.]get[(][)])|ReactionManager' => 'ReactionManager',
'ReactionType|[a-z_]*_reaction_type' => 'ReactionType',
'RequestActor|RequestOnceActor' => 'RequestActor',

View File

@ -48,6 +48,7 @@
#include "td/telegram/Photo.hpp"
#include "td/telegram/PhotoSize.h"
#include "td/telegram/PremiumGiftOption.hpp"
#include "td/telegram/ReactionListType.h"
#include "td/telegram/ReactionManager.h"
#include "td/telegram/SecretChatLayer.h"
#include "td/telegram/SecretChatsManager.h"
@ -10714,7 +10715,7 @@ void ContactsManager::update_user(User *u, UserId user_id, bool from_binlog, boo
if (td_->option_manager_->get_option_boolean("is_premium") != u->is_premium) {
td_->option_manager_->set_option_boolean("is_premium", u->is_premium);
send_closure(td_->config_manager_, &ConfigManager::request_config, true);
td_->reaction_manager_->reload_top_reactions();
td_->reaction_manager_->reload_reaction_list(ReactionListType::Top);
td_->messages_manager_->update_is_translatable(u->is_premium);
}
}

View File

@ -0,0 +1,39 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include "td/telegram/ReactionListType.h"
namespace td {
string get_reaction_list_type_database_key(ReactionListType reaction_list_type) {
switch (reaction_list_type) {
case ReactionListType::Recent:
return "recent_reactions";
case ReactionListType::Top:
return "top_reactions";
case ReactionListType::DefaultTag:
return "default_tag_reactions";
default:
UNREACHABLE();
return string();
}
}
StringBuilder &operator<<(StringBuilder &string_builder, ReactionListType reaction_list_type) {
switch (reaction_list_type) {
case ReactionListType::Recent:
return string_builder << "recent reactions";
case ReactionListType::Top:
return string_builder << "top reactions";
case ReactionListType::DefaultTag:
return string_builder << "default tag reactions";
default:
UNREACHABLE();
return string_builder;
}
}
} // namespace td

View File

@ -0,0 +1,22 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once
#include "td/utils/common.h"
#include "td/utils/StringBuilder.h"
namespace td {
enum class ReactionListType : int32 { Recent, Top, DefaultTag };
static constexpr int32 MAX_REACTION_LIST_TYPE = 3;
string get_reaction_list_type_database_key(ReactionListType reaction_list_type);
StringBuilder &operator<<(StringBuilder &string_builder, ReactionListType reaction_list_type);
} // namespace td

View File

@ -51,72 +51,49 @@ class GetAvailableReactionsQuery final : public Td::ResultHandler {
}
};
class GetRecentReactionsQuery final : public Td::ResultHandler {
class GetReactionListQuery final : public Td::ResultHandler {
ReactionListType reaction_list_type_;
public:
void send(int32 limit, int64 hash) {
send_query(G()->net_query_creator().create(telegram_api::messages_getRecentReactions(limit, hash)));
void send(ReactionListType reaction_list_type, int64 hash) {
reaction_list_type_ = reaction_list_type;
switch (reaction_list_type) {
case ReactionListType::Recent:
send_query(G()->net_query_creator().create(
telegram_api::messages_getRecentReactions(ReactionManager::MAX_RECENT_REACTIONS, hash)));
break;
case ReactionListType::Top:
send_query(G()->net_query_creator().create(telegram_api::messages_getTopReactions(200, hash)));
break;
case ReactionListType::DefaultTag:
send_query(G()->net_query_creator().create(telegram_api::messages_getDefaultTagReactions(hash)));
break;
default:
UNREACHABLE();
break;
}
}
void on_result(BufferSlice packet) final {
static_assert(std::is_same<telegram_api::messages_getRecentReactions::ReturnType,
telegram_api::messages_getTopReactions::ReturnType>::value,
"");
static_assert(std::is_same<telegram_api::messages_getRecentReactions::ReturnType,
telegram_api::messages_getDefaultTagReactions::ReturnType>::value,
"");
auto result_ptr = fetch_result<telegram_api::messages_getRecentReactions>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for GetRecentReactionsQuery: " << to_string(ptr);
td_->reaction_manager_->on_get_recent_reactions(std::move(ptr));
LOG(INFO) << "Receive result for GetReactionListQuery: " << to_string(ptr);
td_->reaction_manager_->on_get_reaction_list(reaction_list_type_, std::move(ptr));
}
void on_error(Status status) final {
LOG(INFO) << "Receive error for GetRecentReactionsQuery: " << status;
td_->reaction_manager_->on_get_recent_reactions(nullptr);
}
};
class GetTopReactionsQuery final : public Td::ResultHandler {
public:
void send(int64 hash) {
send_query(G()->net_query_creator().create(telegram_api::messages_getTopReactions(200, hash)));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_getTopReactions>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for GetTopReactionsQuery: " << to_string(ptr);
td_->reaction_manager_->on_get_top_reactions(std::move(ptr));
}
void on_error(Status status) final {
LOG(INFO) << "Receive error for GetTopReactionsQuery: " << status;
td_->reaction_manager_->on_get_top_reactions(nullptr);
}
};
class GetDefaultTagReactionsQuery final : public Td::ResultHandler {
public:
void send(int64 hash) {
send_query(G()->net_query_creator().create(telegram_api::messages_getDefaultTagReactions(hash)));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_getDefaultTagReactions>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for GetDefaultTagReactionsQuery: " << to_string(ptr);
td_->reaction_manager_->on_get_default_tag_reactions(std::move(ptr));
}
void on_error(Status status) final {
LOG(INFO) << "Receive error for GetDefaultTagReactionsQuery: " << status;
td_->reaction_manager_->on_get_default_tag_reactions(nullptr);
LOG(INFO) << "Receive error for GetReactionListQuery: " << status;
td_->reaction_manager_->on_get_reaction_list(reaction_list_type_, nullptr);
}
};
@ -137,7 +114,7 @@ class ClearRecentReactionsQuery final : public Td::ResultHandler {
return on_error(result_ptr.move_as_error());
}
td_->reaction_manager_->reload_recent_reactions();
td_->reaction_manager_->reload_reaction_list(ReactionListType::Recent);
promise_.set_value(Unit());
}
@ -145,7 +122,7 @@ class ClearRecentReactionsQuery final : public Td::ResultHandler {
if (!G()->is_expected_error(status)) {
LOG(ERROR) << "Receive error for clear recent reactions: " << status;
}
td_->reaction_manager_->reload_recent_reactions();
td_->reaction_manager_->reload_reaction_list(ReactionListType::Recent);
promise_.set_error(std::move(status));
}
};
@ -249,8 +226,8 @@ void ReactionManager::get_emoji_reaction(const string &emoji,
td_api::object_ptr<td_api::availableReactions> ReactionManager::get_sorted_available_reactions(
ChatReactions available_reactions, ChatReactions active_reactions, int32 row_size) {
load_recent_reactions();
load_top_reactions();
load_reaction_list(ReactionListType::Recent);
load_reaction_list(ReactionListType::Top);
if (row_size < 5 || row_size > 25) {
row_size = 8;
@ -258,8 +235,8 @@ td_api::object_ptr<td_api::availableReactions> ReactionManager::get_sorted_avail
bool is_premium = td_->option_manager_->get_option_boolean("is_premium");
bool show_premium = is_premium;
const auto &recent_reactions = recent_reactions_.reaction_types_;
auto top_reactions = top_reactions_.reaction_types_;
const auto &recent_reactions = get_reaction_list(ReactionListType::Recent).reaction_types_;
auto top_reactions = get_reaction_list(ReactionListType::Top).reaction_types_;
LOG(INFO) << "Have available reactions " << available_reactions << " to be sorted by top reactions " << top_reactions
<< " and recent reactions " << recent_reactions;
if (active_reactions.allow_all_custom_ && active_reactions.allow_all_regular_) {
@ -355,27 +332,29 @@ td_api::object_ptr<td_api::availableReactions> ReactionManager::get_available_re
}
void ReactionManager::add_recent_reaction(const ReactionType &reaction_type) {
load_recent_reactions();
load_reaction_list(ReactionListType::Recent);
auto &reactions = recent_reactions_.reaction_types_;
auto &recent_reactions = get_reaction_list(ReactionListType::Recent);
auto &reactions = recent_reactions.reaction_types_;
if (!reactions.empty() && reactions[0] == reaction_type) {
return;
}
add_to_top(reactions, MAX_RECENT_REACTIONS, reaction_type);
recent_reactions_.hash_ = get_reaction_types_hash(reactions);
recent_reactions.hash_ = get_reaction_types_hash(reactions);
}
void ReactionManager::clear_recent_reactions(Promise<Unit> &&promise) {
load_recent_reactions();
load_reaction_list(ReactionListType::Recent);
if (recent_reactions_.reaction_types_.empty()) {
auto &recent_reactions = get_reaction_list(ReactionListType::Recent);
if (recent_reactions.reaction_types_.empty()) {
return promise.set_value(Unit());
}
recent_reactions_.hash_ = 0;
recent_reactions_.reaction_types_.clear();
recent_reactions.hash_ = 0;
recent_reactions.reaction_types_.clear();
td_->create_handler<ClearRecentReactionsQuery>(std::move(promise))->send();
}
@ -390,34 +369,15 @@ void ReactionManager::reload_reactions() {
td_->create_handler<GetAvailableReactionsQuery>()->send(reactions_.hash_);
}
void ReactionManager::reload_recent_reactions() {
if (G()->close_flag() || recent_reactions_.is_being_reloaded_) {
void ReactionManager::reload_reaction_list(ReactionListType reaction_list_type) {
auto &reaction_list = get_reaction_list(reaction_list_type);
if (G()->close_flag() || reaction_list.is_being_reloaded_) {
return;
}
CHECK(!td_->auth_manager_->is_bot());
recent_reactions_.is_being_reloaded_ = true;
load_recent_reactions(); // must be after is_being_reloaded_ is set to true to avoid recursion
td_->create_handler<GetRecentReactionsQuery>()->send(MAX_RECENT_REACTIONS, recent_reactions_.hash_);
}
void ReactionManager::reload_top_reactions() {
if (G()->close_flag() || top_reactions_.is_being_reloaded_) {
return;
}
CHECK(!td_->auth_manager_->is_bot());
top_reactions_.is_being_reloaded_ = true;
load_top_reactions(); // must be after is_being_reloaded_ is set to true to avoid recursion
td_->create_handler<GetTopReactionsQuery>()->send(top_reactions_.hash_);
}
void ReactionManager::reload_default_tag_reactions() {
if (G()->close_flag() || default_tag_reactions_.is_being_reloaded_) {
return;
}
CHECK(!td_->auth_manager_->is_bot());
default_tag_reactions_.is_being_reloaded_ = true;
load_default_tag_reactions(); // must be after is_being_reloaded_ is set to true to avoid recursion
td_->create_handler<GetDefaultTagReactionsQuery>()->send(default_tag_reactions_.hash_);
reaction_list.is_being_reloaded_ = true;
load_reaction_list(reaction_list_type); // must be after is_being_reloaded_ is set to true to avoid recursion
td_->create_handler<GetReactionListQuery>()->send(reaction_list_type, reaction_list.hash_);
}
td_api::object_ptr<td_api::updateActiveEmojiReactions> ReactionManager::get_update_active_emoji_reactions_object()
@ -426,6 +386,10 @@ td_api::object_ptr<td_api::updateActiveEmojiReactions> ReactionManager::get_upda
transform(active_reaction_types_, [](const ReactionType &reaction_type) { return reaction_type.get_string(); }));
}
ReactionManager::ReactionList &ReactionManager::get_reaction_list(ReactionListType reaction_list_type) {
return reaction_lists_[static_cast<int32>(reaction_list_type)];
}
void ReactionManager::save_active_reactions() {
LOG(INFO) << "Save " << active_reaction_types_.size() << " active reactions";
G()->td_db()->get_binlog_pmc()->set("active_reactions", log_event_store(active_reaction_types_).as_slice().str());
@ -437,23 +401,12 @@ void ReactionManager::save_reactions() {
G()->td_db()->get_binlog_pmc()->set("reactions", log_event_store(reactions_).as_slice().str());
}
void ReactionManager::save_recent_reactions() {
LOG(INFO) << "Save " << recent_reactions_.reaction_types_.size() << " recent reactions";
recent_reactions_.is_loaded_from_database_ = true;
G()->td_db()->get_binlog_pmc()->set("recent_reactions", log_event_store(recent_reactions_).as_slice().str());
}
void ReactionManager::save_top_reactions() {
LOG(INFO) << "Save " << top_reactions_.reaction_types_.size() << " top reactions";
top_reactions_.is_loaded_from_database_ = true;
G()->td_db()->get_binlog_pmc()->set("top_reactions", log_event_store(top_reactions_).as_slice().str());
}
void ReactionManager::save_default_tag_reactions() {
LOG(INFO) << "Save " << default_tag_reactions_.reaction_types_.size() << " default tag reactions";
default_tag_reactions_.is_loaded_from_database_ = true;
G()->td_db()->get_binlog_pmc()->set("default_tag_reactions",
log_event_store(default_tag_reactions_).as_slice().str());
void ReactionManager::save_reaction_list(ReactionListType reaction_list_type) {
auto &reaction_list = get_reaction_list(reaction_list_type);
LOG(INFO) << "Save " << reaction_list.reaction_types_.size() << ' ' << reaction_list_type;
reaction_list.is_loaded_from_database_ = true;
G()->td_db()->get_binlog_pmc()->set(get_reaction_list_type_database_key(reaction_list_type),
log_event_store(reaction_list).as_slice().str());
}
void ReactionManager::load_active_reactions() {
@ -508,70 +461,27 @@ void ReactionManager::load_reactions() {
update_active_reactions();
}
void ReactionManager::load_recent_reactions() {
if (recent_reactions_.is_loaded_from_database_) {
void ReactionManager::load_reaction_list(ReactionListType reaction_list_type) {
auto &reaction_list = get_reaction_list(reaction_list_type);
if (reaction_list.is_loaded_from_database_) {
return;
}
recent_reactions_.is_loaded_from_database_ = true;
reaction_list.is_loaded_from_database_ = true;
LOG(INFO) << "Loading recent reactions";
string recent_reactions = G()->td_db()->get_binlog_pmc()->get("recent_reactions");
if (recent_reactions.empty()) {
return reload_recent_reactions();
LOG(INFO) << "Loading " << reaction_list_type;
string reactions_str = G()->td_db()->get_binlog_pmc()->get(get_reaction_list_type_database_key(reaction_list_type));
if (reactions_str.empty()) {
return reload_reaction_list(reaction_list_type);
}
auto status = log_event_parse(recent_reactions_, recent_reactions);
auto status = log_event_parse(reaction_list, reactions_str);
if (status.is_error()) {
LOG(ERROR) << "Can't load recent reactions: " << status;
recent_reactions_ = {};
return reload_recent_reactions();
LOG(ERROR) << "Can't load " << reaction_list_type << ": " << status;
reaction_list = {};
return reload_reaction_list(reaction_list_type);
}
LOG(INFO) << "Successfully loaded " << recent_reactions_.reaction_types_.size() << " recent reactions";
}
void ReactionManager::load_top_reactions() {
if (top_reactions_.is_loaded_from_database_) {
return;
}
top_reactions_.is_loaded_from_database_ = true;
LOG(INFO) << "Loading top reactions";
string top_reactions = G()->td_db()->get_binlog_pmc()->get("top_reactions");
if (top_reactions.empty()) {
return reload_top_reactions();
}
auto status = log_event_parse(top_reactions_, top_reactions);
if (status.is_error()) {
LOG(ERROR) << "Can't load top reactions: " << status;
top_reactions_ = {};
return reload_top_reactions();
}
LOG(INFO) << "Successfully loaded " << top_reactions_.reaction_types_.size() << " top reactions";
}
void ReactionManager::load_default_tag_reactions() {
if (default_tag_reactions_.is_loaded_from_database_) {
return;
}
default_tag_reactions_.is_loaded_from_database_ = true;
LOG(INFO) << "Loading default tag reactions";
string default_tag_reactions = G()->td_db()->get_binlog_pmc()->get("default_tag_reactions");
if (default_tag_reactions.empty()) {
return reload_default_tag_reactions();
}
auto status = log_event_parse(default_tag_reactions_, default_tag_reactions);
if (status.is_error()) {
LOG(ERROR) << "Can't load default tag reactions: " << status;
default_tag_reactions_ = {};
return reload_default_tag_reactions();
}
LOG(INFO) << "Successfully loaded " << default_tag_reactions_.reaction_types_.size() << " default tag reactions";
LOG(INFO) << "Successfully loaded " << reaction_list.reaction_types_.size() << ' ' << reaction_list_type;
}
void ReactionManager::update_active_reactions() {
@ -673,95 +583,40 @@ void ReactionManager::on_get_available_reactions(
update_active_reactions();
}
void ReactionManager::on_get_recent_reactions(tl_object_ptr<telegram_api::messages_Reactions> &&reactions_ptr) {
CHECK(recent_reactions_.is_being_reloaded_);
recent_reactions_.is_being_reloaded_ = false;
void ReactionManager::on_get_reaction_list(ReactionListType reaction_list_type,
tl_object_ptr<telegram_api::messages_Reactions> &&reactions_ptr) {
auto &reaction_list = get_reaction_list(reaction_list_type);
CHECK(reaction_list.is_being_reloaded_);
reaction_list.is_being_reloaded_ = false;
if (reactions_ptr == nullptr) {
// failed to get recent reactions
// failed to get reactions
return;
}
int32 constructor_id = reactions_ptr->get_id();
if (constructor_id == telegram_api::messages_reactionsNotModified::ID) {
LOG(INFO) << "Top reactions are not modified";
LOG(INFO) << "List of " << reaction_list_type << " is not modified";
return;
}
CHECK(constructor_id == telegram_api::messages_reactions::ID);
auto reactions = move_tl_object_as<telegram_api::messages_reactions>(reactions_ptr);
auto new_reaction_types = ReactionType::get_reaction_types(reactions->reactions_);
if (new_reaction_types == recent_reactions_.reaction_types_ && recent_reactions_.hash_ == reactions->hash_) {
LOG(INFO) << "Top reactions are not modified";
if (new_reaction_types == reaction_list.reaction_types_ && reaction_list.hash_ == reactions->hash_) {
LOG(INFO) << "List of " << reaction_list_type << " is not modified";
return;
}
recent_reactions_.reaction_types_ = std::move(new_reaction_types);
recent_reactions_.hash_ = reactions->hash_;
reaction_list.reaction_types_ = std::move(new_reaction_types);
reaction_list.hash_ = reactions->hash_;
auto expected_hash = get_reaction_types_hash(recent_reactions_.reaction_types_);
if (recent_reactions_.hash_ != expected_hash) {
LOG(ERROR) << "Receive hash " << recent_reactions_.hash_ << " instead of " << expected_hash << " for reactions "
<< recent_reactions_.reaction_types_;
auto expected_hash = get_reaction_types_hash(reaction_list.reaction_types_);
if (reaction_list.hash_ != expected_hash) {
LOG(ERROR) << "Receive hash " << reaction_list.hash_ << " instead of " << expected_hash << " for "
<< reaction_list_type << reaction_list.reaction_types_;
}
save_recent_reactions();
}
void ReactionManager::on_get_top_reactions(tl_object_ptr<telegram_api::messages_Reactions> &&reactions_ptr) {
CHECK(top_reactions_.is_being_reloaded_);
top_reactions_.is_being_reloaded_ = false;
if (reactions_ptr == nullptr) {
// failed to get top reactions
return;
}
int32 constructor_id = reactions_ptr->get_id();
if (constructor_id == telegram_api::messages_reactionsNotModified::ID) {
LOG(INFO) << "Top reactions are not modified";
return;
}
CHECK(constructor_id == telegram_api::messages_reactions::ID);
auto reactions = move_tl_object_as<telegram_api::messages_reactions>(reactions_ptr);
auto new_reaction_types = ReactionType::get_reaction_types(reactions->reactions_);
if (new_reaction_types == top_reactions_.reaction_types_ && top_reactions_.hash_ == reactions->hash_) {
LOG(INFO) << "Top reactions are not modified";
return;
}
top_reactions_.reaction_types_ = std::move(new_reaction_types);
top_reactions_.hash_ = reactions->hash_;
save_top_reactions();
}
void ReactionManager::on_get_default_tag_reactions(tl_object_ptr<telegram_api::messages_Reactions> &&reactions_ptr) {
CHECK(default_tag_reactions_.is_being_reloaded_);
default_tag_reactions_.is_being_reloaded_ = false;
if (reactions_ptr == nullptr) {
// failed to get default tag reactions
return;
}
int32 constructor_id = reactions_ptr->get_id();
if (constructor_id == telegram_api::messages_reactionsNotModified::ID) {
LOG(INFO) << "Top reactions are not modified";
return;
}
CHECK(constructor_id == telegram_api::messages_reactions::ID);
auto reactions = move_tl_object_as<telegram_api::messages_reactions>(reactions_ptr);
auto new_reaction_types = ReactionType::get_reaction_types(reactions->reactions_);
if (new_reaction_types == default_tag_reactions_.reaction_types_ &&
default_tag_reactions_.hash_ == reactions->hash_) {
LOG(INFO) << "Top reactions are not modified";
return;
}
default_tag_reactions_.reaction_types_ = std::move(new_reaction_types);
default_tag_reactions_.hash_ = reactions->hash_;
save_default_tag_reactions();
save_reaction_list(reaction_list_type);
}
bool ReactionManager::is_active_reaction(const ReactionType &reaction_type) const {

View File

@ -8,6 +8,7 @@
#include "td/telegram/ChatReactions.h"
#include "td/telegram/files/FileId.h"
#include "td/telegram/ReactionListType.h"
#include "td/telegram/ReactionType.h"
#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
@ -32,6 +33,8 @@ class ReactionManager final : public Actor {
ReactionManager &operator=(ReactionManager &&) = delete;
~ReactionManager() final;
static constexpr size_t MAX_RECENT_REACTIONS = 100; // some reasonable value
void init();
bool is_active_reaction(const ReactionType &reaction_type) const;
@ -50,20 +53,13 @@ class ReactionManager final : public Actor {
void reload_reactions();
void reload_recent_reactions();
void reload_reaction_list(ReactionListType reaction_list_type);
void reload_top_reactions();
void reload_default_tag_reactions();
void on_get_reaction_list(ReactionListType reaction_list_type,
tl_object_ptr<telegram_api::messages_Reactions> &&reactions_ptr);
void on_get_available_reactions(tl_object_ptr<telegram_api::messages_AvailableReactions> &&available_reactions_ptr);
void on_get_recent_reactions(tl_object_ptr<telegram_api::messages_Reactions> &&reactions_ptr);
void on_get_top_reactions(tl_object_ptr<telegram_api::messages_Reactions> &&reactions_ptr);
void on_get_default_tag_reactions(tl_object_ptr<telegram_api::messages_Reactions> &&reactions_ptr);
void set_default_reaction(ReactionType reaction_type, Promise<Unit> &&promise);
void send_set_default_reaction_query();
@ -71,8 +67,6 @@ class ReactionManager final : public Actor {
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
private:
static constexpr size_t MAX_RECENT_REACTIONS = 100; // some reasonable value
struct Reaction {
ReactionType reaction_type_;
string title_;
@ -125,6 +119,8 @@ class ReactionManager final : public Actor {
td_api::object_ptr<td_api::emojiReaction> get_emoji_reaction_object(const string &emoji) const;
ReactionList &get_reaction_list(ReactionListType reaction_list_type);
void start_up() final;
void tear_down() final;
@ -133,21 +129,13 @@ class ReactionManager final : public Actor {
void save_reactions();
void save_recent_reactions();
void save_top_reactions();
void save_default_tag_reactions();
void save_reaction_list(ReactionListType reaction_list_type);
void load_active_reactions();
void load_reactions();
void load_recent_reactions();
void load_top_reactions();
void load_default_tag_reactions();
void load_reaction_list(ReactionListType reaction_list_type);
void update_active_reactions();
@ -163,9 +151,7 @@ class ReactionManager final : public Actor {
Reactions reactions_;
vector<ReactionType> active_reaction_types_;
ReactionList recent_reactions_;
ReactionList top_reactions_;
ReactionList default_tag_reactions_;
ReactionList reaction_lists_[MAX_REACTION_LIST_TYPE];
bool are_reactions_loaded_from_database_ = false;
};

View File

@ -52,6 +52,7 @@
#include "td/telegram/PollManager.h"
#include "td/telegram/PrivacyManager.h"
#include "td/telegram/PublicDialogType.h"
#include "td/telegram/ReactionListType.h"
#include "td/telegram/ReactionManager.h"
#include "td/telegram/ReactionType.h"
#include "td/telegram/ScheduledServerMessageId.h"
@ -2265,9 +2266,12 @@ void UpdatesManager::try_reload_data() {
td_->notification_settings_manager_->send_get_scope_notification_settings_query(NotificationSettingsScope::Channel,
Auto());
td_->reaction_manager_->reload_reactions();
td_->reaction_manager_->reload_recent_reactions();
td_->reaction_manager_->reload_top_reactions();
td_->reaction_manager_->reload_default_tag_reactions();
for (int32 type = 0; type < MAX_REACTION_LIST_TYPE; type++) {
auto reaction_list_type = static_cast<ReactionListType>(type);
td_->reaction_manager_->reload_reaction_list(reaction_list_type);
}
for (int32 type = 0; type < MAX_STICKER_TYPE; type++) {
auto sticker_type = static_cast<StickerType>(type);
td_->stickers_manager_->get_installed_sticker_sets(sticker_type, Auto());
@ -3704,7 +3708,7 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateMessageReaction
}
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateRecentReactions> update, Promise<Unit> &&promise) {
td_->reaction_manager_->reload_recent_reactions();
td_->reaction_manager_->reload_reaction_list(ReactionListType::Recent);
promise.set_value(Unit());
}