Simplify handling of updateNewChannelMessage and updateEditChannelMessage.

This commit is contained in:
levlam 2020-12-25 02:53:00 +03:00
parent b867a597e8
commit a8377db05d
3 changed files with 32 additions and 97 deletions

View File

@ -6396,80 +6396,6 @@ void MessagesManager::on_update_service_notification(tl_object_ptr<telegram_api:
} }
} }
void MessagesManager::on_update_new_channel_message(tl_object_ptr<telegram_api::updateNewChannelMessage> &&update,
Promise<Unit> &&promise) {
int new_pts = update->pts_;
int pts_count = update->pts_count_;
DialogId dialog_id = get_message_dialog_id(update->message_);
switch (dialog_id.get_type()) {
case DialogType::None:
promise.set_value(Unit());
return;
case DialogType::User:
case DialogType::Chat:
case DialogType::SecretChat:
LOG(ERROR) << "Receive updateNewChannelMessage in wrong " << dialog_id;
promise.set_value(Unit());
return;
case DialogType::Channel: {
auto channel_id = dialog_id.get_channel_id();
if (!td_->contacts_manager_->have_channel(channel_id)) {
// if min channel was received
if (td_->contacts_manager_->have_min_channel(channel_id)) {
td_->updates_manager_->schedule_get_difference("on_update_new_channel_message");
promise.set_value(Unit()); // TODO postpone
return;
}
}
// Ok
break;
}
default:
UNREACHABLE();
return;
}
add_pending_channel_update(dialog_id, std::move(update), new_pts, pts_count, std::move(promise),
"on_update_new_channel_message");
}
void MessagesManager::on_update_edit_channel_message(tl_object_ptr<telegram_api::updateEditChannelMessage> &&update,
Promise<Unit> &&promise) {
int new_pts = update->pts_;
int pts_count = update->pts_count_;
DialogId dialog_id = get_message_dialog_id(update->message_);
switch (dialog_id.get_type()) {
case DialogType::None:
promise.set_value(Unit());
return;
case DialogType::User:
case DialogType::Chat:
case DialogType::SecretChat:
LOG(ERROR) << "Receive updateEditChannelMessage in wrong " << dialog_id;
promise.set_value(Unit());
return;
case DialogType::Channel: {
auto channel_id = dialog_id.get_channel_id();
if (!td_->contacts_manager_->have_channel(channel_id)) {
// if min channel was received
if (td_->contacts_manager_->have_min_channel(channel_id)) {
td_->updates_manager_->schedule_get_difference("on_update_edit_channel_message");
promise.set_value(Unit()); // TODO postpone
return;
}
}
// Ok
break;
}
default:
UNREACHABLE();
return;
}
add_pending_channel_update(dialog_id, std::move(update), new_pts, pts_count, std::move(promise),
"on_update_edit_channel_message");
}
void MessagesManager::on_update_read_channel_inbox(tl_object_ptr<telegram_api::updateReadChannelInbox> &&update) { void MessagesManager::on_update_read_channel_inbox(tl_object_ptr<telegram_api::updateReadChannelInbox> &&update) {
ChannelId channel_id(update->channel_id_); ChannelId channel_id(update->channel_id_);
if (!channel_id.is_valid()) { if (!channel_id.is_valid()) {
@ -7123,7 +7049,8 @@ void MessagesManager::add_pending_channel_update(DialogId dialog_id, tl_object_p
LOG(INFO) << "Receive from " << source << " pending " << to_string(update); LOG(INFO) << "Receive from " << source << " pending " << to_string(update);
CHECK(update != nullptr); CHECK(update != nullptr);
if (dialog_id.get_type() != DialogType::Channel) { if (dialog_id.get_type() != DialogType::Channel) {
LOG(ERROR) << "Receive update in invalid " << dialog_id << " from " << source << ": " << oneline(to_string(update)); LOG(ERROR) << "Receive channel update in invalid " << dialog_id << " from " << source << ": "
<< oneline(to_string(update));
promise.set_value(Unit()); promise.set_value(Unit());
return; return;
} }
@ -7134,6 +7061,13 @@ void MessagesManager::add_pending_channel_update(DialogId dialog_id, tl_object_p
return; return;
} }
auto channel_id = dialog_id.get_channel_id();
if (!td_->contacts_manager_->have_channel(channel_id) && td_->contacts_manager_->have_min_channel(channel_id)) {
td_->updates_manager_->schedule_get_difference("on_update_new_channel_message");
promise.set_value(Unit());
return;
}
// TODO need to save all updates that can change result of running queries not associated with pts (for example // TODO need to save all updates that can change result of running queries not associated with pts (for example
// getHistory) and apply them to result of these queries // getHistory) and apply them to result of these queries
@ -7141,7 +7075,6 @@ void MessagesManager::add_pending_channel_update(DialogId dialog_id, tl_object_p
if (d == nullptr) { if (d == nullptr) {
auto pts = load_channel_pts(dialog_id); auto pts = load_channel_pts(dialog_id);
if (pts > 0) { if (pts > 0) {
auto channel_id = dialog_id.get_channel_id();
if (!td_->contacts_manager_->have_channel(channel_id)) { if (!td_->contacts_manager_->have_channel(channel_id)) {
// do not create dialog if there is no info about the channel // do not create dialog if there is no info about the channel
LOG(INFO) << "There is no info about " << channel_id << ", so ignore " << oneline(to_string(update)); LOG(INFO) << "There is no info about " << channel_id << ", so ignore " << oneline(to_string(update));

View File

@ -343,12 +343,6 @@ class MessagesManager : public Actor {
void on_update_service_notification(tl_object_ptr<telegram_api::updateServiceNotification> &&update, void on_update_service_notification(tl_object_ptr<telegram_api::updateServiceNotification> &&update,
bool skip_new_entities, Promise<Unit> &&promise); bool skip_new_entities, Promise<Unit> &&promise);
void on_update_new_channel_message(tl_object_ptr<telegram_api::updateNewChannelMessage> &&update,
Promise<Unit> &&promise);
void on_update_edit_channel_message(tl_object_ptr<telegram_api::updateEditChannelMessage> &&update,
Promise<Unit> &&promise);
void on_update_read_channel_inbox(tl_object_ptr<telegram_api::updateReadChannelInbox> &&update); void on_update_read_channel_inbox(tl_object_ptr<telegram_api::updateReadChannelInbox> &&update);
void on_update_read_channel_outbox(tl_object_ptr<telegram_api::updateReadChannelOutbox> &&update); void on_update_read_channel_outbox(tl_object_ptr<telegram_api::updateReadChannelOutbox> &&update);

View File

@ -1696,12 +1696,16 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateNewMessage> upd
int new_pts = update->pts_; int new_pts = update->pts_;
int pts_count = update->pts_count_; int pts_count = update->pts_count_;
td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, std::move(promise), td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, std::move(promise),
"on_updateNewMessage"); "updateNewMessage");
} }
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateNewChannelMessage> update, bool /*force_apply*/, void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateNewChannelMessage> update, bool /*force_apply*/,
Promise<Unit> &&promise) { Promise<Unit> &&promise) {
td_->messages_manager_->on_update_new_channel_message(std::move(update), std::move(promise)); DialogId dialog_id = MessagesManager::get_message_dialog_id(update->message_);
int new_pts = update->pts_;
int pts_count = update->pts_count_;
td_->messages_manager_->add_pending_channel_update(dialog_id, std::move(update), new_pts, pts_count,
std::move(promise), "updateNewChannelMessage");
} }
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateMessageID> update, bool force_apply, void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateMessageID> update, bool force_apply,
@ -1721,7 +1725,7 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateReadMessagesCon
int new_pts = update->pts_; int new_pts = update->pts_;
int pts_count = update->pts_count_; int pts_count = update->pts_count_;
td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, std::move(promise), td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, std::move(promise),
"on_updateReadMessagesContents"); "updateReadMessagesContents");
} }
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateEditMessage> update, bool force_apply, void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateEditMessage> update, bool force_apply,
@ -1729,7 +1733,7 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateEditMessage> up
int new_pts = update->pts_; int new_pts = update->pts_;
int pts_count = update->pts_count_; int pts_count = update->pts_count_;
td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, std::move(promise), td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, std::move(promise),
"on_updateEditMessage"); "updateEditMessage");
} }
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDeleteMessages> update, bool force_apply, void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDeleteMessages> update, bool force_apply,
@ -1738,11 +1742,11 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDeleteMessages>
int pts_count = update->pts_count_; int pts_count = update->pts_count_;
if (update->messages_.empty()) { if (update->messages_.empty()) {
td_->messages_manager_->add_pending_update(make_tl_object<dummyUpdate>(), new_pts, pts_count, force_apply, td_->messages_manager_->add_pending_update(make_tl_object<dummyUpdate>(), new_pts, pts_count, force_apply,
Promise<Unit>(), "on_updateDeleteMessages"); Promise<Unit>(), "updateDeleteMessages");
promise.set_value(Unit()); promise.set_value(Unit());
} else { } else {
td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, std::move(promise), td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, std::move(promise),
"on_updateDeleteMessages"); "updateDeleteMessages");
} }
} }
@ -1754,7 +1758,7 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateReadHistoryInbo
update->still_unread_count_ = -1; update->still_unread_count_ = -1;
} }
td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, std::move(promise), td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, std::move(promise),
"on_updateReadHistoryInbox"); "updateReadHistoryInbox");
} }
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateReadHistoryOutbox> update, bool force_apply, void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateReadHistoryOutbox> update, bool force_apply,
@ -1762,7 +1766,7 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateReadHistoryOutb
int new_pts = update->pts_; int new_pts = update->pts_;
int pts_count = update->pts_count_; int pts_count = update->pts_count_;
td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, std::move(promise), td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, std::move(promise),
"on_updateReadHistoryOutbox"); "updateReadHistoryOutbox");
} }
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateServiceNotification> update, bool /*force_apply*/, void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateServiceNotification> update, bool /*force_apply*/,
@ -1811,7 +1815,11 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannel> update
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateEditChannelMessage> update, bool /*force_apply*/, void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateEditChannelMessage> update, bool /*force_apply*/,
Promise<Unit> &&promise) { Promise<Unit> &&promise) {
td_->messages_manager_->on_update_edit_channel_message(std::move(update), std::move(promise)); DialogId dialog_id = MessagesManager::get_message_dialog_id(update->message_);
int new_pts = update->pts_;
int pts_count = update->pts_count_;
td_->messages_manager_->add_pending_channel_update(dialog_id, std::move(update), new_pts, pts_count,
std::move(promise), "updateEditChannelMessage");
} }
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDeleteChannelMessages> update, bool /*force_apply*/, void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDeleteChannelMessages> update, bool /*force_apply*/,
@ -1820,7 +1828,7 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDeleteChannelMe
int new_pts = update->pts_; int new_pts = update->pts_;
int pts_count = update->pts_count_; int pts_count = update->pts_count_;
td_->messages_manager_->add_pending_channel_update(dialog_id, std::move(update), new_pts, pts_count, td_->messages_manager_->add_pending_channel_update(dialog_id, std::move(update), new_pts, pts_count,
std::move(promise), "on_updateDeleteChannelMessages"); std::move(promise), "updateDeleteChannelMessages");
} }
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelMessageViews> update, bool /*force_apply*/, void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelMessageViews> update, bool /*force_apply*/,
@ -1882,7 +1890,7 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updatePinnedMessages>
int new_pts = update->pts_; int new_pts = update->pts_;
int pts_count = update->pts_count_; int pts_count = update->pts_count_;
td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, std::move(promise), td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, std::move(promise),
"on_updatePinnedMessages"); "updatePinnedMessages");
} }
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updatePinnedChannelMessages> update, bool /*force_apply*/, void UpdatesManager::on_update(tl_object_ptr<telegram_api::updatePinnedChannelMessages> update, bool /*force_apply*/,
@ -1891,7 +1899,7 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updatePinnedChannelMe
int new_pts = update->pts_; int new_pts = update->pts_;
int pts_count = update->pts_count_; int pts_count = update->pts_count_;
td_->messages_manager_->add_pending_channel_update(dialog_id, std::move(update), new_pts, pts_count, td_->messages_manager_->add_pending_channel_update(dialog_id, std::move(update), new_pts, pts_count,
std::move(promise), "on_updatePinnedChannelMessages"); std::move(promise), "updatePinnedChannelMessages");
} }
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateNotifySettings> update, bool /*force_apply*/, void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateNotifySettings> update, bool /*force_apply*/,
@ -1941,7 +1949,7 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateWebPage> update
Promise<Unit> &&promise) { Promise<Unit> &&promise) {
td_->web_pages_manager_->on_get_web_page(std::move(update->webpage_), DialogId()); td_->web_pages_manager_->on_get_web_page(std::move(update->webpage_), DialogId());
td_->messages_manager_->add_pending_update(make_tl_object<dummyUpdate>(), update->pts_, update->pts_count_, td_->messages_manager_->add_pending_update(make_tl_object<dummyUpdate>(), update->pts_, update->pts_count_,
force_apply, Promise<Unit>(), "on_updateWebPage"); force_apply, Promise<Unit>(), "updateWebPage");
promise.set_value(Unit()); promise.set_value(Unit());
} }
@ -1950,7 +1958,7 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelWebPage>
td_->web_pages_manager_->on_get_web_page(std::move(update->webpage_), DialogId()); td_->web_pages_manager_->on_get_web_page(std::move(update->webpage_), DialogId());
DialogId dialog_id(ChannelId(update->channel_id_)); DialogId dialog_id(ChannelId(update->channel_id_));
td_->messages_manager_->add_pending_channel_update(dialog_id, make_tl_object<dummyUpdate>(), update->pts_, td_->messages_manager_->add_pending_channel_update(dialog_id, make_tl_object<dummyUpdate>(), update->pts_,
update->pts_count_, Promise<Unit>(), "on_updateChannelWebPage"); update->pts_count_, Promise<Unit>(), "updateChannelWebPage");
promise.set_value(Unit()); promise.set_value(Unit());
} }
@ -1963,7 +1971,7 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateFolderPeers> up
} }
td_->messages_manager_->add_pending_update(make_tl_object<dummyUpdate>(), update->pts_, update->pts_count_, td_->messages_manager_->add_pending_update(make_tl_object<dummyUpdate>(), update->pts_, update->pts_count_,
force_apply, Promise<Unit>(), "on_updateFolderPeers"); force_apply, Promise<Unit>(), "updateFolderPeers");
promise.set_value(Unit()); promise.set_value(Unit());
} }