Add {en,dis}ableLiveLocationApproachingNotification methods.

GitOrigin-RevId: d1b92e683a4d663c33a09e8eb42a3aa62d134ef0
This commit is contained in:
levlam 2020-10-19 18:44:55 +03:00
parent 827ceb3ee5
commit 9a3653a017
9 changed files with 124 additions and 1 deletions

View File

@ -868,7 +868,7 @@ chat id:int53 type:ChatType title:string photo:chatPhotoInfo permissions:chatPer
chats total_count:int32 chat_ids:vector<int53> = 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;

Binary file not shown.

View File

@ -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;

Binary file not shown.

View File

@ -1817,6 +1817,41 @@ class ReadDiscussionQuery : public Td::ResultHandler {
}
};
class RequestProximityNotificationQuery : public Td::ResultHandler {
Promise<Unit> promise_;
DialogId dialog_id_;
public:
explicit RequestProximityNotificationQuery(Promise<Unit> &&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<telegram_api::messages_requestProximityNotification>(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<Unit> 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<Unit> &&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<RequestProximityNotificationQuery>(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();

View File

@ -746,6 +746,9 @@ class MessagesManager : public Actor {
vector<FullMessageId> get_active_live_location_messages(Promise<Unit> &&promise);
void enable_live_location_approaching_notification(DialogId dialog_id, MessageId message_id, int32 distance,
Promise<Unit> &&promise);
int64 get_dialog_message_by_date(DialogId dialog_id, int32 date, Promise<Unit> &&promise);
void on_get_dialog_message_by_date_success(DialogId dialog_id, int32 date, int64 random_id,

View File

@ -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_);
}

View File

@ -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);

View File

@ -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<td_api::getActiveLiveLocationMessages>());
} 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<td_api::enableLiveLocationApproachingNotification>(
as_chat_id(chat_id), as_message_id(message_id), to_integer<int32>(distance)));
} else {
send_request(td_api::make_object<td_api::disableLiveLocationApproachingNotification>(
as_chat_id(chat_id), as_message_id(message_id)));
}
} else if (op == "sbsm") {
string bot_id;
string chat_id;