From 9a3653a01745e380eebd866993a4a595b9cb060b Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 19 Oct 2020 18:44:55 +0300 Subject: [PATCH] Add {en,dis}ableLiveLocationApproachingNotification methods. GitOrigin-RevId: d1b92e683a4d663c33a09e8eb42a3aa62d134ef0 --- td/generate/scheme/td_api.tl | 13 ++++- td/generate/scheme/td_api.tlo | Bin 184304 -> 184644 bytes td/generate/scheme/telegram_api.tl | 1 + td/generate/scheme/telegram_api.tlo | Bin 217348 -> 217576 bytes td/telegram/MessagesManager.cpp | 74 ++++++++++++++++++++++++++++ td/telegram/MessagesManager.h | 3 ++ td/telegram/Td.cpp | 17 +++++++ td/telegram/Td.h | 4 ++ td/telegram/cli.cpp | 13 +++++ 9 files changed, 124 insertions(+), 1 deletion(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index f6de33fbe..6969941b2 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -868,7 +868,7 @@ chat id:int53 type:ChatType title:string photo:chatPhotoInfo permissions:chatPer chats total_count:int32 chat_ids:vector = Chats; -//@description Describes a chat located nearby @chat_id Chat identifier @distance Distance to the chat location in meters +//@description Describes a chat located nearby @chat_id Chat identifier @distance Distance to the chat location, in meters chatNearby chat_id:int53 distance:int32 = ChatNearby; //@description Represents a list of chats located nearby @users_nearby List of users nearby @supergroups_nearby List of location-based supergroups nearby @@ -3727,6 +3727,17 @@ searchChatRecentLocationMessages chat_id:int53 limit:int32 = Messages; //@description Returns all active live locations that should be updated by the application. The list is persistent across application restarts only if the message database is used getActiveLiveLocationMessages = Messages; +//@description Enables sending a notification when some other user in the chat approaches the current user. Both users need to send live location messages to the chat +//@chat_id Chat identifier +//@message_id Identifier of an outgoing successfully sent non-anonymous active live location message +//@distance The maximum target distance for the notification, in meters; must be positive +enableLiveLocationApproachingNotification chat_id:int53 message_id:int53 distance:int32 = Ok; + +//@description Disables sending a notification when some other user in the chat approaches the current user +//@chat_id Chat identifier +//@message_id Identifier of an outgoing successfully sent non-anonymous active live location message +disableLiveLocationApproachingNotification chat_id:int53 message_id:int53 = Ok; + //@description Returns the last message sent in a chat no later than the specified date @chat_id Chat identifier @date Point in time (Unix timestamp) relative to which to search for messages getChatMessageByDate chat_id:int53 date:int32 = Message; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index ad190596125aaf7c978a1769f779275c4276460c..34644477a5e8797fbe4e599d0784c399f81b470c 100644 GIT binary patch delta 155 zcmew`pZmxn?uHh|ElgMV7~8gAgC7KMqVD69Dui4dnm; diff --git a/td/generate/scheme/telegram_api.tl b/td/generate/scheme/telegram_api.tl index fd7ebbba5..67b088934 100644 --- a/td/generate/scheme/telegram_api.tl +++ b/td/generate/scheme/telegram_api.tl @@ -1411,6 +1411,7 @@ messages.getOldFeaturedStickers#5fe7025b offset:int limit:int hash:int = message messages.getReplies#24b581ba peer:InputPeer msg_id:int offset_id:int offset_date:int add_offset:int limit:int max_id:int min_id:int hash:int = messages.Messages; messages.getDiscussionMessage#446972fd peer:InputPeer msg_id:int = messages.DiscussionMessage; messages.readDiscussion#f731a9f4 peer:InputPeer msg_id:int read_max_id:int = Bool; +messages.requestProximityNotification#b12ba31c flags:# peer:InputPeer msg_id:int max_distance:flags.0?int = Bool; updates.getState#edd4882a = updates.State; updates.getDifference#25939651 flags:# pts:int pts_total_limit:flags.0?int date:int qts:int = updates.Difference; diff --git a/td/generate/scheme/telegram_api.tlo b/td/generate/scheme/telegram_api.tlo index bed8548d78237a106fa6e3e4dd159a205dbd6b8a..f8511074e63c3ed5a68ffa27b0d876a7774e1a9e 100644 GIT binary patch delta 109 zcmV-z0FwWNq7CSy4S<9Jv;qux0bsWccmj`@DjcILu_bL~b8}&5WpgfaWpQ<7b97L0 zZ+K~KX>@r`Z**y9X=7n@X>V?qE{Fm*mkksHAD6Hs10W3yZDDv{WNCABVQyn(mvQF- PAD2+L0vNZP5CdpH!YwD$ delta 27 jcmaE{n73sSZ$k^?7ABqw#`x{L6-@mzwl@eeXE*==lXMBg diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index a66f515eb..1be2e42c5 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -1817,6 +1817,41 @@ class ReadDiscussionQuery : public Td::ResultHandler { } }; +class RequestProximityNotificationQuery : public Td::ResultHandler { + Promise promise_; + DialogId dialog_id_; + + public: + explicit RequestProximityNotificationQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(DialogId dialog_id, MessageId message_id, int32 distance) { + dialog_id_ = dialog_id; + auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read); + CHECK(input_peer != nullptr); + int32 flags = 0; + if (distance > 0) { + flags |= telegram_api::messages_requestProximityNotification::MAX_DISTANCE_MASK; + } + send_query(G()->net_query_creator().create(telegram_api::messages_requestProximityNotification( + flags, std::move(input_peer), message_id.get_server_message_id().get(), distance))); + } + + void on_result(uint64 id, BufferSlice packet) override { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(id, result_ptr.move_as_error()); + } + + promise_.set_value(Unit()); + } + + void on_error(uint64 id, Status status) override { + td->messages_manager_->on_get_dialog_error(dialog_id_, status, "RequestProximityNotificationQuery"); + promise_.set_error(std::move(status)); + } +}; + class SearchMessagesQuery : public Td::ResultHandler { Promise promise_; DialogId dialog_id_; @@ -20469,6 +20504,45 @@ void MessagesManager::on_message_live_location_viewed_on_server(int64 task_id) { pending_message_live_location_view_timeout_.add_timeout_in(task_id, LIVE_LOCATION_VIEW_PERIOD); } +void MessagesManager::enable_live_location_approaching_notification(DialogId dialog_id, MessageId message_id, + int32 distance, Promise &&promise) { + Dialog *d = get_dialog_force(dialog_id); + if (d == nullptr) { + return promise.set_error(Status::Error(400, "Chat not found")); + } + if (!have_input_peer(dialog_id, AccessRights::Read)) { + return promise.set_error(Status::Error(400, "Can't access the chat")); + } + if (is_broadcast_channel(dialog_id)) { + return promise.set_error(Status::Error(400, "Can't use approaching notifications in channels")); + } + if (dialog_id.get_type() == DialogType::SecretChat) { + return promise.set_error(Status::Error(400, "Can't use approaching notifications in secret chats")); + } + if (dialog_id == get_my_dialog_id()) { + return promise.set_error(Status::Error(400, "Can't use approaching notifications in Saved Messages")); + } + + auto m = get_message_force(d, message_id, "enable_approaching_notification"); + if (m == nullptr) { + return promise.set_error(Status::Error(400, "Message not found")); + } + if (!m->is_outgoing) { + return promise.set_error(Status::Error(400, "Message is not outgoing")); + } + if (!m->sender_user_id.is_valid()) { + return promise.set_error(Status::Error(400, "Message is anonymous")); + } + if (get_message_content_live_location_period(m->content.get()) <= G()->unix_time() - m->date + 1) { + return promise.set_error(Status::Error(400, "Message has no active live location")); + } + if (!message_id.is_server()) { + return promise.set_error(Status::Error(400, "Message is not server")); + } + + td_->create_handler(std::move(promise))->send(dialog_id, message_id, distance); +} + FileSourceId MessagesManager::get_message_file_source_id(FullMessageId full_message_id) { auto dialog_id = full_message_id.get_dialog_id(); auto message_id = full_message_id.get_message_id(); diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index de0998cc4..a05dcc6e1 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -746,6 +746,9 @@ class MessagesManager : public Actor { vector get_active_live_location_messages(Promise &&promise); + void enable_live_location_approaching_notification(DialogId dialog_id, MessageId message_id, int32 distance, + Promise &&promise); + int64 get_dialog_message_by_date(DialogId dialog_id, int32 date, Promise &&promise); void on_get_dialog_message_by_date_success(DialogId dialog_id, int32 date, int64 random_id, diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 5ff84b53c..11303d933 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -5583,6 +5583,23 @@ void Td::on_request(uint64 id, const td_api::getActiveLiveLocationMessages &requ CREATE_NO_ARGS_REQUEST(GetActiveLiveLocationMessagesRequest); } +void Td::on_request(uint64 id, const td_api::enableLiveLocationApproachingNotification &request) { + CHECK_IS_USER(); + if (request.distance_ <= 0) { + return send_error_raw(id, 400, "Invalid distance specified"); + } + CREATE_OK_REQUEST_PROMISE(); + messages_manager_->enable_live_location_approaching_notification( + DialogId(request.chat_id_), MessageId(request.message_id_), request.distance_, std::move(promise)); +} + +void Td::on_request(uint64 id, const td_api::disableLiveLocationApproachingNotification &request) { + CHECK_IS_USER(); + CREATE_OK_REQUEST_PROMISE(); + messages_manager_->enable_live_location_approaching_notification( + DialogId(request.chat_id_), MessageId(request.message_id_), 0, std::move(promise)); +} + void Td::on_request(uint64 id, const td_api::getChatMessageByDate &request) { CREATE_REQUEST(GetChatMessageByDateRequest, request.chat_id_, request.date_); } diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 07fee920d..9fda16f33 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -587,6 +587,10 @@ class Td final : public NetQueryCallback { void on_request(uint64 id, const td_api::getActiveLiveLocationMessages &request); + void on_request(uint64 id, const td_api::enableLiveLocationApproachingNotification &request); + + void on_request(uint64 id, const td_api::disableLiveLocationApproachingNotification &request); + void on_request(uint64 id, const td_api::getChatMessageByDate &request); void on_request(uint64 id, td_api::getChatMessageCount &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index f6c3cdd69..d4f3f0b07 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3160,6 +3160,19 @@ class CliClient final : public Actor { as_chat_id(chat_id), as_message_id(message_id), as_message_scheduling_state(date))); } else if (op == "gallm") { send_request(td_api::make_object()); + } else if (op == "ellan" || op == "dllan") { + string chat_id; + string message_id; + string distance; + std::tie(chat_id, args) = split(args); + std::tie(message_id, distance) = split(args); + if (op == "ellan") { + send_request(td_api::make_object( + as_chat_id(chat_id), as_message_id(message_id), to_integer(distance))); + } else { + send_request(td_api::make_object( + as_chat_id(chat_id), as_message_id(message_id))); + } } else if (op == "sbsm") { string bot_id; string chat_id;