Process Message.is_pinned updates.

GitOrigin-RevId: 5dd3c0545a295c9faf408a3dbf8fb2767e290e34
This commit is contained in:
levlam 2020-10-20 15:08:36 +03:00
parent ec61ef8093
commit 01447bb3f3
6 changed files with 111 additions and 15 deletions

View File

@ -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

Binary file not shown.

View File

@ -6100,6 +6100,14 @@ void MessagesManager::add_pending_update(tl_object_ptr<telegram_api::Update> &&u
}
break;
}
case telegram_api::updatePinnedMessages::ID: {
auto update_pinned_messages = static_cast<const telegram_api::updatePinnedMessages *>(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<telegram_api::Update> &&updat
auto delete_update = move_tl_object_as<telegram_api::updateDeleteMessages>(update);
LOG(INFO) << "Process updateDeleteMessages";
vector<MessageId> 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<telegram_api::Update> &&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<telegram_api::updatePinnedMessages>(update);
LOG(INFO) << "Process updatePinnedMessages";
vector<MessageId> 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<telegram_api::Update>
on_message_edited(full_message_id);
break;
}
case telegram_api::updatePinnedChannelMessages::ID: {
auto pinned_channel_messages_update = move_tl_object_as<telegram_api::updatePinnedChannelMessages>(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<MessageId> 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<MessageId> &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<td_api::updateMessageIsPinned>(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:

View File

@ -1815,6 +1815,11 @@ class MessagesManager : public Actor {
void delete_dialog_messages_from_updates(DialogId dialog_id, const vector<MessageId> &message_ids,
bool skip_update_for_not_found_messages);
void update_dialog_pinned_messages_from_updates(DialogId dialog_id, const vector<MessageId> &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<Message *> &messages,
const vector<MessageId> &message_ids, uint64 log_event_id);

View File

@ -1336,8 +1336,8 @@ void UpdatesManager::on_pending_updates(vector<tl_object_ptr<telegram_api::Updat
if (id == telegram_api::updateNewMessage::ID || id == telegram_api::updateReadMessagesContents::ID ||
id == telegram_api::updateEditMessage::ID || id == telegram_api::updateDeleteMessages::ID ||
id == telegram_api::updateReadHistoryInbox::ID || id == telegram_api::updateReadHistoryOutbox::ID ||
id == telegram_api::updateWebPage::ID || id == telegram_api::updateNewEncryptedMessage::ID ||
id == telegram_api::updateChannelParticipant::ID) {
id == telegram_api::updateWebPage::ID || id == telegram_api::updatePinnedMessages::ID ||
id == telegram_api::updateNewEncryptedMessage::ID || id == telegram_api::updateChannelParticipant::ID) {
if (!downcast_call(*update, OnUpdate(this, update, false))) {
LOG(ERROR) << "Can't call on some update received from " << source;
}
@ -1755,12 +1755,25 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateReadChannelDisc
MessageId(), MessageId(ServerMessageId(update->read_max_id_)));
}
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updatePinnedMessages> update, bool /*force_apply*/) {
// TODO
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updatePinnedMessages> 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<telegram_api::updatePinnedChannelMessages> 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<telegram_api::updateNotifySettings> update, bool /*force_apply*/) {

View File

@ -250,8 +250,8 @@ class UpdatesManager : public Actor {
void on_update(tl_object_ptr<telegram_api::updateReadChannelDiscussionInbox> update, bool /*force_apply*/);
void on_update(tl_object_ptr<telegram_api::updateReadChannelDiscussionOutbox> update, bool /*force_apply*/);
void on_update(tl_object_ptr<telegram_api::updatePinnedMessages> update, bool /*force_apply*/);
void on_update(tl_object_ptr<telegram_api::updatePinnedChannelMessages> update, bool /*force_apply*/);
void on_update(tl_object_ptr<telegram_api::updatePinnedMessages> update, bool force_apply);
void on_update(tl_object_ptr<telegram_api::updatePinnedChannelMessages> update, bool force_apply);
void on_update(tl_object_ptr<telegram_api::updateDraftMessage> update, bool /*force_apply*/);