Remove td_api::getActiveLiveLocationMessages.

This commit is contained in:
levlam 2024-08-05 21:51:57 +03:00
parent 7f10402ba0
commit 6cfffa0dbc
6 changed files with 24 additions and 80 deletions

View File

@ -8546,9 +8546,6 @@ deleteAllCallMessages revoke:Bool = Ok;
//@description Returns information about the recent locations of chat members that were sent to the chat. Returns up to 1 location message per user @chat_id Chat identifier @limit The maximum number of messages to be returned //@description Returns information about the recent locations of chat members that were sent to the chat. Returns up to 1 location message per user @chat_id Chat identifier @limit The maximum number of messages to be returned
searchChatRecentLocationMessages chat_id:int53 limit:int32 = Messages; searchChatRecentLocationMessages chat_id:int53 limit:int32 = Messages;
//@description Returns all active live locations that need to be updated by the application. The list is persistent across application restarts only if the message database is used
getActiveLiveLocationMessages = Messages;
//@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 //@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; getChatMessageByDate chat_id:int53 date:int32 = Message;

View File

@ -6771,15 +6771,15 @@ bool MessagesManager::update_message_interaction_info(Dialog *d, Message *m, int
void MessagesManager::on_update_live_location_viewed(MessageFullId message_full_id) { void MessagesManager::on_update_live_location_viewed(MessageFullId message_full_id) {
LOG(DEBUG) << "Live location was viewed in " << message_full_id; LOG(DEBUG) << "Live location was viewed in " << message_full_id;
if (!are_active_live_location_messages_loaded_) { if (!are_active_live_location_messages_loaded_) {
get_active_live_location_messages(PromiseCreator::lambda([actor_id = actor_id(this), message_full_id](Unit result) { load_active_live_location_messages(
send_closure(actor_id, &MessagesManager::on_update_live_location_viewed, message_full_id); PromiseCreator::lambda([actor_id = actor_id(this), message_full_id](Unit result) {
})); send_closure(actor_id, &MessagesManager::on_update_live_location_viewed, message_full_id);
}));
return; return;
} }
auto active_live_location_message_ids = get_active_live_location_messages(Auto()); if (!td::contains(active_live_location_message_full_ids_, message_full_id)) {
if (!td::contains(active_live_location_message_ids, message_full_id)) { LOG(DEBUG) << "Can't find " << message_full_id;
LOG(DEBUG) << "Can't find " << message_full_id << " in " << active_live_location_message_ids;
return; return;
} }
@ -6789,7 +6789,7 @@ void MessagesManager::on_update_live_location_viewed(MessageFullId message_full_
void MessagesManager::on_update_some_live_location_viewed(Promise<Unit> &&promise) { void MessagesManager::on_update_some_live_location_viewed(Promise<Unit> &&promise) {
LOG(DEBUG) << "Some live location was viewed"; LOG(DEBUG) << "Some live location was viewed";
if (!are_active_live_location_messages_loaded_) { if (!are_active_live_location_messages_loaded_) {
get_active_live_location_messages( load_active_live_location_messages(
PromiseCreator::lambda([actor_id = actor_id(this), promise = std::move(promise)](Unit result) mutable { 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)); send_closure(actor_id, &MessagesManager::on_update_some_live_location_viewed, std::move(promise));
})); }));
@ -6797,8 +6797,7 @@ void MessagesManager::on_update_some_live_location_viewed(Promise<Unit> &&promis
} }
// update all live locations, because it is unknown, which exactly was viewed // 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 (const auto &message_full_id : active_live_location_message_full_ids_) {
for (const auto &message_full_id : active_live_location_message_ids) {
send_update_message_live_location_viewed(message_full_id); send_update_message_live_location_viewed(message_full_id);
} }
@ -12704,7 +12703,7 @@ void MessagesManager::init() {
} }
} }
get_active_live_location_messages(Promise<Unit>()); load_active_live_location_messages(Promise<Unit>());
} else if (!td_->auth_manager_->is_bot()) { } else if (!td_->auth_manager_->is_bot()) {
G()->td_db()->get_binlog_pmc()->erase_by_prefix("pinned_dialog_ids"); G()->td_db()->get_binlog_pmc()->erase_by_prefix("pinned_dialog_ids");
G()->td_db()->get_binlog_pmc()->erase_by_prefix("last_server_dialog_date"); G()->td_db()->get_binlog_pmc()->erase_by_prefix("last_server_dialog_date");
@ -20896,46 +20895,22 @@ void MessagesManager::search_dialog_recent_location_messages(DialogId dialog_id,
} }
} }
vector<MessageFullId> MessagesManager::get_active_live_location_messages(Promise<Unit> &&promise) { void MessagesManager::load_active_live_location_messages(Promise<Unit> &&promise) {
if (!G()->use_message_database()) { if (!G()->use_message_database()) {
are_active_live_location_messages_loaded_ = true; are_active_live_location_messages_loaded_ = true;
} }
if (are_active_live_location_messages_loaded_) {
if (!are_active_live_location_messages_loaded_) { return promise.set_value(Unit());
load_active_live_location_messages_queries_.push_back(std::move(promise));
if (load_active_live_location_messages_queries_.size() == 1u) {
LOG(INFO) << "Trying to load active live location messages from database";
G()->td_db()->get_sqlite_pmc()->get(
"di_active_live_location_messages", PromiseCreator::lambda([](string value) {
send_closure(G()->messages_manager(),
&MessagesManager::on_load_active_live_location_message_full_ids_from_database,
std::move(value));
}));
}
return {};
} }
load_active_live_location_messages_queries_.push_back(std::move(promise));
promise.set_value(Unit()); if (load_active_live_location_messages_queries_.size() == 1u) {
vector<MessageFullId> result; LOG(INFO) << "Trying to load active live location messages from database";
for (const auto &message_full_id : active_live_location_message_full_ids_) { G()->td_db()->get_sqlite_pmc()->get(
auto m = get_message(message_full_id); "di_active_live_location_messages", PromiseCreator::lambda([](string value) {
CHECK(m != nullptr); send_closure(G()->messages_manager(),
CHECK(m->content->get_type() == MessageContentType::LiveLocation); &MessagesManager::on_load_active_live_location_message_full_ids_from_database, std::move(value));
CHECK(!m->message_id.is_scheduled()); }));
if (m->is_failed_to_send) {
continue;
}
auto live_period = get_message_content_live_location_period(m->content.get());
if (live_period <= G()->unix_time() - m->date) { // bool is_expired flag?
// live location is expired
continue;
}
result.push_back(message_full_id);
} }
return result;
} }
void MessagesManager::on_load_active_live_location_message_full_ids_from_database(string value) { void MessagesManager::on_load_active_live_location_message_full_ids_from_database(string value) {
@ -20944,11 +20919,10 @@ void MessagesManager::on_load_active_live_location_message_full_ids_from_databas
} }
if (value.empty()) { if (value.empty()) {
LOG(INFO) << "Active live location messages aren't found in the database"; LOG(INFO) << "Active live location messages aren't found in the database";
on_load_active_live_location_messages_finished();
if (!active_live_location_message_full_ids_.empty()) { if (!active_live_location_message_full_ids_.empty()) {
save_active_live_locations(); save_active_live_locations();
} }
on_load_active_live_location_messages_finished();
return; return;
} }
@ -20971,13 +20945,13 @@ void MessagesManager::on_load_active_live_location_message_full_ids_from_databas
add_active_live_location(message_full_id); add_active_live_location(message_full_id);
} }
on_load_active_live_location_messages_finished();
if (new_message_full_ids.size() != active_live_location_message_full_ids_.size()) { if (new_message_full_ids.size() != active_live_location_message_full_ids_.size()) {
send_update_active_live_location_messages(); send_update_active_live_location_messages();
} }
if (!new_message_full_ids.empty() || old_message_full_ids.size() != active_live_location_message_full_ids_.size()) { if (!new_message_full_ids.empty() || old_message_full_ids.size() != active_live_location_message_full_ids_.size()) {
save_active_live_locations(); save_active_live_locations();
} }
on_load_active_live_location_messages_finished();
} }
void MessagesManager::on_load_active_live_location_messages_finished() { void MessagesManager::on_load_active_live_location_messages_finished() {
@ -21020,7 +20994,7 @@ bool MessagesManager::add_active_live_location(MessageFullId message_full_id) {
save_active_live_locations(); save_active_live_locations();
} else if (load_active_live_location_messages_queries_.empty()) { } else if (load_active_live_location_messages_queries_.empty()) {
// load active live locations and save after that // load active live locations and save after that
get_active_live_location_messages(Auto()); load_active_live_location_messages(Auto());
} }
} }
return true; return true;

