From 01447bb3f3e666e9ce2fe78cc7a900d57ac81a7c Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 20 Oct 2020 15:08:36 +0300 Subject: [PATCH] Process Message.is_pinned updates. GitOrigin-RevId: 5dd3c0545a295c9faf408a3dbf8fb2767e290e34 --- td/generate/scheme/td_api.tl | 9 ++-- td/generate/scheme/td_api.tlo | Bin 185004 -> 185172 bytes td/telegram/MessagesManager.cpp | 85 ++++++++++++++++++++++++++++++-- td/telegram/MessagesManager.h | 5 ++ td/telegram/UpdatesManager.cpp | 23 +++++++-- td/telegram/UpdatesManager.h | 4 +- 6 files changed, 111 insertions(+), 15 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index c21f880b2..7843bfb7b 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -859,7 +859,7 @@ chatPosition list:ChatList order:int64 is_pinned:Bool source:ChatSource = ChatPo //@unread_mention_count Number of unread messages with a mention/reply in the chat //@notification_settings Notification settings for this chat //@action_bar Describes actions which should be possible to do through a chat action bar; may be null -//@pinned_message_id Identifier of the pinned message in the chat; 0 if none +//@pinned_message_id Identifier of the newest pinned message in the chat; 0 if none //@reply_markup_message_id Identifier of the message from which reply markup needs to be used; 0 if there is no default custom reply markup in the chat //@draft_message A draft of a message in the chat; may be null //@client_data Contains application-specific data associated with the chat. (For example, the chat scroll position or local chat notification settings can be stored here.) Persistent if the message database is used @@ -3168,6 +3168,9 @@ updateMessageContent chat_id:int53 message_id:int53 new_content:MessageContent = //@description A message was edited. Changes in the message content will come in a separate updateMessageContent @chat_id Chat identifier @message_id Message identifier @edit_date Point in time (Unix timestamp) when the message was edited @reply_markup New message reply markup; may be null updateMessageEdited chat_id:int53 message_id:int53 edit_date:int32 reply_markup:ReplyMarkup = Update; +//@description The message pinned state was changed @chat_id Chat identifier @message_id The message identifier @is_pinned True, if the message is pinned +updateMessageIsPinned chat_id:int53 message_id:int53 is_pinned:Bool = Update; + //@description The information about interactions with a message has changed @chat_id Chat identifier @message_id Message identifier @interaction_info New information about interactions with the message; may be null updateMessageInteractionInfo chat_id:int53 message_id:int53 interaction_info:messageInteractionInfo = Update; @@ -3229,7 +3232,7 @@ updateScopeNotificationSettings scope:NotificationSettingsScope notification_set //@description The chat action bar was changed @chat_id Chat identifier @action_bar The new value of the action bar; may be null updateChatActionBar chat_id:int53 action_bar:ChatActionBar = Update; -//@description The chat pinned message was changed @chat_id Chat identifier @pinned_message_id The new identifier of the pinned message; 0 if there is no pinned message in the chat +//@description The chat newest pinned message was changed @chat_id Chat identifier @pinned_message_id The new identifier of the newest pinned message; 0 if there is no known pinned messages in the chat updateChatPinnedMessage chat_id:int53 pinned_message_id:int53 = Update; //@description The default chat reply markup was changed. Can occur because new messages with reply markup were received or because an old reply markup was hidden by the user @@ -3595,7 +3598,7 @@ getMessageLocally chat_id:int53 message_id:int53 = Message; //@chat_id Identifier of the chat the message belongs to @message_id Identifier of the message reply to which to get getRepliedMessage chat_id:int53 message_id:int53 = Message; -//@description Returns information about a pinned chat message @chat_id Identifier of the chat the message belongs to +//@description Returns information about a newest pinned chat message @chat_id Identifier of the chat the message belongs to getChatPinnedMessage chat_id:int53 = Message; //@description Returns information about messages. If a message is not found, returns null on the corresponding position of the result @chat_id Identifier of the chat the messages belong to @message_ids Identifiers of the messages to get diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 74138b9f2028c334e6003f48cb5ac0478fee7372..ee7654c7a71b0d5d3b89fdaae892abf2a02cf116 100644 GIT binary patch delta 2055 zcmZ8iT}WGJ81_A@McXqb!?6f5!X`AZSWh=$xrm^3g^ZZC z2-iDGR>9~TMcn}tQ%A`oR;$Or)38eZxs09*Hw9#lj!}_d^o?OAYD{Vnm@*Db>%`8T zPh|T050|E(Ndt6k3m_=#tKjO#Dx^^TLQ^Y+Z2TDMu4jElOJ^$)QKO)8HhI zMSK!lqxX`qQ#HG$AlE)+bgE~iri>aar!kek41;HIbZySLrO zJ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l;@nJ z2;U~Yrm7Y&^pN;rlP)vMr7cvrws4ojTj;jEg}ZFu2IkqOA+BxML2cU(?DH7d=nmd& z-7Y4w?xM$lhLs7r_E0mZry3pL!C6B{ACfL1G0#*LsB_-_dNIxgtOtvF1n2TcnAvlzdpI$5OwPEeNLl=!D=zcx T%T;pq7e7rFv5B^*RCDTI2RZq5 diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index c687ac479..f506cc945 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -6100,6 +6100,14 @@ void MessagesManager::add_pending_update(tl_object_ptr &&u } break; } + case telegram_api::updatePinnedMessages::ID: { + auto update_pinned_messages = static_cast(update.get()); + auto dialog_id = DialogId(update_pinned_messages->peer_); + if (!check_update_dialog_id(update, dialog_id)) { + return; + } + break; + } default: LOG(ERROR) << "Receive unexpected update " << oneline(to_string(update)) << "from " << source; return; @@ -7186,7 +7194,7 @@ void MessagesManager::process_update(tl_object_ptr &&updat auto delete_update = move_tl_object_as(update); LOG(INFO) << "Process updateDeleteMessages"; vector message_ids; - for (auto &message : delete_update->messages_) { + for (auto message : delete_update->messages_) { message_ids.push_back(MessageId(ServerMessageId(message))); } delete_messages_from_updates(message_ids); @@ -7211,6 +7219,17 @@ void MessagesManager::process_update(tl_object_ptr &&updat read_history_outbox(DialogId(read_update->peer_), MessageId(ServerMessageId(read_update->max_id_))); break; } + case telegram_api::updatePinnedMessages::ID: { + auto pinned_messages_update = move_tl_object_as(update); + LOG(INFO) << "Process updatePinnedMessages"; + vector message_ids; + for (auto message : pinned_messages_update->messages_) { + message_ids.push_back(MessageId(ServerMessageId(message))); + } + update_dialog_pinned_messages_from_updates(DialogId(pinned_messages_update->peer_), message_ids, + pinned_messages_update->pinned_); + break; + } default: UNREACHABLE(); } @@ -7260,6 +7279,24 @@ void MessagesManager::process_channel_update(tl_object_ptr on_message_edited(full_message_id); break; } + case telegram_api::updatePinnedChannelMessages::ID: { + auto pinned_channel_messages_update = move_tl_object_as(update); + LOG(INFO) << "Process updatePinnedChannelMessages"; + ChannelId channel_id(pinned_channel_messages_update->channel_id_); + if (!channel_id.is_valid()) { + LOG(ERROR) << "Receive invalid " << channel_id; + break; + } + + vector message_ids; + for (auto &message : pinned_channel_messages_update->messages_) { + message_ids.push_back(MessageId(ServerMessageId(message))); + } + + update_dialog_pinned_messages_from_updates(DialogId(channel_id), message_ids, + pinned_channel_messages_update->pinned_); + break; + } default: UNREACHABLE(); } @@ -9552,6 +9589,46 @@ void MessagesManager::delete_dialog_messages_from_updates(DialogId dialog_id, co send_update_delete_messages(dialog_id, std::move(deleted_message_ids), true, false); } +void MessagesManager::update_dialog_pinned_messages_from_updates(DialogId dialog_id, + const vector &message_ids, bool is_pin) { + Dialog *d = get_dialog_force(dialog_id); + if (d == nullptr) { + LOG(INFO) << "Ignore updatePinnedMessages for unknown " << dialog_id; + return; + } + + for (auto message_id : message_ids) { + if (!message_id.is_valid() || (!message_id.is_server() && dialog_id.get_type() != DialogType::SecretChat)) { + LOG(ERROR) << "Incoming update tries to pin/unpin " << message_id << " in " << dialog_id; + continue; + } + + Message *m = get_message_force(d, message_id, "update_dialog_pinned_messages_from_updates"); + if (m != nullptr) { + if (update_message_is_pinned(d, m, is_pin, "update_dialog_pinned_messages_from_updates")) { + on_message_changed(d, m, true, "update_dialog_pinned_messages_from_updates"); + } + } else if (message_id > d->last_new_message_id) { + get_channel_difference(dialog_id, d->pts, true, "update_dialog_pinned_messages_from_updates"); + } + } +} + +bool MessagesManager::update_message_is_pinned(Dialog *d, Message *m, bool is_pinned, const char *source) { + CHECK(m != nullptr); + CHECK(!m->message_id.is_scheduled()); + if (m->is_pinned == is_pinned) { + return false; + } + + LOG(INFO) << "Update message is_pinned of " << m->message_id << " in " << d->dialog_id << " to " << is_pinned + << " from " << source; + m->is_pinned = is_pinned; + send_closure(G()->td(), &Td::send_update, + make_tl_object(d->dialog_id.get(), m->message_id.get(), is_pinned)); + return true; +} + string MessagesManager::get_message_search_text(const Message *m) const { if (m->is_content_secret) { return string(); @@ -32155,8 +32232,7 @@ bool MessagesManager::update_message(Dialog *d, Message *old_message, unique_ptr // old_message->is_from_scheduled = new_message->is_from_scheduled; } - if (old_message->is_pinned != new_message->is_pinned) { - old_message->is_pinned = new_message->is_pinned; + if (update_message_is_pinned(d, old_message, new_message->is_pinned, "update_message")) { need_send_update = true; } @@ -34154,9 +34230,8 @@ void MessagesManager::process_get_channel_difference_updates( if (update != nullptr) { switch (update->get_id()) { case telegram_api::updateDeleteChannelMessages::ID: - process_channel_update(std::move(update)); - break; case telegram_api::updateEditChannelMessage::ID: + case telegram_api::updatePinnedChannelMessages::ID: process_channel_update(std::move(update)); break; default: diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index fe2e13ff2..37ab83aeb 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -1815,6 +1815,11 @@ class MessagesManager : public Actor { void delete_dialog_messages_from_updates(DialogId dialog_id, const vector &message_ids, bool skip_update_for_not_found_messages); + void update_dialog_pinned_messages_from_updates(DialogId dialog_id, const vector &message_ids, + bool is_pin); + + bool update_message_is_pinned(Dialog *d, Message *m, bool is_pin, const char *source); + void do_forward_messages(DialogId to_dialog_id, DialogId from_dialog_id, const vector &messages, const vector &message_ids, uint64 log_event_id); diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 326d9bac4..edd551888 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -1336,8 +1336,8 @@ void UpdatesManager::on_pending_updates(vectorread_max_id_))); } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { - // TODO +void UpdatesManager::on_update(tl_object_ptr update, bool force_apply) { + CHECK(update != nullptr); + int new_pts = update->pts_; + int pts_count = update->pts_count_; + td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, + "on_updatePinnedMessages"); } void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { - // TODO + ChannelId channel_id(update->channel_id_); + if (!channel_id.is_valid()) { + LOG(ERROR) << "Receive invalid " << channel_id; + return; + } + DialogId dialog_id(channel_id); + 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, + "on_updatePinnedChannelMessages"); } void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { diff --git a/td/telegram/UpdatesManager.h b/td/telegram/UpdatesManager.h index ba9f3cf55..9bf7aa365 100644 --- a/td/telegram/UpdatesManager.h +++ b/td/telegram/UpdatesManager.h @@ -250,8 +250,8 @@ class UpdatesManager : public Actor { void on_update(tl_object_ptr update, bool /*force_apply*/); void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool force_apply); + void on_update(tl_object_ptr update, bool force_apply); void on_update(tl_object_ptr update, bool /*force_apply*/);