Register polls.

GitOrigin-RevId: 812e3e699a578effab96c4d798d5b74ddf635371
This commit is contained in:
levlam 2019-02-19 18:42:59 +03:00
parent 95f7b129c8
commit 839c1856ff
5 changed files with 51 additions and 2 deletions

View File

@ -3269,6 +3269,24 @@ bool merge_message_content_file_id(Td *td, MessageContent *message_content, File
return false;
}
void register_message_content(Td *td, const MessageContent *content, FullMessageId full_message_id) {
switch (content->get_type()) {
case MessageContentType::Poll:
return td->poll_manager_->register_poll(static_cast<const MessagePoll *>(content)->poll_id, full_message_id);
default:
return;
}
}
void unregister_message_content(Td *td, const MessageContent *content, FullMessageId full_message_id) {
switch (content->get_type()) {
case MessageContentType::Poll:
return td->poll_manager_->unregister_poll(static_cast<const MessagePoll *>(content)->poll_id, full_message_id);
default:
return;
}
}
static FormattedText get_secret_media_caption(string &&message_text, string &&message_caption) {
FormattedText caption;
if (message_text.empty()) {

View File

@ -185,6 +185,10 @@ void merge_message_contents(Td *td, MessageContent *old_content, MessageContent
bool merge_message_content_file_id(Td *td, MessageContent *message_content, FileId new_file_id);
void register_message_content(Td *td, const MessageContent *content, FullMessageId full_message_id);
void unregister_message_content(Td *td, const MessageContent *content, FullMessageId full_message_id);
unique_ptr<MessageContent> get_secret_message_content(
Td *td, string message_text, tl_object_ptr<telegram_api::encryptedFile> file,
tl_object_ptr<secret_api::DecryptedMessageMedia> &&media,

View File

@ -8630,8 +8630,10 @@ void MessagesManager::on_message_ttl_expired(Dialog *d, Message *m) {
CHECK(m->ttl > 0);
CHECK(d->dialog_id.get_type() != DialogType::SecretChat);
ttl_unregister_message(d->dialog_id, m, Time::now(), "on_message_ttl_expired");
unregister_message_content(td_, m->content.get(), {d->dialog_id, m->message_id});
remove_message_file_sources(d->dialog_id, m);
on_message_ttl_expired_impl(d, m);
register_message_content(td_, m->content.get(), {d->dialog_id, m->message_id});
send_update_message_content(d->dialog_id, m->message_id, m->content.get(), m->date, m->is_content_secret,
"on_message_ttl_expired");
}
@ -10056,8 +10058,9 @@ void MessagesManager::on_update_sent_text_message(int64 random_id,
return;
}
auto dialog_id = it->second.get_dialog_id();
auto m = get_message_force(it->second);
auto full_message_id = it->second;
auto dialog_id = full_message_id.get_dialog_id();
auto m = get_message_force(full_message_id);
if (m == nullptr) {
// message has already been deleted
return;
@ -10080,6 +10083,8 @@ void MessagesManager::on_update_sent_text_message(int64 random_id,
return;
}
unregister_message_content(td_, m->content.get(), full_message_id);
bool need_update = false;
bool is_content_changed = false;
merge_message_contents(td_, m->content.get(), new_content.get(), need_message_changed_warning(m), dialog_id, false,
@ -10089,6 +10094,7 @@ void MessagesManager::on_update_sent_text_message(int64 random_id,
m->content = std::move(new_content);
m->is_content_secret = is_secret_message_content(m->ttl, MessageContentType::Text);
}
register_message_content(td_, m->content.get(), full_message_id);
if (need_update) {
send_update_message_content(dialog_id, m->message_id, m->content.get(), m->date, m->is_content_secret,
"on_update_sent_text_message");
@ -10925,6 +10931,7 @@ void MessagesManager::on_message_deleted(Dialog *d, Message *m) {
UNREACHABLE();
}
ttl_unregister_message(d->dialog_id, m, Time::now(), "on_message_deleted");
unregister_message_content(td_, m->content.get(), {d->dialog_id, m->message_id});
if (m->notification_id.is_valid()) {
delete_notification_id_to_message_id_correspondence(d, m->notification_id, m->message_id);
}
@ -21772,6 +21779,7 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
}
add_message_file_sources(dialog_id, m);
register_message_content(td_, m->content.get(), {dialog_id, message_id});
if (from_update && message_id.is_server() && dialog_id.get_type() == DialogType::Channel) {
int32 new_participant_count = get_message_content_new_participant_count(m->content.get());
@ -22461,7 +22469,9 @@ bool MessagesManager::update_message_content(DialogId dialog_id, Message *old_me
}
if (is_content_changed || need_update) {
unregister_message_content(td_, old_content.get(), {dialog_id, old_message->message_id});
old_content = std::move(new_content);
register_message_content(td_, old_content.get(), {dialog_id, old_message->message_id});
update_message_content_file_id_remote(old_content.get(), old_file_id);
} else {
update_message_content_file_id_remote(old_content.get(), get_message_content_file_id(new_content.get()));

View File

@ -143,6 +143,16 @@ PollId PollManager::create_poll(string &&question, vector<string> &&answers) {
return poll_id;
}
void PollManager::register_poll(PollId poll_id, FullMessageId full_message_id) {
CHECK(have_poll(poll_id));
poll_messages_[poll_id].insert(full_message_id);
}
void PollManager::unregister_poll(PollId poll_id, FullMessageId full_message_id) {
CHECK(have_poll(poll_id));
poll_messages_[poll_id].erase(full_message_id);
}
void PollManager::close_poll(PollId poll_id) {
auto poll = get_poll_editable(poll_id);
CHECK(poll != nullptr);

View File

@ -6,6 +6,7 @@
//
#pragma once
#include "td/telegram/MessageId.h"
#include "td/telegram/PollId.h"
#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
@ -34,6 +35,10 @@ class PollManager : public Actor {
PollId create_poll(string &&question, vector<string> &&answers);
void register_poll(PollId poll_id, FullMessageId full_message_id);
void unregister_poll(PollId poll_id, FullMessageId full_message_id);
void close_poll(PollId poll_id);
tl_object_ptr<telegram_api::InputMedia> get_input_media(PollId poll_id) const;
@ -104,6 +109,8 @@ class PollManager : public Actor {
ActorShared<> parent_;
std::unordered_map<PollId, unique_ptr<Poll>, PollIdHash> polls_;
std::unordered_map<PollId, std::unordered_set<FullMessageId, FullMessageIdHash>, PollIdHash> poll_messages_;
int64 current_local_poll_id_ = 0;
std::unordered_set<PollId, PollIdHash> loaded_from_database_polls_;