View File

@ -754,7 +754,7 @@ class MessagesManager final : public Actor {
void search_dialog_recent_location_messages(DialogId dialog_id, int32 limit, void search_dialog_recent_location_messages(DialogId dialog_id, int32 limit,
Promise<td_api::object_ptr<td_api::messages>> &&promise); Promise<td_api::object_ptr<td_api::messages>> &&promise);
vector<MessageFullId> get_active_live_location_messages(Promise<Unit> &&promise); void load_active_live_location_messages(Promise<Unit> &&promise);
void get_dialog_message_by_date(DialogId dialog_id, int32 date, void get_dialog_message_by_date(DialogId dialog_id, int32 date,
Promise<td_api::object_ptr<td_api::message>> &&promise); Promise<td_api::object_ptr<td_api::message>> &&promise);

View File

@ -1258,24 +1258,6 @@ class SearchChatMessagesRequest final : public RequestActor<> {
} }
}; };
class GetActiveLiveLocationMessagesRequest final : public RequestActor<> {
vector<MessageFullId> message_full_ids_;
void do_run(Promise<Unit> &&promise) final {
message_full_ids_ = td_->messages_manager_->get_active_live_location_messages(std::move(promise));
}
void do_send_result() final {
send_result(td_->messages_manager_->get_messages_object(-1, message_full_ids_, true,
"GetActiveLiveLocationMessagesRequest"));
}
public:
GetActiveLiveLocationMessagesRequest(ActorShared<Td> td, uint64 request_id)
: RequestActor(std::move(td), request_id) {
}
};
class GetChatScheduledMessagesRequest final : public RequestActor<> { class GetChatScheduledMessagesRequest final : public RequestActor<> {
DialogId dialog_id_; DialogId dialog_id_;
@ -4898,11 +4880,6 @@ void Td::on_request(uint64 id, const td_api::searchChatRecentLocationMessages &r
std::move(promise)); std::move(promise));
} }
void Td::on_request(uint64 id, const td_api::getActiveLiveLocationMessages &request) {
CHECK_IS_USER();
CREATE_NO_ARGS_REQUEST(GetActiveLiveLocationMessagesRequest);
}
void Td::on_request(uint64 id, const td_api::getChatMessageByDate &request) { void Td::on_request(uint64 id, const td_api::getChatMessageByDate &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CREATE_REQUEST_PROMISE(); CREATE_REQUEST_PROMISE();

View File

@ -790,8 +790,6 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::searchChatRecentLocationMessages &request); void on_request(uint64 id, const td_api::searchChatRecentLocationMessages &request);
void on_request(uint64 id, const td_api::getActiveLiveLocationMessages &request);
void on_request(uint64 id, const td_api::getChatMessageByDate &request); void on_request(uint64 id, const td_api::getChatMessageByDate &request);
void on_request(uint64 id, const td_api::getChatSparseMessagePositions &request); void on_request(uint64 id, const td_api::getChatSparseMessagePositions &request);

View File

@ -5359,8 +5359,6 @@ class CliClient final : public Actor {
MessageThreadId message_thread_id; MessageThreadId message_thread_id;
get_args(args, chat_id, message_thread_id); get_args(args, chat_id, message_thread_id);
send_request(td_api::make_object<td_api::deleteForumTopic>(chat_id, message_thread_id)); send_request(td_api::make_object<td_api::deleteForumTopic>(chat_id, message_thread_id));
} else if (op == "gallm") {
send_request(td_api::make_object<td_api::getActiveLiveLocationMessages>());
} else if (op == "sbsm") { } else if (op == "sbsm") {
UserId bot_user_id; UserId bot_user_id;
ChatId chat_id; ChatId chat_id;