diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index cb949c692..79f428163 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -1592,8 +1592,9 @@ messageVoiceNote voice_note:voiceNote caption:formattedText is_listened:Bool = M //@description A message with a location @location The location description @live_period Time relative to the message send date, for which the location can be updated, in seconds //@expires_in Left time for which the location can be updated, in seconds. updateMessageContent is not sent when this field changes -//@heading For live locations, a direction in which the location moves, in degrees; 0-360. If 0 the direction is unknown -messageLocation location:location live_period:int32 expires_in:int32 heading:int32 = MessageContent; +//@heading For live locations, a direction in which the location moves, in degrees; 1-360. If 0 the direction is unknown +//@approaching_notification_distance For live locations, a maximum distance for notifications about approaching another chat member, in meters. 0 if notification is disabled. Available only for the message sender +messageLocation location:location live_period:int32 expires_in:int32 heading:int32 approaching_notification_distance:int32 = MessageContent; //@description A message with information about a venue @venue The venue description messageVenue venue:venue = MessageContent; @@ -1812,8 +1813,9 @@ inputMessageVideoNote video_note:InputFile thumbnail:inputThumbnail duration:int inputMessageVoiceNote voice_note:InputFile duration:int32 waveform:bytes caption:formattedText = InputMessageContent; //@description A message with a location @location Location to be sent @live_period Period for which the location can be updated, in seconds; should be between 60 and 86400 for a live location and 0 otherwise -//@heading For live locations, a direction in which the location moves, in degrees; 0-360. Pass 0 if unknown -inputMessageLocation location:location live_period:int32 heading:int32 = InputMessageContent; +//@heading For live locations, a direction in which the location moves, in degrees; 1-360. Pass 0 if unknown +//@approaching_notification_distance For live locations, a maximum distance for notifications about approaching another chat member, in meters. Pass 0 if notification is disabled. Can't be enabled in channels and Saved Messages, or for anonymous messages +inputMessageLocation location:location live_period:int32 heading:int32 approaching_notification_distance:int32 = InputMessageContent; //@description A message with information about a venue @venue Venue to send inputMessageVenue venue:venue = InputMessageContent; @@ -3734,17 +3736,6 @@ 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; @@ -3854,8 +3845,9 @@ editMessageText chat_id:int53 message_id:int53 reply_markup:ReplyMarkup input_me //@description Edits the message content of a live location. Messages can be edited for a limited period of time specified in the live location. Returns the edited message after the edit is completed on the server side //@chat_id The chat the message belongs to @message_id Identifier of the message @reply_markup The new message reply markup; for bots only @location New location content of the message; may be null. Pass null to stop sharing the live location -//@heading The new direction in which the location moves, in degrees; 0-360. Pass 0 if unknown -editMessageLiveLocation chat_id:int53 message_id:int53 reply_markup:ReplyMarkup location:location heading:int32 = Message; +//@heading The new direction in which the location moves, in degrees; 1-360. Pass 0 if unknown +//@approaching_notification_distance The new maximum distance for notifications about approaching another chat member, in meters. Pass 0 if notification is disabled +editMessageLiveLocation chat_id:int53 message_id:int53 reply_markup:ReplyMarkup location:location heading:int32 approaching_notification_distance:int32 = Message; //@description Edits the content of a message with an animation, an audio, a document, a photo or a video. The media in the message can't be replaced if the message was set to self-destruct. Media can't be replaced by self-destructing media. Media in an album can be edited only to contain a photo or a video. Returns the edited message after the edit is completed on the server side //@chat_id The chat the message belongs to @message_id Identifier of the message @reply_markup The new message reply markup; for bots only @input_message_content New content of the message. Must be one of the following types: InputMessageAnimation, InputMessageAudio, InputMessageDocument, InputMessagePhoto or InputMessageVideo @@ -3874,8 +3866,9 @@ editInlineMessageText inline_message_id:string reply_markup:ReplyMarkup input_me //@description Edits the content of a live location in an inline message sent via a bot; for bots only @inline_message_id Inline message identifier @reply_markup The new message reply markup //@location New location content of the message; may be null. Pass null to stop sharing the live location -//@heading The new direction in which the location moves, in degrees; 0-360. Pass 0 if unknown -editInlineMessageLiveLocation inline_message_id:string reply_markup:ReplyMarkup location:location heading:int32 = Ok; +//@heading The new direction in which the location moves, in degrees; 1-360. Pass 0 if unknown +//@approaching_notification_distance The new maximum distance for notifications about approaching another chat member, in meters. Pass 0 if notification is disabled +editInlineMessageLiveLocation inline_message_id:string reply_markup:ReplyMarkup location:location heading:int32 approaching_notification_distance:int32 = Ok; //@description Edits the content of a message with an animation, an audio, a document, a photo or a video in an inline message sent via a bot; for bots only @inline_message_id Inline message identifier //@reply_markup The new message reply markup; for bots only @input_message_content New content of the message. Must be one of the following types: InputMessageAnimation, InputMessageAudio, InputMessageDocument, InputMessagePhoto or InputMessageVideo diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 89bfec09b..dbdd661cc 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ diff --git a/td/generate/scheme/telegram_api.tl b/td/generate/scheme/telegram_api.tl index 2b4df9c8b..b5af97f13 100644 --- a/td/generate/scheme/telegram_api.tl +++ b/td/generate/scheme/telegram_api.tl @@ -56,7 +56,7 @@ inputMediaPhotoExternal#e5bbfe1a flags:# url:string ttl_seconds:flags.0?int = In inputMediaDocumentExternal#fb52dc99 flags:# url:string ttl_seconds:flags.0?int = InputMedia; inputMediaGame#d33f43f3 id:InputGame = InputMedia; inputMediaInvoice#f4e096c3 flags:# title:string description:string photo:flags.0?InputWebDocument invoice:Invoice payload:bytes provider:string provider_data:DataJSON start_param:string = InputMedia; -inputMediaGeoLive#a22c410e flags:# stopped:flags.0?true geo_point:InputGeoPoint heading:int period:flags.1?int = InputMedia; +inputMediaGeoLive#971fa843 flags:# stopped:flags.0?true geo_point:InputGeoPoint heading:flags.2?int period:flags.1?int proximity_notification_radius:flags.3?int = InputMedia; inputMediaPoll#f94e5f1 flags:# poll:Poll correct_answers:flags.0?Vector solution:flags.1?string solution_entities:flags.1?Vector = InputMedia; inputMediaDice#e66fbf7b emoticon:string = InputMedia; @@ -141,7 +141,7 @@ messageMediaWebPage#a32dd600 webpage:WebPage = MessageMedia; messageMediaVenue#2ec0533f geo:GeoPoint title:string address:string provider:string venue_id:string venue_type:string = MessageMedia; messageMediaGame#fdb19008 game:Game = MessageMedia; messageMediaInvoice#84551347 flags:# shipping_address_requested:flags.1?true test:flags.3?true title:string description:string photo:flags.0?WebDocument receipt_msg_id:flags.2?int currency:string total_amount:long start_param:string = MessageMedia; -messageMediaGeoLive#c65b8990 geo:GeoPoint heading:int period:int = MessageMedia; +messageMediaGeoLive#b940c666 flags:# geo:GeoPoint heading:flags.0?int period:int proximity_notification_radius:flags.1?int = MessageMedia; messageMediaPoll#4bd6e798 poll:Poll results:PollResults = MessageMedia; messageMediaDice#3f7ee58b value:int emoticon:string = MessageMedia; @@ -618,7 +618,7 @@ messages.savedGifs#2e0709a5 hash:int gifs:Vector = messages.SavedGifs; inputBotInlineMessageMediaAuto#3380c786 flags:# message:string entities:flags.1?Vector reply_markup:flags.2?ReplyMarkup = InputBotInlineMessage; inputBotInlineMessageText#3dcd7a87 flags:# no_webpage:flags.0?true message:string entities:flags.1?Vector reply_markup:flags.2?ReplyMarkup = InputBotInlineMessage; -inputBotInlineMessageMediaGeo#db94eea4 flags:# geo_point:InputGeoPoint period:int heading:int reply_markup:flags.2?ReplyMarkup = InputBotInlineMessage; +inputBotInlineMessageMediaGeo#96929a85 flags:# geo_point:InputGeoPoint heading:flags.0?int period:flags.1?int proximity_notification_radius:flags.3?int reply_markup:flags.2?ReplyMarkup = InputBotInlineMessage; inputBotInlineMessageMediaVenue#417bbf11 flags:# geo_point:InputGeoPoint title:string address:string provider:string venue_id:string venue_type:string reply_markup:flags.2?ReplyMarkup = InputBotInlineMessage; inputBotInlineMessageMediaContact#a6edbffd flags:# phone_number:string first_name:string last_name:string vcard:string reply_markup:flags.2?ReplyMarkup = InputBotInlineMessage; inputBotInlineMessageGame#4b425864 flags:# reply_markup:flags.2?ReplyMarkup = InputBotInlineMessage; @@ -630,7 +630,7 @@ inputBotInlineResultGame#4fa417f2 id:string short_name:string send_message:Input botInlineMessageMediaAuto#764cf810 flags:# message:string entities:flags.1?Vector reply_markup:flags.2?ReplyMarkup = BotInlineMessage; botInlineMessageText#8c7f65e2 flags:# no_webpage:flags.0?true message:string entities:flags.1?Vector reply_markup:flags.2?ReplyMarkup = BotInlineMessage; -botInlineMessageMediaGeo#cd65660 flags:# geo:GeoPoint period:int heading:int reply_markup:flags.2?ReplyMarkup = BotInlineMessage; +botInlineMessageMediaGeo#51846fd flags:# geo:GeoPoint heading:flags.0?int period:flags.1?int proximity_notification_radius:flags.3?int reply_markup:flags.2?ReplyMarkup = BotInlineMessage; botInlineMessageMediaVenue#8a86659c flags:# geo:GeoPoint title:string address:string provider:string venue_id:string venue_type:string reply_markup:flags.2?ReplyMarkup = BotInlineMessage; botInlineMessageMediaContact#18d1cdc2 flags:# phone_number:string first_name:string last_name:string vcard:string reply_markup:flags.2?ReplyMarkup = BotInlineMessage; @@ -1412,7 +1412,6 @@ 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; messages.unpinAllMessages#f025bc8b peer:InputPeer = messages.AffectedHistory; updates.getState#edd4882a = updates.State; diff --git a/td/generate/scheme/telegram_api.tlo b/td/generate/scheme/telegram_api.tlo index 9b8820048..7f33b24ef 100644 Binary files a/td/generate/scheme/telegram_api.tlo and b/td/generate/scheme/telegram_api.tlo differ diff --git a/td/telegram/InlineQueriesManager.cpp b/td/telegram/InlineQueriesManager.cpp index ea2745537..659fea246 100644 --- a/td/telegram/InlineQueriesManager.cpp +++ b/td/telegram/InlineQueriesManager.cpp @@ -257,9 +257,16 @@ Result> InlineQueriesManager: } if (constructor_id == td_api::inputMessageLocation::ID) { TRY_RESULT(location, process_input_message_location(std::move(input_message_content))); - return make_tl_object(flags, location.location.get_input_geo_point(), - location.live_period, location.heading, - std::move(input_reply_markup)); + if (location.heading != 0) { + flags |= telegram_api::inputBotInlineMessageMediaGeo::HEADING_MASK; + } + if (location.live_period != 0) { + flags |= telegram_api::inputBotInlineMessageMediaGeo::PERIOD_MASK; + flags |= telegram_api::inputBotInlineMessageMediaGeo::PROXIMITY_NOTIFICATION_RADIUS_MASK; + } + return make_tl_object( + flags, location.location.get_input_geo_point(), location.heading, location.live_period, + location.approaching_notification_distance, std::move(input_reply_markup)); } if (constructor_id == td_api::inputMessageVenue::ID) { TRY_RESULT(venue, process_input_message_venue(std::move(input_message_content))); diff --git a/td/telegram/Location.cpp b/td/telegram/Location.cpp index 08a2a43ad..5d4fd6f14 100644 --- a/td/telegram/Location.cpp +++ b/td/telegram/Location.cpp @@ -151,10 +151,16 @@ Result process_input_message_location( return Status::Error(400, "Wrong live location heading specified"); } + auto approaching_notification_distance = input_location->approaching_notification_distance_; + if (approaching_notification_distance < 0) { + return Status::Error(400, "Wrong live location approaching notification distance specified"); + } + InputMessageLocation result; result.location = std::move(location); result.live_period = period; result.heading = heading; + result.approaching_notification_distance = approaching_notification_distance; return std::move(result); } diff --git a/td/telegram/Location.h b/td/telegram/Location.h index 0cdcf064c..2e624bcb0 100644 --- a/td/telegram/Location.h +++ b/td/telegram/Location.h @@ -126,6 +126,7 @@ struct InputMessageLocation { Location location; int32 live_period; int32 heading; + int32 approaching_notification_distance; }; Result process_input_message_location( td_api::object_ptr &&input_message_content) TD_WARN_UNUSED_RESULT; diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 0127bb0e2..84602dded 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -568,14 +568,24 @@ class MessageLiveLocation : public MessageContent { Location location; int32 period = 0; int32 heading = 0; + int32 approaching_notification_distance = 0; MessageLiveLocation() = default; - MessageLiveLocation(Location &&location, int32 period, int32 heading) - : location(std::move(location)), period(period), heading(heading) { + MessageLiveLocation(Location &&location, int32 period, int32 heading, int32 approaching_notification_distance) + : location(std::move(location)) + , period(period) + , heading(heading) + , approaching_notification_distance(approaching_notification_distance) { + if (period < 0) { + period = 0; + } if (heading < 0 || heading > 360) { LOG(ERROR) << "Receive wrong heading " << heading; heading = 0; } + if (approaching_notification_distance < 0) { + approaching_notification_distance = 0; + } } MessageContentType get_type() const override { @@ -755,6 +765,7 @@ static void store(const MessageContent *content, StorerT &storer) { store(m->location, storer); store(m->period, storer); store(m->heading, storer); + store(m->approaching_notification_distance, storer); break; } case MessageContentType::Location: { @@ -1061,6 +1072,11 @@ static void parse(unique_ptr &content, ParserT &parser) { } else { m->heading = 0; } + if (parser.version() >= static_cast(Version::AddLiveLocationApproachingNotificationDistance)) { + parse(m->approaching_notification_distance, parser); + } else { + m->approaching_notification_distance = 0; + } content = std::move(m); break; } @@ -1396,9 +1412,18 @@ InlineMessageContent create_inline_message_content(Td *td, FileId file_id, } case telegram_api::botInlineMessageMediaGeo::ID: { auto inline_message_geo = move_tl_object_as(inline_message); - if (inline_message_geo->period_ > 0) { + if ((inline_message_geo->flags_ & telegram_api::botInlineMessageMediaGeo::PERIOD_MASK) != 0 && + inline_message_geo->period_ > 0) { + auto heading = (inline_message_geo->flags_ & telegram_api::botInlineMessageMediaGeo::HEADING_MASK) != 0 + ? inline_message_geo->heading_ + : 0; + auto approacing_notification_distance = + (inline_message_geo->flags_ & telegram_api::botInlineMessageMediaGeo::PROXIMITY_NOTIFICATION_RADIUS_MASK) != + 0 + ? inline_message_geo->proximity_notification_radius_ + : 0; result.message_content = make_unique( - Location(inline_message_geo->geo_), inline_message_geo->period_, inline_message_geo->heading_); + Location(inline_message_geo->geo_), inline_message_geo->period_, heading, approacing_notification_distance); } else { result.message_content = make_unique(Location(inline_message_geo->geo_)); } @@ -1661,8 +1686,8 @@ static Result create_input_message_content( if (location.live_period == 0) { content = make_unique(std::move(location.location)); } else { - content = - make_unique(std::move(location.location), location.live_period, location.heading); + content = make_unique(std::move(location.location), location.live_period, location.heading, + location.approaching_notification_distance); } break; } @@ -2258,8 +2283,13 @@ static tl_object_ptr get_input_media_impl( case MessageContentType::LiveLocation: { auto m = static_cast(content); int32 flags = telegram_api::inputMediaGeoLive::PERIOD_MASK; + if (m->heading != 0) { + flags |= telegram_api::inputMediaGeoLive::HEADING_MASK; + } + flags |= telegram_api::inputMediaGeoLive::PROXIMITY_NOTIFICATION_RADIUS_MASK; return make_tl_object(flags, false /*ignored*/, - m->location.get_input_geo_point(), m->heading, m->period); + m->location.get_input_geo_point(), m->heading, m->period, + m->approaching_notification_distance); } case MessageContentType::Location: { auto m = static_cast(content); @@ -2841,7 +2871,8 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo if (old_->location != new_->location) { need_update = true; } - if (old_->period != new_->period || old_->heading != new_->heading) { + if (old_->period != new_->period || old_->heading != new_->heading || + old_->approaching_notification_distance != new_->approaching_notification_distance) { need_update = true; } if (old_->location.get_access_hash() != new_->location.get_access_hash()) { @@ -2929,8 +2960,8 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo auto volume_id = -new_file_view.remote_location().get_id(); FileId file_id = td->file_manager_->register_remote( FullRemoteFileLocation({FileType::Photo, 'i'}, new_file_view.remote_location().get_id(), - new_file_view.remote_location().get_access_hash(), 0, volume_id, - DcId::invalid(), new_file_view.remote_location().get_file_reference().str()), + new_file_view.remote_location().get_access_hash(), 0, volume_id, DcId::invalid(), + new_file_view.remote_location().get_file_reference().str()), FileLocationSource::FromServer, dialog_id, old_photo->photos.back().size, 0, ""); LOG_STATUS(td->file_manager_->merge(file_id, old_file_id)); } @@ -3876,7 +3907,8 @@ unique_ptr get_message_content(Td *td, FormattedText message, LOG(ERROR) << "Receive wrong live location period = " << period; return make_unique(std::move(location)); } - return make_unique(std::move(location), period, message_geo_point_live->heading_); + return make_unique(std::move(location), period, message_geo_point_live->heading_, + message_geo_point_live->proximity_notification_radius_); } case telegram_api::messageMediaVenue::ID: { auto message_venue = move_tl_object_as(media); @@ -4454,11 +4486,13 @@ tl_object_ptr get_message_content_object(const MessageCo auto passed = max(G()->unix_time_cached() - message_date, 0); auto expires_in = max(0, m->period - passed); auto heading = expires_in == 0 ? 0 : m->heading; - return make_tl_object(m->location.get_location_object(), m->period, expires_in, heading); + auto approaching_notification_distance = expires_in == 0 ? 0 : m->approaching_notification_distance; + return make_tl_object(m->location.get_location_object(), m->period, expires_in, heading, + approaching_notification_distance); } case MessageContentType::Location: { const MessageLocation *m = static_cast(content); - return make_tl_object(m->location.get_location_object(), 0, 0, 0); + return make_tl_object(m->location.get_location_object(), 0, 0, 0, 0); } case MessageContentType::Photo: { const MessagePhoto *m = static_cast(content); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 813b62e82..df10519d5 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -1872,41 +1872,6 @@ 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_; @@ -20692,45 +20657,6 @@ 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(); @@ -24172,7 +24098,7 @@ void MessagesManager::edit_message_text(FullMessageId full_message_id, void MessagesManager::edit_message_live_location(FullMessageId full_message_id, tl_object_ptr &&reply_markup, tl_object_ptr &&input_location, int32 heading, - Promise &&promise) { + int32 approaching_notification_distance, Promise &&promise) { LOG(INFO) << "Begin to edit live location of " << full_message_id; auto dialog_id = full_message_id.get_dialog_id(); Dialog *d = get_dialog_force(dialog_id); @@ -24218,8 +24144,12 @@ void MessagesManager::edit_message_live_location(FullMessageId full_message_id, if (location.empty()) { flags |= telegram_api::inputMediaGeoLive::STOPPED_MASK; } + if (heading != 0) { + flags |= telegram_api::inputMediaGeoLive::HEADING_MASK; + } + flags |= telegram_api::inputMediaGeoLive::PROXIMITY_NOTIFICATION_RADIUS_MASK; auto input_media = telegram_api::make_object( - flags, false /*ignored*/, location.get_input_geo_point(), heading, 0); + flags, false /*ignored*/, location.get_input_geo_point(), heading, 0, approaching_notification_distance); send_closure(td_->create_net_actor(std::move(promise)), &EditMessageActor::send, 0, dialog_id, m->message_id, string(), vector>(), std::move(input_media), std::move(input_reply_markup), get_message_schedule_date(m), @@ -24533,6 +24463,7 @@ void MessagesManager::edit_inline_message_text(const string &inline_message_id, void MessagesManager::edit_inline_message_live_location(const string &inline_message_id, tl_object_ptr &&reply_markup, tl_object_ptr &&input_location, int32 heading, + int32 approaching_notification_distance, Promise &&promise) { if (!td_->auth_manager_->is_bot()) { return promise.set_error(Status::Error(3, "Method is available only for bots")); @@ -24557,8 +24488,12 @@ void MessagesManager::edit_inline_message_live_location(const string &inline_mes if (location.empty()) { flags |= telegram_api::inputMediaGeoLive::STOPPED_MASK; } + if (heading != 0) { + flags |= telegram_api::inputMediaGeoLive::HEADING_MASK; + } + flags |= telegram_api::inputMediaGeoLive::PROXIMITY_NOTIFICATION_RADIUS_MASK; auto input_media = telegram_api::make_object( - flags, false /*ignored*/, location.get_input_geo_point(), heading, 0); + flags, false /*ignored*/, location.get_input_geo_point(), heading, 0, approaching_notification_distance); td_->create_handler(std::move(promise)) ->send(0, std::move(input_bot_inline_message_id), "", vector>(), std::move(input_media), get_input_reply_markup(r_new_reply_markup.ok())); diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 17ddce4ef..7101b368c 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -440,7 +440,7 @@ class MessagesManager : public Actor { void edit_message_live_location(FullMessageId full_message_id, tl_object_ptr &&reply_markup, tl_object_ptr &&input_location, int32 heading, - Promise &&promise); + int32 approaching_notification_distance, Promise &&promise); void edit_message_media(FullMessageId full_message_id, tl_object_ptr &&reply_markup, tl_object_ptr &&input_message_content, Promise &&promise); @@ -458,7 +458,7 @@ class MessagesManager : public Actor { void edit_inline_message_live_location(const string &inline_message_id, tl_object_ptr &&reply_markup, tl_object_ptr &&input_location, int32 heading, - Promise &&promise); + int32 approaching_notification_distance, Promise &&promise); void edit_inline_message_media(const string &inline_message_id, tl_object_ptr &&reply_markup, tl_object_ptr &&input_message_content, @@ -751,9 +751,6 @@ 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 476cf5b15..d9c51acb6 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -1202,10 +1202,11 @@ class EditMessageLiveLocationRequest : public RequestOnceActor { tl_object_ptr reply_markup_; tl_object_ptr location_; int32 heading_; + int32 approaching_notification_distance_; void do_run(Promise &&promise) override { td->messages_manager_->edit_message_live_location(full_message_id_, std::move(reply_markup_), std::move(location_), - heading_, std::move(promise)); + heading_, approaching_notification_distance_, std::move(promise)); } void do_send_result() override { @@ -1215,12 +1216,14 @@ class EditMessageLiveLocationRequest : public RequestOnceActor { public: EditMessageLiveLocationRequest(ActorShared td, uint64 request_id, int64 dialog_id, int64 message_id, tl_object_ptr reply_markup, - tl_object_ptr location, int32 heading) + tl_object_ptr location, int32 heading, + int32 approaching_notification_distance) : RequestOnceActor(std::move(td), request_id) , full_message_id_(DialogId(dialog_id), MessageId(message_id)) , reply_markup_(std::move(reply_markup)) , location_(std::move(location)) - , heading_(heading) { + , heading_(heading) + , approaching_notification_distance_(approaching_notification_distance) { } }; @@ -5583,23 +5586,6 @@ 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_); } @@ -5751,7 +5737,8 @@ void Td::on_request(uint64 id, td_api::editMessageText &request) { void Td::on_request(uint64 id, td_api::editMessageLiveLocation &request) { CREATE_REQUEST(EditMessageLiveLocationRequest, request.chat_id_, request.message_id_, - std::move(request.reply_markup_), std::move(request.location_), request.heading_); + std::move(request.reply_markup_), std::move(request.location_), request.heading_, + request.approaching_notification_distance_); } void Td::on_request(uint64 id, td_api::editMessageMedia &request) { @@ -5782,9 +5769,9 @@ void Td::on_request(uint64 id, td_api::editInlineMessageLiveLocation &request) { CHECK_IS_BOT(); CLEAN_INPUT_STRING(request.inline_message_id_); CREATE_OK_REQUEST_PROMISE(); - messages_manager_->edit_inline_message_live_location(std::move(request.inline_message_id_), - std::move(request.reply_markup_), std::move(request.location_), - request.heading_, std::move(promise)); + messages_manager_->edit_inline_message_live_location( + std::move(request.inline_message_id_), std::move(request.reply_markup_), std::move(request.location_), + request.heading_, request.approaching_notification_distance_, std::move(promise)); } void Td::on_request(uint64 id, td_api::editInlineMessageMedia &request) { diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 8c13bec32..ee82ef34c 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -587,10 +587,6 @@ 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/Version.h b/td/telegram/Version.h index b00b91932..f5ac591f7 100644 --- a/td/telegram/Version.h +++ b/td/telegram/Version.h @@ -41,6 +41,7 @@ enum class Version : int32 { AddDialogPhotoHasAnimation, AddPhotoProgressiveSizes, AddLiveLocationHeading, + AddLiveLocationApproachingNotificationDistance, // 30 Next }; diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 6f6fe0e72..ebe5e307b 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3159,14 +3159,16 @@ class CliClient final : public Actor { string longitude; string accuracy; string heading; + string approaching_notification_distance; std::tie(chat_id, args) = split(args); std::tie(message_id, args) = split(args); std::tie(latitude, args) = split(args); std::tie(longitude, args) = split(args); - std::tie(accuracy, heading) = split(args); + std::tie(accuracy, args) = split(args); + std::tie(heading, approaching_notification_distance) = split(args); send_request(td_api::make_object( as_chat_id(chat_id), as_message_id(message_id), nullptr, as_location(latitude, longitude, accuracy), - to_integer(heading))); + to_integer(heading), to_integer(approaching_notification_distance))); } else if (op == "emss") { string chat_id; string message_id; @@ -3177,19 +3179,6 @@ 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; @@ -3434,8 +3423,8 @@ class CliClient final : public Actor { std::tie(latitude, args) = split(args); std::tie(longitude, accuracy) = split(args); - send_message(chat_id, - td_api::make_object(as_location(latitude, longitude, accuracy), 0, 0)); + send_message(chat_id, td_api::make_object( + as_location(latitude, longitude, accuracy), 0, 0, 0)); } else if (op == "sll") { string chat_id; string period; @@ -3443,15 +3432,17 @@ class CliClient final : public Actor { string longitude; string accuracy; string heading; + string approaching_notification_distance; std::tie(chat_id, args) = split(args); std::tie(period, args) = split(args); std::tie(latitude, args) = split(args); std::tie(longitude, args) = split(args); - std::tie(accuracy, heading) = split(args); + std::tie(accuracy, args) = split(args); + std::tie(heading, approaching_notification_distance) = split(args); send_message(chat_id, td_api::make_object( as_location(latitude, longitude, accuracy), to_integer(period), - to_integer(heading))); + to_integer(heading), to_integer(approaching_notification_distance))); } else if (op == "spoll" || op == "spollm" || op == "spollp" || op == "squiz") { string chat_id; string question;