From c6c82220a4e30b060fc9caa6abce6a83afc1e785 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 12 Dec 2018 15:57:24 +0300 Subject: [PATCH] Add on_sent_message_content. GitOrigin-RevId: ce05a403dd251208c19696598b7ff2fea7b910f0 --- td/telegram/AnimationsManager.cpp | 1 + td/telegram/MessageContent.cpp | 12 ++++++++++++ td/telegram/MessageContent.h | 2 ++ td/telegram/MessagesManager.cpp | 18 +++--------------- td/telegram/StickersManager.cpp | 1 + 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/td/telegram/AnimationsManager.cpp b/td/telegram/AnimationsManager.cpp index ef409b981..1258ad5d2 100644 --- a/td/telegram/AnimationsManager.cpp +++ b/td/telegram/AnimationsManager.cpp @@ -570,6 +570,7 @@ void AnimationsManager::add_saved_animation_by_id(FileId animation_id) { bool AnimationsManager::add_saved_animation_impl(FileId animation_id, Promise &promise) { CHECK(!td_->auth_manager_->is_bot()); + LOG(INFO) << "Add saved animation " << animation_id; if (!are_saved_animations_loaded_) { load_saved_animations(PromiseCreator::lambda([animation_id, promise = std::move(promise)](Result<> result) mutable { if (result.is_ok()) { diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index c3a531542..28658e5d9 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -4524,4 +4524,16 @@ void add_message_content_dependencies(Dependencies &dependencies, const MessageC add_formatted_text_dependencies(dependencies, get_message_content_text(message_content)); } +void on_sent_message_content(Td *td, const MessageContent *content) { + switch (content->get_type()) { + case MessageContentType::Animation: + return td->animations_manager_->add_saved_animation_by_id(get_message_content_file_id(content)); + case MessageContentType::Sticker: + return td->stickers_manager_->add_recent_sticker_by_id(false, get_message_content_file_id(content)); + default: + // nothing to do + return; + } +} + } // namespace td diff --git a/td/telegram/MessageContent.h b/td/telegram/MessageContent.h index f0db868cd..1d52c8cae 100644 --- a/td/telegram/MessageContent.h +++ b/td/telegram/MessageContent.h @@ -221,6 +221,8 @@ string get_message_content_search_text(const Td *td, const MessageContent *conte void update_expired_message_content(unique_ptr &content); +void on_sent_message_content(Td *td, const MessageContent *content); + void add_message_content_dependencies(Dependencies &dependencies, const MessageContent *message_content); } // namespace td diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 2efe3ff89..ccf1a9a57 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -6,7 +6,6 @@ // #include "td/telegram/MessagesManager.h" -#include "td/telegram/AnimationsManager.h" #include "td/telegram/AuthManager.h" #include "td/telegram/ChatId.h" #include "td/telegram/ConfigShared.h" @@ -21036,21 +21035,10 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq } if (!td_->auth_manager_->is_bot() && from_update && m->forward_info == nullptr && (m->is_outgoing || dialog_id == my_dialog_id)) { - switch (message_content_type) { - case MessageContentType::Animation: - if (dialog_id.get_type() != DialogType::SecretChat) { - td_->animations_manager_->add_saved_animation_by_id(get_message_content_file_id(m->content.get())); - } - break; - case MessageContentType::Sticker: - if (dialog_id.get_type() != DialogType::SecretChat) { - td_->stickers_manager_->add_recent_sticker_by_id(false, get_message_content_file_id(m->content.get())); - } - break; - default: - update_used_hashtags(dialog_id, m); - break; + if (dialog_id.get_type() != DialogType::SecretChat && !message_id.is_local()) { + on_sent_message_content(td_, m->content.get()); } + update_used_hashtags(dialog_id, m); } if (!td_->auth_manager_->is_bot() && from_update && message_id.is_server() && (m->is_outgoing || dialog_id == my_dialog_id) && dialog_id.get_type() != DialogType::SecretChat) { diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index d84ca6b26..3bb230e7e 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -3701,6 +3701,7 @@ void StickersManager::add_recent_sticker_by_id(bool is_attached, FileId sticker_ bool StickersManager::add_recent_sticker_impl(bool is_attached, FileId sticker_id, Promise &promise) { CHECK(!td_->auth_manager_->is_bot()); + LOG(INFO) << "Add recent " << (is_attached ? "attached " : "") << "sticker " << sticker_id; if (!are_recent_stickers_loaded_[is_attached]) { load_recent_stickers(is_attached, PromiseCreator::lambda([is_attached, sticker_id, promise = std::move(promise)](Result<> result) mutable {