Skip to content

Commit

Permalink
Repair last message after getChannelDifference if it is still unknown.
Browse files Browse the repository at this point in the history
  • Loading branch information
levlam committed Jul 29, 2021
1 parent be53ea2 commit c07562e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion td/telegram/MessagesManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13890,6 +13890,7 @@ void MessagesManager::set_dialog_unread_mention_count(Dialog *d, int32 unread_me

void MessagesManager::set_dialog_is_empty(Dialog *d, const char *source) {
LOG(INFO) << "Set " << d->dialog_id << " is_empty to true from " << source;
CHECK(d->have_full_history);
d->is_empty = true;

if (d->server_unread_count + d->local_unread_count > 0) {
Expand Down Expand Up @@ -14458,7 +14459,7 @@ void MessagesManager::on_get_dialogs(FolderId folder_id, vector<tl_object_ptr<te
auto last_message = std::move(full_message_id_to_message[full_message_id]);
if (last_message == nullptr) {
LOG(ERROR) << "Last " << full_message_id << " not found";
} else if (!has_pts || d->pts == 0 || dialog->pts_ <= d->pts) {
} else if (!has_pts || d->pts == 0 || dialog->pts_ <= d->pts || d->is_channel_difference_finished) {
auto added_full_message_id =
on_get_message(std::move(last_message), false, has_pts, false, false, false, "get chats");
CHECK(d->last_new_message_id == MessageId());
Expand Down Expand Up @@ -35825,6 +35826,7 @@ void MessagesManager::after_get_channel_difference(DialogId dialog_id, bool succ

auto d = get_dialog(dialog_id);
if (d != nullptr) {
d->is_channel_difference_finished = true;
bool have_access = have_input_peer(dialog_id, AccessRights::Read);
if (!d->postponed_channel_updates.empty()) {
LOG(INFO) << "Begin to apply postponed channel updates";
Expand Down Expand Up @@ -35877,6 +35879,11 @@ void MessagesManager::after_get_channel_difference(DialogId dialog_id, bool succ
send_closure_later(G()->notification_manager(), &NotificationManager::after_get_chat_difference,
d->mention_notification_group.group_id);
}

if (!td_->auth_manager_->is_bot() && have_access && !d->last_message_id.is_valid() && !d->is_empty &&
(d->order != DEFAULT_ORDER || is_dialog_sponsored(d))) {
get_history_from_the_end_impl(d, true, false, Auto());
}
}

if (postponed_chat_read_inbox_updates_.erase(dialog_id) > 0) {
Expand Down
1 change: 1 addition & 0 deletions td/telegram/MessagesManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,7 @@ class MessagesManager final : public Actor {

bool is_update_new_chat_sent = false;
bool has_unload_timeout = false;
bool is_channel_difference_finished = false;

int32 pts = 0; // for channels only
std::multimap<int32, PendingPtsUpdate> postponed_channel_updates; // for channels only
Expand Down

0 comments on commit c07562e

Please sign in to comment.