Support indefinite sharing of live locations.

This commit is contained in:
levlam 2024-04-25 20:38:27 +03:00
parent 882ee4f3b0
commit 6be5906111
3 changed files with 6 additions and 4 deletions

View File

@ -3022,7 +3022,7 @@ messageExpiredVoiceNote = MessageContent;
//@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
//@live_period Time relative to the message send date, for which the location can be updated, in seconds; if 2147483647, then location can be updated forever
//@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; 1-360. If 0 the direction is unknown
//@proximity_alert_radius For live locations, a maximum distance to another chat member for proximity alerts, in meters (0-100000). 0 if the notification is disabled. Available only to the message sender
@ -3462,7 +3462,7 @@ inputMessageVoiceNote voice_note:InputFile duration:int32 waveform:bytes caption
//@description A message with a location
//@location Location to be sent
//@live_period Period for which the location can be updated, in seconds; must be between 60 and 86400 for a live location and 0 otherwise
//@live_period Period for which the location can be updated, in seconds; must be between 60 and 86400 for a temporary live location, 2147483647 for permanent live location, and 0 otherwise
//@heading For live locations, a direction in which the location moves, in degrees; 1-360. Pass 0 if unknown
//@proximity_alert_radius For live locations, a maximum distance to another chat member for proximity alerts, in meters (0-100000). Pass 0 if the notification is disabled. Can't be enabled in channels and Saved Messages
inputMessageLocation location:location live_period:int32 heading:int32 proximity_alert_radius:int32 = InputMessageContent;

View File

@ -10,6 +10,7 @@
#include "td/telegram/Td.h"
#include <cmath>
#include <limits>
namespace td {
@ -157,7 +158,8 @@ Result<InputMessageLocation> process_input_message_location(
constexpr int32 MAX_LIVE_LOCATION_PERIOD = 86400; // seconds, server side limit
auto period = input_location->live_period_;
if (period != 0 && (period < MIN_LIVE_LOCATION_PERIOD || period > MAX_LIVE_LOCATION_PERIOD)) {
if (period != 0 && period != std::numeric_limits<int32>::max() &&
(period < MIN_LIVE_LOCATION_PERIOD || period > MAX_LIVE_LOCATION_PERIOD)) {
return Status::Error(400, "Wrong live location period specified");
}

View File

@ -6940,7 +6940,7 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
case MessageContentType::LiveLocation: {
const auto *m = static_cast<const MessageLiveLocation *>(content);
auto passed = max(G()->unix_time() - message_date, 0);
auto expires_in = max(0, m->period - passed);
auto expires_in = m->period == std::numeric_limits<int32>::max() ? m->period : max(0, m->period - passed);
auto heading = expires_in == 0 ? 0 : m->heading;
auto proximity_alert_radius = expires_in == 0 ? 0 : m->proximity_alert_radius;
return make_tl_object<td_api::messageLocation>(m->location.get_location_object(), m->period, expires_in, heading,