Remove file reference tracing for chat photos.
GitOrigin-RevId: 1cb90efec24192b5a712cabde325c8768e1af572
This commit is contained in:
parent
ed333a67c7
commit
2ad13e414e
@ -8462,9 +8462,6 @@ void ContactsManager::update_user(User *u, UserId user_id, bool from_binlog, boo
|
||||
[messages_manager = td_->messages_manager_.get()](SecretChatId secret_chat_id) {
|
||||
messages_manager->on_dialog_photo_updated(DialogId(secret_chat_id));
|
||||
});
|
||||
|
||||
add_user_photo_id(u, user_id, u->photo.id, dialog_photo_get_file_ids(u->photo));
|
||||
|
||||
drop_user_photos(user_id, u->photo.id <= 0, true, "update_user");
|
||||
}
|
||||
if (u->is_status_changed && user_id != get_my_id()) {
|
||||
@ -8543,15 +8540,6 @@ 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) {
|
||||
@ -8599,15 +8587,6 @@ 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) {
|
||||
@ -9132,6 +9111,7 @@ void ContactsManager::on_get_chat_full(tl_object_ptr<telegram_api::ChatFull> &&c
|
||||
on_update_chat_full_invite_link(chat, std::move(chat_full->exported_invite_));
|
||||
|
||||
// Ignoring chat_full->photo
|
||||
// If not ignored, file reference needs to be repaired with getChatFull
|
||||
|
||||
for (auto &bot_info : chat_full->bot_info_) {
|
||||
if (on_update_bot_info(std::move(bot_info))) {
|
||||
@ -9184,6 +9164,7 @@ void ContactsManager::on_get_chat_full(tl_object_ptr<telegram_api::ChatFull> &&c
|
||||
DialogId(channel_id), std::move(channel_full->notify_settings_), "on_get_channel_full");
|
||||
|
||||
// Ignoring channel_full->photo
|
||||
// If not ignored, file reference needs to be repaired with getChannelFull
|
||||
|
||||
auto c = get_channel(channel_id);
|
||||
if (c == nullptr) {
|
||||
@ -11251,11 +11232,6 @@ void ContactsManager::on_update_chat_photo(Chat *c, ChatId chat_id,
|
||||
get_dialog_photo(td_->file_manager_.get(), DialogId(chat_id), 0, 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->need_save_to_database = true;
|
||||
@ -11380,11 +11356,6 @@ void ContactsManager::on_update_channel_photo(Channel *c, ChannelId channel_id,
|
||||
get_dialog_photo(td_->file_manager_.get(), DialogId(channel_id), c->access_hash, 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->need_save_to_database = true;
|
||||
@ -12049,12 +12020,6 @@ ContactsManager::Chat *ContactsManager::add_chat(ChatId chat_id) {
|
||||
auto &chat_ptr = chats_[chat_id];
|
||||
if (chat_ptr == nullptr) {
|
||||
chat_ptr = make_unique<Chat>();
|
||||
auto it = chat_photo_file_source_ids_.find(chat_id);
|
||||
if (it != chat_photo_file_source_ids_.end()) {
|
||||
VLOG(file_references) << "Move " << it->second << " inside of " << chat_id;
|
||||
chat_ptr->photo_source_id = it->second;
|
||||
chat_photo_file_source_ids_.erase(it);
|
||||
}
|
||||
}
|
||||
return chat_ptr.get();
|
||||
}
|
||||
@ -12231,15 +12196,6 @@ bool ContactsManager::is_appointed_chat_administrator(ChatId chat_id) const {
|
||||
return c->status.is_administrator();
|
||||
}
|
||||
|
||||
FileSourceId ContactsManager::get_chat_photo_file_source_id(ChatId chat_id) {
|
||||
auto c = get_chat(chat_id);
|
||||
auto &source_id = c == nullptr ? chat_photo_file_source_ids_[chat_id] : c->photo_source_id;
|
||||
if (!source_id.is_valid()) {
|
||||
source_id = td_->file_reference_manager_->create_chat_photo_file_source(chat_id);
|
||||
}
|
||||
return source_id;
|
||||
}
|
||||
|
||||
bool ContactsManager::is_channel_public(ChannelId channel_id) const {
|
||||
return is_channel_public(get_channel(channel_id));
|
||||
}
|
||||
@ -12321,15 +12277,6 @@ bool ContactsManager::get_channel_sign_messages(const Channel *c) {
|
||||
return c->sign_messages;
|
||||
}
|
||||
|
||||
FileSourceId ContactsManager::get_channel_photo_file_source_id(ChannelId channel_id) {
|
||||
auto c = get_channel(channel_id);
|
||||
auto &source_id = c == nullptr ? channel_photo_file_source_ids_[channel_id] : c->photo_source_id;
|
||||
if (!source_id.is_valid()) {
|
||||
source_id = td_->file_reference_manager_->create_channel_photo_file_source(channel_id);
|
||||
}
|
||||
return source_id;
|
||||
}
|
||||
|
||||
int32 ContactsManager::get_channel_slow_mode_delay(ChannelId channel_id) {
|
||||
auto channel_full = get_channel_full_force(channel_id, ":get_channel_slow_mode_delay");
|
||||
if (channel_full == nullptr) {
|
||||
@ -12369,12 +12316,6 @@ ContactsManager::Channel *ContactsManager::add_channel(ChannelId channel_id, con
|
||||
auto &channel_ptr = channels_[channel_id];
|
||||
if (channel_ptr == nullptr) {
|
||||
channel_ptr = make_unique<Channel>();
|
||||
auto it = channel_photo_file_source_ids_.find(channel_id);
|
||||
if (it != channel_photo_file_source_ids_.end()) {
|
||||
VLOG(file_references) << "Move " << it->second << " inside of " << channel_id;
|
||||
channel_ptr->photo_source_id = it->second;
|
||||
channel_photo_file_source_ids_.erase(it);
|
||||
}
|
||||
}
|
||||
return channel_ptr.get();
|
||||
}
|
||||
|
@ -451,7 +451,6 @@ class ContactsManager : public Actor {
|
||||
DialogParticipantStatus get_chat_status(ChatId chat_id) const;
|
||||
DialogParticipantStatus get_chat_permissions(ChatId chat_id) const;
|
||||
bool is_appointed_chat_administrator(ChatId chat_id) const;
|
||||
FileSourceId get_chat_photo_file_source_id(ChatId chat_id);
|
||||
|
||||
bool have_channel(ChannelId channel_id) const;
|
||||
bool have_min_channel(ChannelId channel_id) const;
|
||||
@ -473,7 +472,6 @@ class ContactsManager : public Actor {
|
||||
DialogParticipantStatus get_channel_permissions(ChannelId channel_id) const;
|
||||
int32 get_channel_participant_count(ChannelId channel_id) const;
|
||||
bool get_channel_sign_messages(ChannelId channel_id) const;
|
||||
FileSourceId get_channel_photo_file_source_id(ChannelId channel_id);
|
||||
int32 get_channel_slow_mode_delay(ChannelId channel_id);
|
||||
|
||||
std::pair<int32, vector<UserId>> search_among_users(const vector<UserId> &user_ids, const string &query, int32 limit);
|
||||
@ -678,7 +676,6 @@ class ContactsManager : public Actor {
|
||||
struct Chat {
|
||||
string title;
|
||||
DialogPhoto photo;
|
||||
FileSourceId photo_source_id;
|
||||
int32 participant_count = 0;
|
||||
int32 date = 0;
|
||||
int32 version = -1;
|
||||
@ -743,7 +740,6 @@ class ContactsManager : public Actor {
|
||||
int64 access_hash = 0;
|
||||
string title;
|
||||
DialogPhoto photo;
|
||||
FileSourceId photo_source_id;
|
||||
string username;
|
||||
vector<RestrictionReason> restriction_reasons;
|
||||
DialogParticipantStatus status = DialogParticipantStatus::Banned(0);
|
||||
@ -1409,13 +1405,11 @@ class ContactsManager : public Actor {
|
||||
std::unordered_map<ChatId, unique_ptr<Chat>, ChatIdHash> chats_;
|
||||
std::unordered_map<ChatId, unique_ptr<ChatFull>, ChatIdHash> chats_full_;
|
||||
mutable std::unordered_set<ChatId, ChatIdHash> unknown_chats_;
|
||||
std::unordered_map<ChatId, FileSourceId, ChatIdHash> chat_photo_file_source_ids_;
|
||||
|
||||
std::unordered_set<ChannelId, ChannelIdHash> min_channels_;
|
||||
std::unordered_map<ChannelId, unique_ptr<Channel>, ChannelIdHash> channels_;
|
||||
std::unordered_map<ChannelId, unique_ptr<ChannelFull>, ChannelIdHash> channels_full_;
|
||||
mutable std::unordered_set<ChannelId, ChannelIdHash> unknown_channels_;
|
||||
std::unordered_map<ChannelId, FileSourceId, ChannelIdHash> channel_photo_file_source_ids_;
|
||||
|
||||
std::unordered_map<SecretChatId, unique_ptr<SecretChat>, SecretChatIdHash> secret_chats_;
|
||||
mutable std::unordered_set<SecretChatId, SecretChatIdHash> unknown_secret_chats_;
|
||||
|
@ -45,7 +45,7 @@ size_t FileReferenceManager::get_file_reference_error_pos(const Status &error) {
|
||||
fileSourceMessage chat_id:int53 message_id:int53 = FileSource; // repaired with get_message_from_server
|
||||
fileSourceUserProfilePhoto user_id:int32 photo_id:int64 = FileSource; // repaired with photos.getUserPhotos
|
||||
fileSourceBasicGroupPhoto basic_group_id:int32 = FileSource; // repaired with messages.getChats
|
||||
fileSourceSupergroupPhoto supergroup_id:int32 = FileSource; // repaired with channels.getChannels
|
||||
fileSourceSupergroupPhoto supergroup_id:int32 = FileSource; // no need to repair
|
||||
fileSourceWebPage url:string = FileSource; // repaired with messages.getWebPage
|
||||
fileSourceWallpapers = FileSource; // can't be repaired
|
||||
fileSourceSavedAnimations = FileSource; // repaired with messages.getSavedGifs
|
||||
@ -75,16 +75,6 @@ FileSourceId FileReferenceManager::create_user_photo_file_source(UserId user_id,
|
||||
return add_file_source_id(source, PSLICE() << "photo " << photo_id << " of " << user_id);
|
||||
}
|
||||
|
||||
FileSourceId FileReferenceManager::create_chat_photo_file_source(ChatId chat_id) {
|
||||
FileSourceChatPhoto source{chat_id};
|
||||
return add_file_source_id(source, PSLICE() << "photo of " << chat_id);
|
||||
}
|
||||
|
||||
FileSourceId FileReferenceManager::create_channel_photo_file_source(ChannelId channel_id) {
|
||||
FileSourceChannelPhoto source{channel_id};
|
||||
return add_file_source_id(source, PSLICE() << "photo of " << channel_id);
|
||||
}
|
||||
|
||||
FileSourceId FileReferenceManager::create_web_page_file_source(string url) {
|
||||
FileSourceWebPage source{std::move(url)};
|
||||
auto source_str = PSTRING() << "web page of " << source.url;
|
||||
|
@ -40,8 +40,9 @@ class FileReferenceManager : public Actor {
|
||||
|
||||
FileSourceId create_message_file_source(FullMessageId full_message_id);
|
||||
FileSourceId create_user_photo_file_source(UserId user_id, int64 photo_id);
|
||||
FileSourceId create_chat_photo_file_source(ChatId chat_id);
|
||||
FileSourceId create_channel_photo_file_source(ChannelId channel_id);
|
||||
// file reference aren't used for chat/channel photo download and the photos can't be reused
|
||||
// FileSourceId create_chat_photo_file_source(ChatId chat_id);
|
||||
// FileSourceId create_channel_photo_file_source(ChannelId channel_id);
|
||||
// FileSourceId create_wallpapers_file_source(); old wallpapers can't be repaired
|
||||
FileSourceId create_web_page_file_source(string url);
|
||||
FileSourceId create_saved_animations_file_source();
|
||||
|
@ -69,12 +69,12 @@ FileSourceId FileReferenceManager::parse_file_source(Td *td, ParserT &parser) {
|
||||
case 2: {
|
||||
ChatId chat_id;
|
||||
td::parse(chat_id, parser);
|
||||
return td->contacts_manager_->get_chat_photo_file_source_id(chat_id);
|
||||
return FileSourceId(); // there is no need to repair chat photos
|
||||
}
|
||||
case 3: {
|
||||
ChannelId channel_id;
|
||||
td::parse(channel_id, parser);
|
||||
return td->contacts_manager_->get_channel_photo_file_source_id(channel_id);
|
||||
return FileSourceId(); // there is no need to repair channel photos
|
||||
}
|
||||
case 4:
|
||||
return FileSourceId(); // there is no way to repair old wallpapers
|
||||
|
Loading…
Reference in New Issue
Block a user