From fa04e668f6acf90fc8a128edb41cb84aea4f27dc Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 14 Dec 2019 01:57:17 +0300 Subject: [PATCH] Better support for GEO_LIVE_PENDING push notifications. GitOrigin-RevId: 7fb392ec0e6471a09a3b325db48531700204c039 --- td/telegram/MessagesManager.cpp | 25 ++++++++++++++++++++++--- td/telegram/MessagesManager.h | 2 ++ td/telegram/NotificationManager.cpp | 3 ++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 4f2bc0ea2..9ce67975f 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -5701,15 +5701,34 @@ void MessagesManager::on_update_live_location_viewed(FullMessageId full_message_ 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; + auto active_live_location_message_ids = get_active_live_location_messages(Auto()); + if (!td::contains(active_live_location_message_ids, full_message_id)) { + LOG(DEBUG) << "Can't find " << full_message_id << " in " << active_live_location_message_ids; return; } send_update_message_live_location_viewed(full_message_id); } +void MessagesManager::on_update_some_live_location_viewed(Promise &&promise) { + LOG(DEBUG) << "Some live location was viewed"; + if (!are_active_live_location_messages_loaded_) { + get_active_live_location_messages( + PromiseCreator::lambda([actor_id = actor_id(this), promise = std::move(promise)](Unit result) mutable { + send_closure(actor_id, &MessagesManager::on_update_some_live_location_viewed, std::move(promise)); + })); + return; + } + + // update all live locations, because it is unknown, which exactly was viewed + auto active_live_location_message_ids = get_active_live_location_messages(Auto()); + for (auto full_message_id : active_live_location_message_ids) { + send_update_message_live_location_viewed(full_message_id); + } + + promise.set_value(Unit()); +} + void MessagesManager::on_update_message_content(FullMessageId full_message_id) { const Dialog *d = get_dialog(full_message_id.get_dialog_id()); CHECK(d != nullptr); diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 3aaf4b4a3..a00e8c6a2 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -313,6 +313,8 @@ class MessagesManager : public Actor { void on_update_live_location_viewed(FullMessageId full_message_id); + void on_update_some_live_location_viewed(Promise &&promise); + 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, diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index bca1cd8b7..2ef6dc6d7 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -3017,7 +3017,8 @@ Status NotificationManager::process_push_notification_payload(string payload, bo } if (loc_key == "GEO_LIVE_PENDING") { - return Status::Error(406, "Need update live location"); + td_->messages_manager_->on_update_some_live_location_viewed(std::move(promise)); + return Status::OK(); } if (loc_key == "AUTH_REGION" || loc_key == "AUTH_UNKNOWN") {