Locally add reaction to recent.

This commit is contained in:
levlam 2022-09-12 20:17:14 +03:00
parent 164f5e97fd
commit 999326d56a
5 changed files with 39 additions and 3 deletions

View File

@ -877,4 +877,8 @@ void report_message_reactions(Td *td, FullMessageId full_message_id, DialogId ch
td->create_handler<ReportReactionQuery>(std::move(promise))->send(dialog_id, message_id, chooser_dialog_id);
}
void add_recent_reaction(Td *td, const string &reaction) {
td->stickers_manager_->add_recent_reaction(reaction);
}
} // namespace td

View File

@ -212,4 +212,6 @@ void send_update_default_reaction_type(const string &default_reaction);
void report_message_reactions(Td *td, FullMessageId full_message_id, DialogId chooser_dialog_id,
Promise<Unit> &&promise);
void add_recent_reaction(Td *td, const string &reaction);
} // namespace td

View File

@ -24557,6 +24557,10 @@ void MessagesManager::add_message_reaction(FullMessageId full_message_id, string
return promise.set_value(Unit());
}
if (add_to_recent) {
add_recent_reaction(td_, reaction);
}
set_message_reactions(d, m, is_big, add_to_recent, std::move(promise));
}

View File

@ -95,8 +95,8 @@ class GetAvailableReactionsQuery final : public Td::ResultHandler {
class GetRecentReactionsQuery final : public Td::ResultHandler {
public:
void send(int64 hash) {
send_query(G()->net_query_creator().create(telegram_api::messages_getRecentReactions(50, hash)));
void send(int32 limit, int64 hash) {
send_query(G()->net_query_creator().create(telegram_api::messages_getRecentReactions(limit, hash)));
}
void on_result(BufferSlice packet) final {
@ -1573,6 +1573,28 @@ td_api::object_ptr<td_api::emojiReaction> StickersManager::get_emoji_reaction_ob
return nullptr;
}
void StickersManager::add_recent_reaction(const string &reaction) {
load_recent_reactions();
auto &reactions = recent_reactions_.reactions_;
if (!reactions.empty() && reactions[0] == reaction) {
return;
}
auto it = std::find(reactions.begin(), reactions.end(), reaction);
if (it == reactions.end()) {
if (static_cast<int32>(reactions.size()) == MAX_RECENT_REACTIONS) {
reactions.back() = reaction;
} else {
reactions.push_back(reaction);
}
it = reactions.end() - 1;
}
std::rotate(reactions.begin(), it, it + 1);
recent_reactions_.hash_ = 0;
}
void StickersManager::clear_recent_reactions(Promise<Unit> &&promise) {
load_recent_reactions();
@ -1603,7 +1625,7 @@ void StickersManager::reload_recent_reactions() {
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(recent_reactions_.hash_);
td_->create_handler<GetRecentReactionsQuery>()->send(MAX_RECENT_REACTIONS, recent_reactions_.hash_);
}
void StickersManager::reload_top_reactions() {

View File

@ -173,6 +173,8 @@ class StickersManager final : public Actor {
td_api::object_ptr<td_api::emojiReaction> get_emoji_reaction_object(const string &emoji);
void add_recent_reaction(const string &reaction);
void clear_recent_reactions(Promise<Unit> &&promise);
void reload_reactions();
@ -403,6 +405,8 @@ class StickersManager final : public Actor {
static constexpr int32 EMOJI_KEYWORDS_UPDATE_DELAY = 3600;
static constexpr double MIN_ANIMATED_EMOJI_CLICK_DELAY = 0.2;
static constexpr int32 MAX_RECENT_REACTIONS = 100; // some reasonable value
class Sticker {
public:
StickerSetId set_id_;