mirror of
https://github.com/chatmail/core.git
synced 2026-04-05 23:22:11 +03:00
Compare commits
3 Commits
v1.156.3
...
sk/add_loc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7694bc0ba8 | ||
|
|
9f1eb45acd | ||
|
|
092b6e96ea |
@@ -2520,8 +2520,12 @@ pub unsafe extern "C" fn dc_is_sending_locations_to_chat(
|
||||
Some(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
|
||||
block_on(async {
|
||||
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]
|
||||
|
||||
@@ -629,7 +629,9 @@ 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!("{cnt} chats");
|
||||
@@ -841,7 +843,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
||||
}
|
||||
|
||||
println!(
|
||||
"Location streaming: {}",
|
||||
"Location streaming: {:?}",
|
||||
location::is_sending_locations_to_chat(
|
||||
&context,
|
||||
Some(sel_chat.as_ref().unwrap().get_id())
|
||||
|
||||
@@ -87,6 +87,17 @@ pub struct Kml {
|
||||
pub curr: Location,
|
||||
}
|
||||
|
||||
/// Location streaming status for one chat.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum LocationSendingStatus {
|
||||
/// Location streaming is disabled.
|
||||
Disabled = 0,
|
||||
/// Location streaming is enabled.
|
||||
Enabled = 1,
|
||||
/// Location streaming is enabled but (currently) not possible.
|
||||
Failure = 2,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Eq)]
|
||||
enum KmlTag {
|
||||
#[default]
|
||||
@@ -274,7 +285,8 @@ pub async fn send_locations_to_chat(
|
||||
ensure!(seconds >= 0);
|
||||
ensure!(!chat_id.is_special());
|
||||
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
|
||||
.sql
|
||||
.execute(
|
||||
@@ -314,25 +326,43 @@ pub async fn send_locations_to_chat(
|
||||
pub async fn is_sending_locations_to_chat(
|
||||
context: &Context,
|
||||
chat_id: Option<ChatId>,
|
||||
) -> Result<bool> {
|
||||
) -> Result<LocationSendingStatus> {
|
||||
let exists = match chat_id {
|
||||
Some(chat_id) => {
|
||||
context
|
||||
let enabled = context
|
||||
.sql
|
||||
.exists(
|
||||
"SELECT COUNT(id) FROM chats WHERE id=? AND locations_send_until>?;",
|
||||
(chat_id, time()),
|
||||
)
|
||||
.await?;
|
||||
let functional: i32 = context
|
||||
.sql
|
||||
.query_get_value("SELECT locations_send_begin FROM chats WHERE id=?;", ())
|
||||
.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 => {
|
||||
context
|
||||
if context
|
||||
.sql
|
||||
.exists(
|
||||
"SELECT COUNT(id) FROM chats WHERE locations_send_until>?;",
|
||||
(time(),),
|
||||
)
|
||||
.await?
|
||||
{
|
||||
LocationSendingStatus::Enabled
|
||||
} else {
|
||||
LocationSendingStatus::Disabled
|
||||
}
|
||||
}
|
||||
};
|
||||
Ok(exists)
|
||||
|
||||
@@ -20,7 +20,7 @@ use crate::e2ee::EncryptHelper;
|
||||
use crate::ephemeral::Timer as EphemeralTimer;
|
||||
use crate::headerdef::HeaderDef;
|
||||
use crate::html::new_html_mimepart;
|
||||
use crate::location;
|
||||
use crate::location::{self, LocationSendingStatus};
|
||||
use crate::message::{self, Message, MsgId, Viewtype};
|
||||
use crate::mimeparser::SystemMessage;
|
||||
use crate::param::Param;
|
||||
@@ -1372,7 +1372,9 @@ impl MimeFactory {
|
||||
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? {
|
||||
parts.push(part);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user