api: add JSON-RPC APIs for location streaming

New API stop_sending_locations() only available
in JSON-RPC stops location streaming
in all accounts and chats.
This commit is contained in:
link2xt
2026-04-24 20:58:58 +02:00
committed by l
parent 7f9c184659
commit 8c927c7f86
7 changed files with 151 additions and 0 deletions

View File

@@ -327,6 +327,29 @@ pub async fn is_sending_locations_to_chat(context: &Context, chat_id: ChatId) ->
.await
}
/// Returns a list of chats in which location streaming is enabled.
async fn get_chats_with_location_streaming(context: &Context) -> Result<Vec<ChatId>> {
context
.sql
.query_map_vec(
"SELECT id FROM chats WHERE locations_send_until>?",
(time(),),
|row| {
let chat_id: ChatId = row.get(0)?;
Ok(chat_id)
},
)
.await
}
/// Stop sending locations in all chats.
pub async fn stop_sending_locations(context: &Context) -> Result<()> {
for chat_id in get_chats_with_location_streaming(context).await? {
send_locations_to_chat(context, chat_id, 0).await?;
}
Ok(())
}
/// Sets current location of the user device.
pub async fn set(context: &Context, latitude: f64, longitude: f64, accuracy: f64) -> Result<bool> {
if latitude == 0.0 && longitude == 0.0 {