Fix addind/removing file source for messages.

GitOrigin-RevId: 726e2671dee6368bce20bac207b8d3929b1a34f6
This commit is contained in:
levlam 2019-01-03 18:26:44 +03:00
parent b53cd5d76a
commit cc5eaa6b7e
8 changed files with 66 additions and 32 deletions

View File

@ -36,8 +36,8 @@ class ConfigManager;
class ConfigShared;
class ConnectionCreator;
class ContactsManager;
class FileReferenceManager;
class FileManager;
class FileReferenceManager;
class LanguagePackManager;
class MessagesManager;
class MtprotoHeader;
@ -173,13 +173,6 @@ class Global : public ActorContext {
contacts_manager_ = contacts_manager;
}
ActorId<FileReferenceManager> file_reference_manager() const {
return file_reference_manager_;
}
void set_file_reference_manager(ActorId<FileReferenceManager> file_reference_manager) {
file_reference_manager_ = std::move(file_reference_manager);
}
ActorId<FileManager> file_manager() const {
return file_manager_;
}
@ -187,6 +180,13 @@ class Global : public ActorContext {
file_manager_ = std::move(file_manager);
}
ActorId<FileReferenceManager> file_reference_manager() const {
return file_reference_manager_;
}
void set_file_reference_manager(ActorId<FileReferenceManager> file_reference_manager) {
file_reference_manager_ = std::move(file_reference_manager);
}
ActorId<LanguagePackManager> language_pack_manager() const {
return language_pack_manager_;
}
@ -356,8 +356,8 @@ class Global : public ActorContext {
ActorId<CallManager> call_manager_;
ActorId<ConfigManager> config_manager_;
ActorId<ContactsManager> contacts_manager_;
ActorId<FileReferenceManager> file_reference_manager_;
ActorId<FileManager> file_manager_;
ActorId<FileReferenceManager> file_reference_manager_;
ActorId<LanguagePackManager> language_pack_manager_;
ActorId<MessagesManager> messages_manager_;
ActorId<NotificationManager> notification_manager_;

View File

@ -3159,7 +3159,7 @@ static auto secret_to_telegram(secret_api::fileLocationUnavailable &file_locatio
static auto secret_to_telegram(secret_api::fileLocation &file_location) {
return make_tl_object<telegram_api::fileLocation>(file_location.dc_id_, file_location.volume_id_,
file_location.local_id_, file_location.secret_,
BufferSlice() /*FIXME*/);
BufferSlice());
}
// photoSizeEmpty#e17e23c type:string = PhotoSize;
@ -3308,7 +3308,7 @@ static auto secret_to_telegram_document(secret_api::decryptedMessageMediaExterna
from.mime_type_.clear();
}
return make_tl_object<telegram_api::document>(
from.id_, from.access_hash_, BufferSlice() /*FIXME*/, from.date_, from.mime_type_, from.size_,
from.id_, from.access_hash_, BufferSlice(), from.date_, from.mime_type_, from.size_,
secret_to_telegram<telegram_api::PhotoSize>(*from.thumb_), from.dc_id_, secret_to_telegram(from.attributes_));
}

View File

