Fetch last message of the personal channel if needed.

This commit is contained in:
levlam 2024-03-28 18:58:45 +03:00
parent 877e3329fe
commit e1f7a1331d
3 changed files with 26 additions and 8 deletions

View File

@ -10501,6 +10501,11 @@ void ContactsManager::on_get_user_full(tl_object_ptr<telegram_api::userFull> &&u
user_full->personal_channel_id = personal_channel_id;
user_full->is_changed = true;
}
if (user_full->personal_channel_id != ChannelId()) {
auto personal_message_id = MessageId(ServerMessageId(user->personal_channel_message_));
td_->messages_manager_->get_channel_difference_if_needed(DialogId(user_full->personal_channel_id),
personal_message_id, "on_get_user_full personal chat");
}
auto photo = get_photo(td_, std::move(user->profile_photo_), DialogId(user_id));
auto personal_photo = get_photo(td_, std::move(user->personal_photo_), DialogId(user_id));

View File

@ -8462,6 +8462,14 @@ void MessagesManager::on_get_empty_messages(DialogId dialog_id, const vector<Mes
}
}
void MessagesManager::get_channel_difference_if_needed(DialogId dialog_id, MessageId message_id, const char *source) {
if (!need_channel_difference_to_add_message(dialog_id, message_id)) {
return;
}
const Dialog *d = get_dialog(dialog_id);
get_channel_difference(dialog_id, d == nullptr ? load_channel_pts(dialog_id) : d->pts, 0, message_id, true, source);
}
void MessagesManager::get_channel_difference_if_needed(DialogId dialog_id, MessagesInfo &&messages_info,
Promise<MessagesInfo> &&promise, const char *source) {
if (td_->auth_manager_->is_bot()) {
@ -35947,15 +35955,17 @@ void MessagesManager::set_channel_pts(Dialog *d, int32 new_pts, const char *sour
bool MessagesManager::need_channel_difference_to_add_message(DialogId dialog_id,
const tl_object_ptr<telegram_api::Message> &message_ptr) {
if (dialog_id.get_type() != DialogType::Channel ||
!td_->dialog_manager_->have_input_peer(dialog_id, AccessRights::Read) ||
dialog_id == debug_channel_difference_dialog_ || td_->auth_manager_->is_bot()) {
if (message_ptr == nullptr || DialogId::get_message_dialog_id(message_ptr) != dialog_id) {
return false;
}
if (message_ptr == nullptr) {
return true;
}
if (DialogId::get_message_dialog_id(message_ptr) != dialog_id) {
return need_channel_difference_to_add_message(dialog_id, MessageId::get_message_id(message_ptr, false));
}
bool MessagesManager::need_channel_difference_to_add_message(DialogId dialog_id, MessageId message_id) {
if (td_->auth_manager_->is_bot() || dialog_id.get_type() != DialogType::Channel ||
!td_->dialog_manager_->have_input_peer(dialog_id, AccessRights::Read) ||
dialog_id == debug_channel_difference_dialog_) {
return false;
}
@ -35969,7 +35979,6 @@ bool MessagesManager::need_channel_difference_to_add_message(DialogId dialog_id,
return d->pts > 0 && !d->is_channel_difference_finished;
}
auto message_id = MessageId::get_message_id(message_ptr, false);
LOG(DEBUG) << "Check ability to add " << message_id << " to " << dialog_id;
return message_id > d->last_new_message_id;
}

View File

@ -147,6 +147,8 @@ class MessagesManager final : public Actor {
void on_get_empty_messages(DialogId dialog_id, const vector<MessageId> &empty_message_ids);
void get_channel_difference_if_needed(DialogId dialog_id, MessageId message_id, const char *source);
void get_channel_difference_if_needed(DialogId dialog_id, MessagesInfo &&messages_info,
Promise<MessagesInfo> &&promise, const char *source);
@ -2909,6 +2911,8 @@ class MessagesManager final : public Actor {
bool need_channel_difference_to_add_message(DialogId dialog_id,
const tl_object_ptr<telegram_api::Message> &message_ptr);
bool need_channel_difference_to_add_message(DialogId dialog_id, MessageId message_id);
void run_after_channel_difference(DialogId dialog_id, MessageId expected_max_message_id, Promise<Unit> &&promise,
const char *source);