From bfaaf09b2bd868db96c716630534f8b0c664e3fd Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 21 Feb 2019 01:54:31 +0300 Subject: [PATCH] Send updateMEssageContent about changed polls. GitOrigin-RevId: bb61f466759ac27c687411861f8c7452cd5758ce --- td/telegram/MessagesManager.cpp | 7 +++++++ td/telegram/MessagesManager.h | 2 ++ td/telegram/PollManager.cpp | 19 +++++++++++++++++-- td/telegram/PollManager.h | 2 ++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 958da6401..4c1c99da1 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -5017,6 +5017,13 @@ bool MessagesManager::update_message_views(DialogId dialog_id, Message *m, int32 return false; } +void MessagesManager::on_update_message_content(FullMessageId full_message_id) { + const Message *m = get_message(full_message_id); + CHECK(m != nullptr); + send_update_message_content(full_message_id.get_dialog_id(), m->message_id, m->content.get(), m->date, + m->is_content_secret, "on_update_message_content"); +} + bool MessagesManager::update_message_contains_unread_mention(Dialog *d, Message *m, bool contains_unread_mention, const char *source) { LOG_CHECK(m != nullptr) << source; diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 8a97fc038..8982992f1 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -295,6 +295,8 @@ class MessagesManager : public Actor { void on_update_message_views(FullMessageId full_message_id, int32 views); + void on_update_message_content(FullMessageId full_message_id); + void on_read_channel_inbox(ChannelId channel_id, MessageId max_message_id, int32 server_unread_count); void on_read_channel_outbox(ChannelId channel_id, MessageId max_message_id); diff --git a/td/telegram/PollManager.cpp b/td/telegram/PollManager.cpp index f9be8c962..81442cd64 100644 --- a/td/telegram/PollManager.cpp +++ b/td/telegram/PollManager.cpp @@ -8,6 +8,7 @@ #include "td/telegram/Global.h" #include "td/telegram/logevent/LogEvent.h" +#include "td/telegram/MessagesManager.h" #include "td/telegram/PollManager.hpp" #include "td/telegram/TdDb.h" #include "td/telegram/Td.h" @@ -56,19 +57,31 @@ bool PollManager::have_poll(PollId poll_id) const { return get_poll(poll_id) != nullptr; } +void PollManager::notify_on_poll_update(PollId poll_id) { + auto it = poll_messages_.find(poll_id); + if (it == poll_messages_.end()) { + return; + } + + for (auto full_message_id : it->second) { + td_->messages_manager_->on_update_message_content(full_message_id); + } +} + string PollManager::get_poll_database_key(PollId poll_id) { return PSTRING() << "poll" << poll_id.get(); } void PollManager::save_poll(const Poll *poll, PollId poll_id) { + CHECK(!is_local_poll_id(poll_id)); + if (!G()->parameters().use_message_db) { return; } - CHECK(!is_local_poll_id(poll_id)); LOG(INFO) << "Save " << poll_id << " to database"; CHECK(poll != nullptr); - // G()->td_db()->get_sqlite_pmc()->set(get_poll_database_key(poll_id), log_event_store(*poll).as_slice().str(), Auto()); + G()->td_db()->get_sqlite_pmc()->set(get_poll_database_key(poll_id), log_event_store(*poll).as_slice().str(), Auto()); } void PollManager::on_load_poll_from_database(PollId poll_id, string value) { @@ -161,6 +174,7 @@ void PollManager::close_poll(PollId poll_id) { } poll->is_closed = true; + notify_on_poll_update(poll_id); if (!is_local_poll_id(poll_id)) { // TODO send poll close request to the server + LogEvent save_poll(poll, poll_id); @@ -270,6 +284,7 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptr