diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 4f754d36e..7ebd14dbd 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -2726,6 +2726,10 @@ updateMessageContentOpened chat_id:int53 message_id:int53 = Update; //@description A message with an unread mention was read @chat_id Chat identifier @message_id Message identifier @unread_mention_count The new number of unread mention messages left in the chat updateMessageMentionRead chat_id:int53 message_id:int53 unread_mention_count:int32 = Update; +//@description A message with a live location was viewed. When the update is received, the client is supposed to update the live location +//@chat_id Identifier of the chat with the live location message @message_id Identifier of the message with live location +updateMessageLiveLocationViewed chat_id:int53 message_id:int53 = Update; + //@description A new chat has been loaded/created. This update is guaranteed to come before the chat identifier is returned to the client. The chat field changes will be reported through separate updates @chat The chat updateNewChat chat:chat = Update; @@ -2913,14 +2917,17 @@ updateTermsOfService terms_of_service_id:string terms_of_service:termsOfService //@description List of users nearby has changed. The update is sent only 60 seconds after a successful searchChatsNearby request @users_nearby The new list of users nearby updateUsersNearby users_nearby:vector = Update; -//@description A new incoming inline query; for bots only @id Unique query identifier @sender_user_id Identifier of the user who sent the query @user_location User location, provided by the client; may be null @query Text of the query @offset Offset of the first entry to return +//@description A new incoming inline query; for bots only @id Unique query identifier @sender_user_id Identifier of the user who sent the query @user_location User location, provided by the client; may be null +//@query Text of the query @offset Offset of the first entry to return updateNewInlineQuery id:int64 sender_user_id:int32 user_location:location query:string offset:string = Update; -//@description The user has chosen a result of an inline query; for bots only @sender_user_id Identifier of the user who sent the query @user_location User location, provided by the client; may be null @query Text of the query @result_id Identifier of the chosen result @inline_message_id Identifier of the sent inline message, if known +//@description The user has chosen a result of an inline query; for bots only @sender_user_id Identifier of the user who sent the query @user_location User location, provided by the client; may be null +//@query Text of the query @result_id Identifier of the chosen result @inline_message_id Identifier of the sent inline message, if known updateNewChosenInlineResult sender_user_id:int32 user_location:location query:string result_id:string inline_message_id:string = Update; -//@description A new incoming callback query; for bots only @id Unique query identifier @sender_user_id Identifier of the user who sent the query @chat_id Identifier of the chat where the query was sent -//@message_id Identifier of the message, from which the query originated @chat_instance Identifier that uniquely corresponds to the chat to which the message was sent @payload Query payload +//@description A new incoming callback query; for bots only @id Unique query identifier @sender_user_id Identifier of the user who sent the query +//@chat_id Identifier of the chat where the query was sent @message_id Identifier of the message, from which the query originated +//@chat_instance Identifier that uniquely corresponds to the chat to which the message was sent @payload Query payload updateNewCallbackQuery id:int64 sender_user_id:int32 chat_id:int53 message_id:int53 chat_instance:int64 payload:CallbackQueryPayload = Update; //@description A new incoming callback query from a message sent via a bot; for bots only @id Unique query identifier @sender_user_id Identifier of the user who sent the query @inline_message_id Identifier of the inline message, from which the query originated diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index af9480e10..0bfe15314 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 63d6164e2..4f2bc0ea2 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -5692,6 +5692,24 @@ bool MessagesManager::update_message_views(DialogId dialog_id, Message *m, int32 return false; } +void MessagesManager::on_update_live_location_viewed(FullMessageId full_message_id) { + LOG(DEBUG) << "Live location was viewed in " << full_message_id; + if (!are_active_live_location_messages_loaded_) { + get_active_live_location_messages(PromiseCreator::lambda([actor_id = actor_id(this), full_message_id](Unit result) { + send_closure(actor_id, &MessagesManager::on_update_live_location_viewed, full_message_id); + })); + return; + } + + auto active_live_locations = get_active_live_location_messages(Auto()); + if (!td::contains(active_live_locations, full_message_id)) { + LOG(DEBUG) << "Can't find " << full_message_id << " in " << active_live_locations; + return; + } + + send_update_message_live_location_viewed(full_message_id); +} + void MessagesManager::on_update_message_content(FullMessageId full_message_id) { const Dialog *d = get_dialog(full_message_id.get_dialog_id()); CHECK(d != nullptr); @@ -16011,6 +16029,10 @@ void MessagesManager::on_load_active_live_location_full_message_ids_from_databas if (value.empty()) { LOG(INFO) << "Active live location messages aren't found in the database"; on_load_active_live_location_messages_finished(); + + if (!active_live_location_full_message_ids_.empty()) { + save_active_live_locations(); + } return; } @@ -16074,6 +16096,9 @@ void MessagesManager::add_active_live_location(FullMessageId full_message_id) { if (are_active_live_location_messages_loaded_) { save_active_live_locations(); + } else { + // load active live locations and save after that + get_active_live_location_messages(Auto()); } } @@ -22146,6 +22171,13 @@ void MessagesManager::send_update_message_edited(DialogId dialog_id, const Messa get_reply_markup_object(m->reply_markup))); } +void MessagesManager::send_update_message_live_location_viewed(FullMessageId full_message_id) { + CHECK(get_message(full_message_id) != nullptr); + send_closure(G()->td(), &Td::send_update, + td_api::make_object(full_message_id.get_dialog_id().get(), + full_message_id.get_message_id().get())); +} + void MessagesManager::send_update_delete_messages(DialogId dialog_id, vector &&message_ids, bool is_permanent, bool from_cache) const { if (message_ids.empty()) { diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index ea10af5ba..3aaf4b4a3 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -311,6 +311,8 @@ class MessagesManager : public Actor { void on_update_message_views(FullMessageId full_message_id, int32 views); + void on_update_live_location_viewed(FullMessageId full_message_id); + void on_update_message_content(FullMessageId full_message_id); void on_read_channel_inbox(ChannelId channel_id, MessageId max_message_id, int32 server_unread_count, int32 pts, @@ -1874,6 +1876,8 @@ class MessagesManager : public Actor { void send_update_message_edited(DialogId dialog_id, const Message *m); + void send_update_message_live_location_viewed(FullMessageId full_message_id); + void send_update_delete_messages(DialogId dialog_id, vector &&message_ids, bool is_permanent, bool from_cache) const; diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 977dd18d0..980cf6a92 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -1952,6 +1952,11 @@ void UpdatesManager::on_update(tl_object_ptr updat std::move(update->difference_)); } +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { + td_->messages_manager_->on_update_live_location_viewed( + {DialogId(update->peer_), MessageId(ServerMessageId(update->msg_id_))}); +} + void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { td_->poll_manager_->on_get_poll(PollId(update->poll_id_), std::move(update->poll_), std::move(update->results_)); } @@ -1975,9 +1980,6 @@ void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { } -void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { -} - void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { } diff --git a/td/telegram/UpdatesManager.h b/td/telegram/UpdatesManager.h index 9a50a1c36..1c13fce3f 100644 --- a/td/telegram/UpdatesManager.h +++ b/td/telegram/UpdatesManager.h @@ -278,6 +278,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*/); @@ -287,8 +289,6 @@ 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*/); };