@ -10627,6 +10627,7 @@ unique_ptr<MessagesManager::Message> MessagesManager::do_delete_message(Dialog *
delete_message_from_database(d, message_id, m, is_permanently_deleted);
delete_active_live_location(d->dialog_id, m);
remove_message_file_sources(d->dialog_id, m);
if (message_id == d->last_message_id) {
MessagesConstIterator it(d, message_id);
@ -10838,6 +10839,7 @@ void MessagesManager::do_delete_all_dialog_messages(Dialog *d, unique_ptr<Messag
do_delete_all_dialog_messages(d, m->left, deleted_message_ids);
delete_active_live_location(d->dialog_id, m.get());
remove_message_file_sources(d->dialog_id, m.get());
if (message_id.is_yet_unsent()) {
cancel_send_message_query(d->dialog_id, m);
@ -13695,6 +13697,38 @@ void MessagesManager::save_active_live_locations() {
}
}
void MessagesManager::add_message_file_sources(DialogId dialog_id, const Message *m) {
if (dialog_id.get_type() == DialogType::SecretChat || !m->message_id.is_server()) {
return;
}
auto file_ids = get_message_content_file_ids(m->content.get(), td_);
if (file_ids.empty()) {
return;
}
auto file_source_id = td_->file_reference_manager_->create_file_source(FullMessageId(dialog_id, m->message_id));
for (auto file_id : file_ids) {
td_->file_manager_->add_file_source(file_id, file_source_id);
}
}
void MessagesManager::remove_message_file_sources(DialogId dialog_id, const Message *m) {
if (dialog_id.get_type() == DialogType::SecretChat || !m->message_id.is_server()) {
return;
}
auto file_ids = get_message_content_file_ids(m->content.get(), td_);
if (file_ids.empty()) {
return;
}
auto file_source_id = td_->file_reference_manager_->create_file_source(FullMessageId(dialog_id, m->message_id));
for (auto file_id : file_ids) {
td_->file_manager_->remove_file_source(file_id, file_source_id);
}
}
MessageId MessagesManager::get_first_database_message_id_by_index(const Dialog *d, SearchMessagesFilter filter) {
CHECK(d != nullptr);
auto message_id = filter == SearchMessagesFilter::Empty
@ -20971,16 +21005,6 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
cancel_user_dialog_action(dialog_id, message.get());
}
if (message_id.is_server()) {
auto file_ids = get_message_content_file_ids(message->content.get(), td_);
if (!file_ids.empty()) {
auto file_source_id = td_->file_reference_manager_->create_file_source(FullMessageId(dialog_id, message_id));
for (auto file_id : file_ids) {
td_->file_manager_->add_file_source(file_id, file_source_id);
}
}
}
{
unique_ptr<Message> *v = find_message(&d->messages, message_id);
if (*v == nullptr && !message->from_database) {
@ -21014,11 +21038,13 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
const int32 INDEX_MASK_MASK = ~search_messages_filter_index_mask(SearchMessagesFilter::UnreadMention);
auto old_index_mask = get_message_index_mask(dialog_id, v->get()) & INDEX_MASK_MASK;
bool was_deleted = delete_active_live_location(dialog_id, v->get());
remove_message_file_sources(dialog_id, v->get());
update_message(d, *v, std::move(message), true, need_update_dialog_pos);
auto new_index_mask = get_message_index_mask(dialog_id, v->get()) & INDEX_MASK_MASK;
if (was_deleted) {
try_add_active_live_location(dialog_id, v->get());
}
add_message_file_sources(dialog_id, v->get());
if (old_index_mask != new_index_mask) {
update_message_count_by_index(d, -1, old_index_mask & ~new_index_mask);
update_message_count_by_index(d, +1, new_index_mask & ~old_index_mask);
@ -21346,6 +21372,8 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
get_messages_from_server({full_message_id}, Auto());
}
add_message_file_sources(dialog_id, m);
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());
if (new_participant_count != 0) {

View File

@ -1841,6 +1841,10 @@ class MessagesManager : public Actor {
void save_active_live_locations();
void add_message_file_sources(DialogId dialog_id, const Message *m);
void remove_message_file_sources(DialogId dialog_id, const Message *m);
Result<unique_ptr<ReplyMarkup>> get_dialog_reply_markup(
DialogId dialog_id, tl_object_ptr<td_api::ReplyMarkup> &&reply_markup_ptr) const TD_WARN_UNUSED_RESULT;

View File

@ -3633,10 +3633,10 @@ void Td::dec_actor_refcnt() {
LOG(DEBUG) << "ContactsManager was cleared " << timer;
documents_manager_.reset();
LOG(DEBUG) << "DocumentsManager was cleared " << timer;
file_reference_manager_.reset();
LOG(DEBUG) << "FileReferenceManager was cleared " << timer;
file_manager_.reset();
LOG(DEBUG) << "FileManager was cleared " << timer;
file_reference_manager_.reset();
LOG(DEBUG) << "FileReferenceManager was cleared " << timer;
inline_queries_manager_.reset();
LOG(DEBUG) << "InlineQueriesManager was cleared " << timer;
messages_manager_.reset();
@ -3808,10 +3808,10 @@ void Td::clear() {
LOG(DEBUG) << "AuthManager actor was cleared " << timer;
contacts_manager_actor_.reset();
LOG(DEBUG) << "ContactsManager actor was cleared " << timer;
file_reference_manager_actor_.reset();
LOG(DEBUG) << "FileReferenceManager actor was cleared " << timer;
file_manager_actor_.reset();
LOG(DEBUG) << "FileManager actor was cleared " << timer;
file_reference_manager_actor_.reset();
LOG(DEBUG) << "FileReferenceManager actor was cleared " << timer;
inline_queries_manager_actor_.reset();
LOG(DEBUG) << "InlineQueriesManager actor was cleared " << timer;
messages_manager_actor_.reset(); // TODO: Stop silent
@ -4087,15 +4087,16 @@ Status Td::init(DbKey key) {
private:
Td *td_;
};
file_reference_manager_ = make_unique<FileReferenceManager>();
file_reference_manager_actor_ = register_actor("FileReferenceManager", file_reference_manager_.get());
G()->set_file_reference_manager(file_reference_manager_actor_.get());
file_manager_ = make_unique<FileManager>(make_unique<FileManagerContext>(this));
file_manager_actor_ = register_actor("FileManager", file_manager_.get());
file_manager_->init_actor();
G()->set_file_manager(file_manager_actor_.get());
file_reference_manager_ = make_unique<FileReferenceManager>();
file_reference_manager_actor_ = register_actor("FileReferenceManager", file_reference_manager_.get());
G()->set_file_reference_manager(file_reference_manager_actor_.get());
VLOG(td_init) << "Create Managers";
audios_manager_ = make_unique<AudiosManager>(this);
callback_queries_manager_ = make_unique<CallbackQueriesManager>(this);

View File

@ -44,8 +44,8 @@ class ConfigManager;
class ContactsManager;
class DeviceTokenManager;
class DocumentsManager;
class FileReferenceManager;
class FileManager;
class FileReferenceManager;
class InlineQueriesManager;
class HashtagHints;
class LanguagePackManager;
@ -139,10 +139,10 @@ class Td final : public NetQueryCallback {
ActorOwn<AuthManager> auth_manager_actor_;
unique_ptr<ContactsManager> contacts_manager_;
ActorOwn<ContactsManager> contacts_manager_actor_;
unique_ptr<FileReferenceManager> file_reference_manager_;
ActorOwn<FileReferenceManager> file_reference_manager_actor_;
unique_ptr<FileManager> file_manager_;
ActorOwn<FileManager> file_manager_actor_;
unique_ptr<FileReferenceManager> file_reference_manager_;
ActorOwn<FileReferenceManager> file_reference_manager_actor_;
unique_ptr<InlineQueriesManager> inline_queries_manager_;
ActorOwn<InlineQueriesManager> inline_queries_manager_actor_;
unique_ptr<MessagesManager> messages_manager_;

View File

@ -607,6 +607,7 @@ void FileManager::init_actor() {
file_generate_manager_ = create_actor_on_scheduler<FileGenerateManager>(
"FileGenerateManager", G()->get_slow_net_scheduler_id(), context_->create_reference());
}
FileManager::~FileManager() {
}