mirror of
https://github.com/chatmail/core.git
synced 2026-05-09 01:46:30 +03:00
feat: add location streaming failure response code
Before `is_sending_location_to_chat` returned a boolean when location was enabled or disabled for a chat. It now returns an enum value representing Enabled, disabled and failure where failure says that its enabled but (currently) not possible. This should not break cffi because 0 is still disabled, 1 enabled and new code 2 (failure) is handled similar to 1.
This commit is contained in:
@@ -2520,8 +2520,10 @@ pub unsafe extern "C" fn dc_is_sending_locations_to_chat(
|
|||||||
Some(ChatId::new(chat_id))
|
Some(ChatId::new(chat_id))
|
||||||
};
|
};
|
||||||
|
|
||||||
block_on(location::is_sending_locations_to_chat(ctx, chat_id))
|
block_on(async {
|
||||||
.unwrap_or_log_default(ctx, "Failed dc_is_sending_locations_to_chat()") as libc::c_int
|
location::is_sending_locations_to_chat(ctx, chat_id).await.map(|res| res as u8)
|
||||||
|
})
|
||||||
|
.unwrap_or_log_default(ctx, "Failed dc_is_sending_locations_to_chat()") as libc::c_int
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
|||||||
@@ -629,7 +629,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_to_chat(&context, None).await? != location::LocationSendingStatus::Disabled {
|
||||||
println!("Location streaming enabled.");
|
println!("Location streaming enabled.");
|
||||||
}
|
}
|
||||||
println!("{cnt} chats");
|
println!("{cnt} chats");
|
||||||
@@ -841,7 +841,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
|||||||
}
|
}
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"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())
|
Some(sel_chat.as_ref().unwrap().get_id())
|
||||||
|
|||||||
@@ -87,6 +87,17 @@ pub struct Kml {
|
|||||||
pub curr: Location,
|
pub curr: Location,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Location streaming status for one chat.
|
||||||
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
pub enum LocationSendingStatus {
|
||||||
|
/// Location streaming is enabled.
|
||||||
|
Enabled = 0,
|
||||||
|
/// Location streaming is disabled.
|
||||||
|
Disabled = 1,
|
||||||
|
/// Location streaming is enabled but (currently) not possible.
|
||||||
|
Failure = 2,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug, Clone, PartialEq, Eq)]
|
#[derive(Default, Debug, Clone, PartialEq, Eq)]
|
||||||
enum KmlTag {
|
enum KmlTag {
|
||||||
#[default]
|
#[default]
|
||||||
@@ -274,7 +285,8 @@ 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, Some(chat_id)).await?
|
||||||
|
== LocationSendingStatus::Enabled;
|
||||||
context
|
context
|
||||||
.sql
|
.sql
|
||||||
.execute(
|
.execute(
|
||||||
@@ -314,25 +326,43 @@ pub async fn send_locations_to_chat(
|
|||||||
pub async fn is_sending_locations_to_chat(
|
pub async fn is_sending_locations_to_chat(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
chat_id: Option<ChatId>,
|
chat_id: Option<ChatId>,
|
||||||
) -> Result<bool> {
|
) -> Result<LocationSendingStatus> {
|
||||||
let exists = match chat_id {
|
let exists = match chat_id {
|
||||||
Some(chat_id) => {
|
Some(chat_id) => {
|
||||||
context
|
let enabled = context
|
||||||
.sql
|
.sql
|
||||||
.exists(
|
.exists(
|
||||||
"SELECT COUNT(id) FROM chats WHERE id=? AND locations_send_until>?;",
|
"SELECT COUNT(id) FROM chats WHERE id=? AND locations_send_until>?;",
|
||||||
(chat_id, time()),
|
(chat_id, time()),
|
||||||
)
|
)
|
||||||
|
.await?;
|
||||||
|
let functional: i32 = context
|
||||||
|
.sql
|
||||||
|
.query_get_value("SELECT locations_send_begin FROM chats WHERE id=?;", ())
|
||||||
.await?
|
.await?
|
||||||
|
.ok_or(anyhow::anyhow!("not able to select"))?;
|
||||||
|
|
||||||
|
if enabled && functional > 0 {
|
||||||
|
LocationSendingStatus::Enabled
|
||||||
|
} else if enabled && functional == 0 {
|
||||||
|
LocationSendingStatus::Failure
|
||||||
|
} else {
|
||||||
|
LocationSendingStatus::Disabled
|
||||||
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
context
|
if context
|
||||||
.sql
|
.sql
|
||||||
.exists(
|
.exists(
|
||||||
"SELECT COUNT(id) FROM chats WHERE locations_send_until>?;",
|
"SELECT COUNT(id) FROM chats WHERE locations_send_until>?;",
|
||||||
(time(),),
|
(time(),),
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
|
{
|
||||||
|
LocationSendingStatus::Enabled
|
||||||
|
} else {
|
||||||
|
LocationSendingStatus::Disabled
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Ok(exists)
|
Ok(exists)
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ use crate::e2ee::EncryptHelper;
|
|||||||
use crate::ephemeral::Timer as EphemeralTimer;
|
use crate::ephemeral::Timer as EphemeralTimer;
|
||||||
use crate::headerdef::HeaderDef;
|
use crate::headerdef::HeaderDef;
|
||||||
use crate::html::new_html_mimepart;
|
use crate::html::new_html_mimepart;
|
||||||
use crate::location;
|
use crate::location::{self, LocationSendingStatus};
|
||||||
use crate::message::{self, Message, MsgId, Viewtype};
|
use crate::message::{self, Message, MsgId, Viewtype};
|
||||||
use crate::mimeparser::SystemMessage;
|
use crate::mimeparser::SystemMessage;
|
||||||
use crate::param::Param;
|
use crate::param::Param;
|
||||||
@@ -1372,7 +1372,9 @@ 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, Some(msg.chat_id)).await?
|
||||||
|
!= LocationSendingStatus::Disabled
|
||||||
|
{
|
||||||
if let Some(part) = self.get_location_kml_part(context).await? {
|
if let Some(part) = self.get_location_kml_part(context).await? {
|
||||||
parts.push(part);
|
parts.push(part);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user