mirror of
https://github.com/chatmail/core.git
synced 2026-04-27 18:36:30 +03:00
refactor: split is_sending_locations_to_chat() into two functions
This commit is contained in:
@@ -2561,14 +2561,16 @@ pub unsafe extern "C" fn dc_is_sending_locations_to_chat(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
let ctx = &*context;
|
let ctx = &*context;
|
||||||
let chat_id = if chat_id == 0 {
|
if chat_id == 0 {
|
||||||
None
|
block_on(location::is_sending_locations(ctx))
|
||||||
|
.unwrap_or_log_default(ctx, "Failed is_sending_locations()") as libc::c_int
|
||||||
} else {
|
} else {
|
||||||
Some(ChatId::new(chat_id))
|
block_on(location::is_sending_locations_to_chat(
|
||||||
};
|
ctx,
|
||||||
|
ChatId::new(chat_id),
|
||||||
block_on(location::is_sending_locations_to_chat(ctx, chat_id))
|
))
|
||||||
.unwrap_or_log_default(ctx, "Failed dc_is_sending_locations_to_chat()") as libc::c_int
|
.unwrap_or_log_default(ctx, "Failed is_sending_locations_to_chat()") as libc::c_int
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
|||||||
@@ -573,7 +573,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if location::is_sending_locations_to_chat(&context, None).await? {
|
if location::is_sending_locations(&context).await? {
|
||||||
println!("Location streaming enabled.");
|
println!("Location streaming enabled.");
|
||||||
}
|
}
|
||||||
println!("{cnt} chats");
|
println!("{cnt} chats");
|
||||||
@@ -782,7 +782,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
|||||||
"Location streaming: {}",
|
"Location streaming: {}",
|
||||||
location::is_sending_locations_to_chat(
|
location::is_sending_locations_to_chat(
|
||||||
&context,
|
&context,
|
||||||
Some(sel_chat.as_ref().unwrap().get_id())
|
sel_chat.as_ref().unwrap().get_id()
|
||||||
)
|
)
|
||||||
.await?,
|
.await?,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -272,7 +272,7 @@ pub async fn send_locations_to_chat(
|
|||||||
ensure!(seconds >= 0);
|
ensure!(seconds >= 0);
|
||||||
ensure!(!chat_id.is_special());
|
ensure!(!chat_id.is_special());
|
||||||
let now = time();
|
let now = time();
|
||||||
let is_sending_locations_before = is_sending_locations_to_chat(context, Some(chat_id)).await?;
|
let is_sending_locations_before = is_sending_locations_to_chat(context, chat_id).await?;
|
||||||
context
|
context
|
||||||
.sql
|
.sql
|
||||||
.execute(
|
.execute(
|
||||||
@@ -305,35 +305,26 @@ pub async fn send_locations_to_chat(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether `chat_id` or any chat is sending locations.
|
/// Returns whether any chat is sending locations.
|
||||||
///
|
pub async fn is_sending_locations(context: &Context) -> Result<bool> {
|
||||||
/// If `chat_id` is `Some` only that chat is checked, otherwise returns `true` if any chat
|
context
|
||||||
/// is sending locations.
|
.sql
|
||||||
pub async fn is_sending_locations_to_chat(
|
.exists(
|
||||||
context: &Context,
|
"SELECT COUNT(id) FROM chats WHERE locations_send_until>?",
|
||||||
chat_id: Option<ChatId>,
|
(time(),),
|
||||||
) -> Result<bool> {
|
)
|
||||||
let exists = match chat_id {
|
.await
|
||||||
Some(chat_id) => {
|
}
|
||||||
context
|
|
||||||
.sql
|
/// Returns whether `chat_id` is sending locations.
|
||||||
.exists(
|
pub async fn is_sending_locations_to_chat(context: &Context, chat_id: ChatId) -> Result<bool> {
|
||||||
"SELECT COUNT(id) FROM chats WHERE id=? AND locations_send_until>?;",
|
context
|
||||||
(chat_id, time()),
|
.sql
|
||||||
)
|
.exists(
|
||||||
.await?
|
"SELECT COUNT(id) FROM chats WHERE id=? AND locations_send_until>?",
|
||||||
}
|
(chat_id, time()),
|
||||||
None => {
|
)
|
||||||
context
|
.await
|
||||||
.sql
|
|
||||||
.exists(
|
|
||||||
"SELECT COUNT(id) FROM chats WHERE locations_send_until>?;",
|
|
||||||
(time(),),
|
|
||||||
)
|
|
||||||
.await?
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Ok(exists)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets current location of the user device.
|
/// Sets current location of the user device.
|
||||||
|
|||||||
@@ -1829,7 +1829,7 @@ impl MimeFactory {
|
|||||||
parts.push(msg_kml_part);
|
parts.push(msg_kml_part);
|
||||||
}
|
}
|
||||||
|
|
||||||
if location::is_sending_locations_to_chat(context, Some(msg.chat_id)).await?
|
if location::is_sending_locations_to_chat(context, msg.chat_id).await?
|
||||||
&& let Some(part) = self.get_location_kml_part(context).await?
|
&& let Some(part) = self.get_location_kml_part(context).await?
|
||||||
{
|
{
|
||||||
parts.push(part);
|
parts.push(part);
|
||||||
|
|||||||
Reference in New Issue
Block a user