Create file sources for channel and chat photos.

GitOrigin-RevId: c3660edd78b7ad07aaa7e6c5e238c2e2e30f2b11
This commit is contained in:
levlam 2019-01-20 06:34:47 +03:00
parent 730466e328
commit 937db792cb
5 changed files with 47 additions and 1 deletions

View File

@ -12,6 +12,7 @@
#include "td/telegram/AuthManager.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/FileReferenceManager.h"
#include "td/telegram/files/FileManager.h"
#include "td/telegram/files/FileType.h"
#include "td/telegram/Global.h"
@ -6248,6 +6249,15 @@ void ContactsManager::update_user(User *u, UserId user_id, bool from_binlog, boo
void ContactsManager::update_chat(Chat *c, ChatId chat_id, bool from_binlog, bool from_database) {
CHECK(c != nullptr);
if (c->is_photo_changed) {
auto file_ids = dialog_photo_get_file_ids(c->photo);
if (!file_ids.empty()) {
if (!c->photo_source_id.is_valid()) {
c->photo_source_id = td_->file_reference_manager_->create_chat_photo_file_source(chat_id);
}
for (auto file_id : file_ids) {
td_->file_manager_->add_file_source(file_id, c->photo_source_id);
}
}
td_->messages_manager_->on_dialog_photo_updated(DialogId(chat_id));
}
if (c->is_title_changed) {
@ -6278,6 +6288,15 @@ void ContactsManager::update_chat(Chat *c, ChatId chat_id, bool from_binlog, boo
void ContactsManager::update_channel(Channel *c, ChannelId channel_id, bool from_binlog, bool from_database) {
CHECK(c != nullptr);
if (c->is_photo_changed) {
auto file_ids = dialog_photo_get_file_ids(c->photo);
if (!file_ids.empty()) {
if (!c->photo_source_id.is_valid()) {
c->photo_source_id = td_->file_reference_manager_->create_channel_photo_file_source(channel_id);
}
for (auto file_id : file_ids) {
td_->file_manager_->add_file_source(file_id, c->photo_source_id);
}
}
td_->messages_manager_->on_dialog_photo_updated(DialogId(channel_id));
}
if (c->is_title_changed) {
@ -7926,6 +7945,11 @@ void ContactsManager::on_update_chat_photo(Chat *c, ChatId chat_id,
DialogPhoto new_chat_photo = get_dialog_photo(td_->file_manager_.get(), std::move(chat_photo_ptr));
if (new_chat_photo != c->photo) {
if (c->photo_source_id.is_valid()) {
for (auto file_id : dialog_photo_get_file_ids(c->photo)) {
td_->file_manager_->remove_file_source(file_id, c->photo_source_id);
}
}
c->photo = new_chat_photo;
c->is_photo_changed = true;
c->is_changed = true;
@ -8027,6 +8051,11 @@ void ContactsManager::on_update_channel_photo(Channel *c, ChannelId channel_id,
DialogPhoto new_chat_photo = get_dialog_photo(td_->file_manager_.get(), std::move(chat_photo_ptr));
if (new_chat_photo != c->photo) {
if (c->photo_source_id.is_valid()) {
for (auto file_id : dialog_photo_get_file_ids(c->photo)) {
td_->file_manager_->remove_file_source(file_id, c->photo_source_id);
}
}
c->photo = new_chat_photo;
c->is_photo_changed = true;
c->is_changed = true;

View File

@ -16,6 +16,7 @@
#include "td/telegram/DialogId.h"
#include "td/telegram/DialogParticipant.h"
#include "td/telegram/files/FileId.h"
#include "td/telegram/files/FileSourceId.h"
#include "td/telegram/MessageId.h"
#include "td/telegram/Photo.h"
#include "td/telegram/SecretChatId.h"
@ -553,6 +554,7 @@ class ContactsManager : public Actor {
struct Chat {
string title;
DialogPhoto photo;
FileSourceId photo_source_id;
int32 participant_count = 0;
int32 date = 0;
int32 version = -1;
@ -598,6 +600,7 @@ class ContactsManager : public Actor {
int64 access_hash = 0;
string title;
DialogPhoto photo;
FileSourceId photo_source_id;
string username;
string restriction_reason;
DialogParticipantStatus status = DialogParticipantStatus::Banned(0);

View File

@ -95,9 +95,10 @@ void FileReferenceManager::remove_file_source(NodeId node_id, FileSourceId file_
}
void FileReferenceManager::merge(NodeId to_node_id, NodeId from_node_id) {
VLOG(file_references) << "Merge sources of files " << to_node_id << " and " << from_node_id;
auto &to = nodes_[to_node_id];
auto &from = nodes_[from_node_id];
VLOG(file_references) << "Merge " << to.file_source_ids.size() << " and " << from.file_source_ids.size()
<< " sources of files " << to_node_id << " and " << from_node_id;
CHECK(!to.query || to.query->proxy.empty());
CHECK(!from.query || from.query->proxy.empty());
if (to.query || from.query) {

View File

@ -203,6 +203,17 @@ tl_object_ptr<td_api::chatPhoto> get_chat_photo_object(FileManager *file_manager
file_manager->get_file_object(dialog_photo->big_file_id));
}
vector<FileId> dialog_photo_get_file_ids(const DialogPhoto &dialog_photo) {
vector<FileId> result;
if (dialog_photo.small_file_id.is_valid()) {
result.push_back(dialog_photo.small_file_id);
}
if (dialog_photo.big_file_id.is_valid()) {
result.push_back(dialog_photo.big_file_id);
}
return result;
}
bool operator==(const DialogPhoto &lhs, const DialogPhoto &rhs) {
return lhs.small_file_id == rhs.small_file_id && lhs.big_file_id == rhs.big_file_id;
}

View File

@ -73,6 +73,8 @@ StringBuilder &operator<<(StringBuilder &string_builder, const ProfilePhoto &pro
DialogPhoto get_dialog_photo(FileManager *file_manager, tl_object_ptr<telegram_api::ChatPhoto> &&chat_photo_ptr);
tl_object_ptr<td_api::chatPhoto> get_chat_photo_object(FileManager *file_manager, const DialogPhoto *dialog_photo);
vector<FileId> dialog_photo_get_file_ids(const DialogPhoto &dialog_photo);
bool operator==(const DialogPhoto &lhs, const DialogPhoto &rhs);
bool operator!=(const DialogPhoto &lhs, const DialogPhoto &rhs);