Update chat/channel photo whenever receive new full chat/channel photo.

This commit is contained in:
levlam 2022-04-28 20:35:44 +03:00
parent b6f711044f
commit d106148618
2 changed files with 36 additions and 28 deletions

View File

@ -9805,9 +9805,11 @@ void ContactsManager::on_load_chat_full_from_database(ChatId chat_id, string val
} }
} }
td_->group_call_manager_->on_update_dialog_about(DialogId(chat_id), chat_full->description, false); auto photo = std::move(chat_full->photo);
chat_full->photo = Photo();
on_update_chat_full_photo(chat_full, chat_id, std::move(photo));
on_update_chat_full_photo(chat_full, chat_id, std::move(chat_full->photo)); td_->group_call_manager_->on_update_dialog_about(DialogId(chat_id), chat_full->description, false);
chat_full->is_update_chat_full_sent = true; chat_full->is_update_chat_full_sent = true;
update_chat_full(chat_full, chat_id, "on_load_chat_full_from_database", true); update_chat_full(chat_full, chat_id, "on_load_chat_full_from_database", true);
@ -9916,6 +9918,7 @@ void ContactsManager::on_load_channel_full_from_database(ChannelId channel_id, s
} }
} }
auto photo = std::move(channel_full->photo); auto photo = std::move(channel_full->photo);
channel_full->photo = Photo();
on_update_channel_full_photo(channel_full, channel_id, std::move(photo)); on_update_channel_full_photo(channel_full, channel_id, std::move(photo));
if (channel_full->participant_count < channel_full->administrator_count) { if (channel_full->participant_count < channel_full->administrator_count) {
@ -10741,16 +10744,17 @@ void ContactsManager::on_get_chat_full(tl_object_ptr<telegram_api::ChatFull> &&c
return promise.set_value(Unit()); return promise.set_value(Unit());
} }
Chat *c = get_chat(chat_id);
if (c == nullptr) {
LOG(ERROR) << "Can't find " << chat_id;
return promise.set_value(Unit());
}
{ {
MessageId pinned_message_id; MessageId pinned_message_id;
if ((chat->flags_ & CHAT_FULL_FLAG_HAS_PINNED_MESSAGE) != 0) { if ((chat->flags_ & CHAT_FULL_FLAG_HAS_PINNED_MESSAGE) != 0) {
pinned_message_id = MessageId(ServerMessageId(chat->pinned_msg_id_)); pinned_message_id = MessageId(ServerMessageId(chat->pinned_msg_id_));
} }
Chat *c = get_chat(chat_id); if (c->version >= c->pinned_message_version) {
if (c == nullptr) {
LOG(ERROR) << "Can't find " << chat_id;
return promise.set_value(Unit());
} else if (c->version >= c->pinned_message_version) {
LOG(INFO) << "Receive pinned " << pinned_message_id << " in " << chat_id << " with version " << c->version LOG(INFO) << "Receive pinned " << pinned_message_id << " in " << chat_id << " with version " << c->version
<< ". Current version is " << c->pinned_message_version; << ". Current version is " << c->pinned_message_version;
td_->messages_manager_->on_update_dialog_last_pinned_message_id(DialogId(chat_id), pinned_message_id); td_->messages_manager_->on_update_dialog_last_pinned_message_id(DialogId(chat_id), pinned_message_id);
@ -10797,8 +10801,9 @@ void ContactsManager::on_get_chat_full(tl_object_ptr<telegram_api::ChatFull> &&c
ChatFull *chat_full = add_chat_full(chat_id); ChatFull *chat_full = add_chat_full(chat_id);
on_update_chat_full_invite_link(chat_full, std::move(chat->exported_invite_)); on_update_chat_full_invite_link(chat_full, std::move(chat->exported_invite_));
on_update_chat_full_photo(chat_full, chat_id, auto photo = get_photo(td_->file_manager_.get(), std::move(chat->chat_photo_), DialogId(chat_id));
get_photo(td_->file_manager_.get(), std::move(chat->chat_photo_), DialogId(chat_id))); on_update_chat_photo(c, as_dialog_photo(td_->file_manager_.get(), DialogId(chat_id), 0, photo));
on_update_chat_full_photo(chat_full, chat_id, std::move(photo));
if (chat_full->description != chat->about_) { if (chat_full->description != chat->about_) {
chat_full->description = std::move(chat->about_); chat_full->description = std::move(chat->about_);
chat_full->is_changed = true; chat_full->is_changed = true;
@ -10828,6 +10833,7 @@ void ContactsManager::on_get_chat_full(tl_object_ptr<telegram_api::ChatFull> &&c
} }
chat_full->is_update_chat_full_sent = true; chat_full->is_update_chat_full_sent = true;
update_chat(c, chat_id);
update_chat_full(chat_full, chat_id, "on_get_chat_full"); update_chat_full(chat_full, chat_id, "on_get_chat_full");
} else { } else {
CHECK(chat_full_ptr->get_id() == telegram_api::channelFull::ID); CHECK(chat_full_ptr->get_id() == telegram_api::channelFull::ID);
@ -10963,9 +10969,9 @@ void ContactsManager::on_get_chat_full(tl_object_ptr<telegram_api::ChatFull> &&c
channel_full->need_save_to_database = true; channel_full->need_save_to_database = true;
} }
on_update_channel_full_photo( auto photo = get_photo(td_->file_manager_.get(), std::move(channel->chat_photo_), DialogId(channel_id));
channel_full, channel_id, on_update_channel_photo(c, as_dialog_photo(td_->file_manager_.get(), DialogId(channel_id), c->access_hash, photo));
get_photo(td_->file_manager_.get(), std::move(channel->chat_photo_), DialogId(channel_id))); on_update_channel_full_photo(channel_full, channel_id, std::move(photo));
td_->messages_manager_->on_read_channel_outbox(channel_id, td_->messages_manager_->on_read_channel_outbox(channel_id,
MessageId(ServerMessageId(channel->read_outbox_max_id_))); MessageId(ServerMessageId(channel->read_outbox_max_id_)));
@ -11096,6 +11102,7 @@ void ContactsManager::on_get_chat_full(tl_object_ptr<telegram_api::ChatFull> &&c
} }
channel_full->is_update_channel_full_sent = true; channel_full->is_update_channel_full_sent = true;
update_channel(c, channel_id);
update_channel_full(channel_full, channel_id, "on_get_channel_full"); update_channel_full(channel_full, channel_id, "on_get_channel_full");
if (linked_channel_id.is_valid()) { if (linked_channel_id.is_valid()) {
@ -12620,9 +12627,6 @@ void ContactsManager::on_update_chat_full_photo(ChatFull *chat_full, ChatId chat
chat_full->photo = std::move(photo); chat_full->photo = std::move(photo);
chat_full->is_changed = true; chat_full->is_changed = true;
} }
if (chat_full->photo.is_empty()) {
drop_chat_photos(chat_id, true, false, "on_update_chat_full_photo");
}
auto photo_file_ids = photo_get_file_ids(chat_full->photo); auto photo_file_ids = photo_get_file_ids(chat_full->photo);
if (chat_full->registered_photo_file_ids == photo_file_ids) { if (chat_full->registered_photo_file_ids == photo_file_ids) {
@ -12657,9 +12661,6 @@ void ContactsManager::on_update_channel_full_photo(ChannelFull *channel_full, Ch
channel_full->photo = std::move(photo); channel_full->photo = std::move(photo);
channel_full->is_changed = true; channel_full->is_changed = true;
} }
if (channel_full->photo.is_empty()) {
drop_channel_photos(channel_id, true, false, "on_update_channel_full_photo");
}
auto photo_file_ids = photo_get_file_ids(channel_full->photo); auto photo_file_ids = photo_get_file_ids(channel_full->photo);
if (channel_full->registered_photo_file_ids == photo_file_ids) { if (channel_full->registered_photo_file_ids == photo_file_ids) {
@ -13437,14 +13438,16 @@ void ContactsManager::on_update_chat_participant_count(Chat *c, ChatId chat_id,
void ContactsManager::on_update_chat_photo(Chat *c, ChatId chat_id, void ContactsManager::on_update_chat_photo(Chat *c, ChatId chat_id,
tl_object_ptr<telegram_api::ChatPhoto> &&chat_photo_ptr) { tl_object_ptr<telegram_api::ChatPhoto> &&chat_photo_ptr) {
DialogPhoto new_chat_photo = on_update_chat_photo(c, get_dialog_photo(td_->file_manager_.get(), DialogId(chat_id), 0, std::move(chat_photo_ptr)));
get_dialog_photo(td_->file_manager_.get(), DialogId(chat_id), 0, std::move(chat_photo_ptr)); }
void ContactsManager::on_update_chat_photo(Chat *c, DialogPhoto &&photo) {
if (td_->auth_manager_->is_bot()) { if (td_->auth_manager_->is_bot()) {
new_chat_photo.minithumbnail.clear(); photo.minithumbnail.clear();
} }
if (new_chat_photo != c->photo) { if (photo != c->photo) {
c->photo = new_chat_photo; c->photo = std::move(photo);
c->is_photo_changed = true; c->is_photo_changed = true;
c->need_save_to_database = true; c->need_save_to_database = true;
} }
@ -13579,14 +13582,17 @@ void ContactsManager::drop_chat_full(ChatId chat_id) {
void ContactsManager::on_update_channel_photo(Channel *c, ChannelId channel_id, void ContactsManager::on_update_channel_photo(Channel *c, ChannelId channel_id,
tl_object_ptr<telegram_api::ChatPhoto> &&chat_photo_ptr) { tl_object_ptr<telegram_api::ChatPhoto> &&chat_photo_ptr) {
DialogPhoto new_chat_photo = on_update_channel_photo(
get_dialog_photo(td_->file_manager_.get(), DialogId(channel_id), c->access_hash, std::move(chat_photo_ptr)); c, get_dialog_photo(td_->file_manager_.get(), DialogId(channel_id), c->access_hash, std::move(chat_photo_ptr)));
}
void ContactsManager::on_update_channel_photo(Channel *c, DialogPhoto &&photo) {
if (td_->auth_manager_->is_bot()) { if (td_->auth_manager_->is_bot()) {
new_chat_photo.minithumbnail.clear(); photo.minithumbnail.clear();
} }
if (new_chat_photo != c->photo) { if (photo != c->photo) {
c->photo = new_chat_photo; c->photo = std::move(photo);
c->is_photo_changed = true; c->is_photo_changed = true;
c->need_save_to_database = true; c->need_save_to_database = true;
} }

View File

@ -1256,6 +1256,7 @@ class ContactsManager final : public Actor {
void on_update_chat_participant_count(Chat *c, ChatId chat_id, int32 participant_count, int32 version, void on_update_chat_participant_count(Chat *c, ChatId chat_id, int32 participant_count, int32 version,
const string &debug_str); const string &debug_str);
void on_update_chat_photo(Chat *c, ChatId chat_id, tl_object_ptr<telegram_api::ChatPhoto> &&chat_photo_ptr); void on_update_chat_photo(Chat *c, ChatId chat_id, tl_object_ptr<telegram_api::ChatPhoto> &&chat_photo_ptr);
void on_update_chat_photo(Chat *c, DialogPhoto &&photo);
static void on_update_chat_title(Chat *c, ChatId chat_id, string &&title); static void on_update_chat_title(Chat *c, ChatId chat_id, string &&title);
static void on_update_chat_active(Chat *c, ChatId chat_id, bool is_active); static void on_update_chat_active(Chat *c, ChatId chat_id, bool is_active);
static void on_update_chat_migrated_to_channel_id(Chat *c, ChatId chat_id, ChannelId migrated_to_channel_id); static void on_update_chat_migrated_to_channel_id(Chat *c, ChatId chat_id, ChannelId migrated_to_channel_id);
@ -1270,6 +1271,7 @@ class ContactsManager final : public Actor {
void on_update_channel_photo(Channel *c, ChannelId channel_id, void on_update_channel_photo(Channel *c, ChannelId channel_id,
tl_object_ptr<telegram_api::ChatPhoto> &&chat_photo_ptr); tl_object_ptr<telegram_api::ChatPhoto> &&chat_photo_ptr);
void on_update_channel_photo(Channel *c, DialogPhoto &&photo);
static void on_update_channel_title(Channel *c, ChannelId channel_id, string &&title); static void on_update_channel_title(Channel *c, ChannelId channel_id, string &&title);
void on_update_channel_username(Channel *c, ChannelId channel_id, string &&username); void on_update_channel_username(Channel *c, ChannelId channel_id, string &&username);
void on_update_channel_status(Channel *c, ChannelId channel_id, DialogParticipantStatus &&status); void on_update_channel_status(Channel *c, ChannelId channel_id, DialogParticipantStatus &&status);