mirror of
https://github.com/chatmail/core.git
synced 2026-05-20 15:26:30 +03:00
clean up rebase
This commit is contained in:
@@ -1,10 +1,6 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
### API-Changes
|
|
||||||
- add `debug_logging` setting #3296
|
|
||||||
|
|
||||||
### Changes
|
### Changes
|
||||||
- Disable Autocrypt & Authres-checking for mailing lists,
|
- Disable Autocrypt & Authres-checking for mailing lists,
|
||||||
because they don't work well with mailing lists #3765
|
because they don't work well with mailing lists #3765
|
||||||
@@ -17,6 +13,7 @@
|
|||||||
- Add Python API to send reactions #3762
|
- Add Python API to send reactions #3762
|
||||||
- jsonrpc: add message errors to MessageObject #3788
|
- jsonrpc: add message errors to MessageObject #3788
|
||||||
- jsonrpc: Add async Python client #3734
|
- jsonrpc: Add async Python client #3734
|
||||||
|
- add `debug_logging` setting #3296
|
||||||
|
|
||||||
### Fixes
|
### Fixes
|
||||||
- Make sure malformed messsages will never block receiving further messages anymore #3771
|
- Make sure malformed messsages will never block receiving further messages anymore #3771
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use criterion::async_executor::AsyncStdExecutor;
|
|
||||||
use criterion::{criterion_group, criterion_main, Criterion};
|
use criterion::{criterion_group, criterion_main, Criterion};
|
||||||
|
|
||||||
use deltachat::context::Context;
|
use deltachat::context::Context;
|
||||||
use deltachat::{info, Event, EventType};
|
use deltachat::stock_str::StockStrings;
|
||||||
|
use deltachat::{info, Event, EventType, Events};
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
|
|
||||||
async fn send_events_benchmark(context: &Context) {
|
async fn send_events_benchmark(context: &Context) {
|
||||||
@@ -29,11 +29,17 @@ fn criterion_benchmark(c: &mut Criterion) {
|
|||||||
let dir = tempdir().unwrap();
|
let dir = tempdir().unwrap();
|
||||||
let dbfile = dir.path().join("db.sqlite");
|
let dbfile = dir.path().join("db.sqlite");
|
||||||
let id = 100;
|
let id = 100;
|
||||||
let context =
|
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||||
async_std::task::block_on(async { Context::new(dbfile.into(), id).await.unwrap() });
|
|
||||||
|
let context = rt.block_on(async {
|
||||||
|
Context::new(&dbfile, id, Events::new(), StockStrings::new())
|
||||||
|
.await
|
||||||
|
.expect("failed to create context")
|
||||||
|
});
|
||||||
|
let executor = tokio::runtime::Runtime::new().unwrap();
|
||||||
|
|
||||||
c.bench_function("Sending 1000 events", |b| {
|
c.bench_function("Sending 1000 events", |b| {
|
||||||
b.to_async(AsyncStdExecutor)
|
b.to_async(&executor)
|
||||||
.iter(|| send_events_benchmark(&context))
|
.iter(|| send_events_benchmark(&context))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -530,47 +530,8 @@ pub unsafe extern "C" fn dc_event_get_data1_int(event: *mut dc_event_t) -> libc:
|
|||||||
eprintln!("ignoring careless call to dc_event_get_data1_int()");
|
eprintln!("ignoring careless call to dc_event_get_data1_int()");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
let event = &(*event).typ;
|
let event = &(*event).typ;
|
||||||
match event {
|
event.get_data1_int() as libc::c_int
|
||||||
EventType::Info(_)
|
|
||||||
| EventType::SmtpConnected(_)
|
|
||||||
| EventType::ImapConnected(_)
|
|
||||||
| EventType::SmtpMessageSent(_)
|
|
||||||
| EventType::ImapMessageDeleted(_)
|
|
||||||
| EventType::ImapMessageMoved(_)
|
|
||||||
| EventType::NewBlobFile(_)
|
|
||||||
| EventType::DeletedBlobFile(_)
|
|
||||||
| EventType::Warning(_)
|
|
||||||
| EventType::Error(_)
|
|
||||||
| EventType::ConnectivityChanged
|
|
||||||
| EventType::SelfavatarChanged
|
|
||||||
| EventType::IncomingMsgBunch { .. }
|
|
||||||
| EventType::ErrorSelfNotInGroup(_) => 0,
|
|
||||||
EventType::MsgsChanged { chat_id, .. }
|
|
||||||
| EventType::ReactionsChanged { chat_id, .. }
|
|
||||||
| EventType::IncomingMsg { chat_id, .. }
|
|
||||||
| EventType::MsgsNoticed(chat_id)
|
|
||||||
| EventType::MsgDelivered { chat_id, .. }
|
|
||||||
| EventType::MsgFailed { chat_id, .. }
|
|
||||||
| EventType::MsgRead { chat_id, .. }
|
|
||||||
| EventType::ChatModified(chat_id)
|
|
||||||
| EventType::ChatEphemeralTimerModified { chat_id, .. } => chat_id.to_u32() as libc::c_int,
|
|
||||||
EventType::ContactsChanged(id) | EventType::LocationChanged(id) => {
|
|
||||||
let id = id.unwrap_or_default();
|
|
||||||
id.to_u32() as libc::c_int
|
|
||||||
}
|
|
||||||
EventType::ConfigureProgress { progress, .. } | EventType::ImexProgress(progress) => {
|
|
||||||
*progress as libc::c_int
|
|
||||||
}
|
|
||||||
EventType::ImexFileWritten(_) => 0,
|
|
||||||
EventType::SecurejoinInviterProgress { contact_id, .. }
|
|
||||||
| EventType::SecurejoinJoinerProgress { contact_id, .. } => {
|
|
||||||
contact_id.to_u32() as libc::c_int
|
|
||||||
}
|
|
||||||
EventType::WebxdcStatusUpdate { msg_id, .. } => msg_id.to_u32() as libc::c_int,
|
|
||||||
EventType::WebxdcInstanceDeleted { msg_id, .. } => msg_id.to_u32() as libc::c_int,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
@@ -581,43 +542,10 @@ pub unsafe extern "C" fn dc_event_get_data2_int(event: *mut dc_event_t) -> libc:
|
|||||||
}
|
}
|
||||||
|
|
||||||
let event = &(*event).typ;
|
let event = &(*event).typ;
|
||||||
|
if let Some(data2) = event.get_data2_int() {
|
||||||
match event {
|
data2 as libc::c_int
|
||||||
EventType::Info(_)
|
} else {
|
||||||
| EventType::SmtpConnected(_)
|
0
|
||||||
| EventType::ImapConnected(_)
|
|
||||||
| EventType::SmtpMessageSent(_)
|
|
||||||
| EventType::ImapMessageDeleted(_)
|
|
||||||
| EventType::ImapMessageMoved(_)
|
|
||||||
| EventType::NewBlobFile(_)
|
|
||||||
| EventType::DeletedBlobFile(_)
|
|
||||||
| EventType::Warning(_)
|
|
||||||
| EventType::Error(_)
|
|
||||||
| EventType::ErrorSelfNotInGroup(_)
|
|
||||||
| EventType::ContactsChanged(_)
|
|
||||||
| EventType::LocationChanged(_)
|
|
||||||
| EventType::ConfigureProgress { .. }
|
|
||||||
| EventType::ImexProgress(_)
|
|
||||||
| EventType::ImexFileWritten(_)
|
|
||||||
| EventType::MsgsNoticed(_)
|
|
||||||
| EventType::ConnectivityChanged
|
|
||||||
| EventType::WebxdcInstanceDeleted { .. }
|
|
||||||
| EventType::IncomingMsgBunch { .. }
|
|
||||||
| EventType::SelfavatarChanged => 0,
|
|
||||||
EventType::ChatModified(_) => 0,
|
|
||||||
EventType::MsgsChanged { msg_id, .. }
|
|
||||||
| EventType::ReactionsChanged { msg_id, .. }
|
|
||||||
| EventType::IncomingMsg { msg_id, .. }
|
|
||||||
| EventType::MsgDelivered { msg_id, .. }
|
|
||||||
| EventType::MsgFailed { msg_id, .. }
|
|
||||||
| EventType::MsgRead { msg_id, .. } => msg_id.to_u32() as libc::c_int,
|
|
||||||
EventType::SecurejoinInviterProgress { progress, .. }
|
|
||||||
| EventType::SecurejoinJoinerProgress { progress, .. } => *progress as libc::c_int,
|
|
||||||
EventType::ChatEphemeralTimerModified { timer, .. } => timer.to_u32() as libc::c_int,
|
|
||||||
EventType::WebxdcStatusUpdate {
|
|
||||||
status_update_serial,
|
|
||||||
..
|
|
||||||
} => status_update_serial.to_u32() as libc::c_int,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -629,48 +557,25 @@ pub unsafe extern "C" fn dc_event_get_data2_str(event: *mut dc_event_t) -> *mut
|
|||||||
}
|
}
|
||||||
|
|
||||||
let event = &(*event).typ;
|
let event = &(*event).typ;
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
|
EventType::IncomingMsgBunch { msg_ids } => serde_json::to_string(msg_ids)
|
||||||
|
.unwrap_or_default()
|
||||||
|
.to_c_string()
|
||||||
|
.unwrap_or_default()
|
||||||
|
.into_raw(),
|
||||||
EventType::ImexFileWritten(file) => {
|
EventType::ImexFileWritten(file) => {
|
||||||
// Directly convert the PathBuf file to a CString, since both can contain invalid
|
// Directly convert the PathBuf file to a CString, since both can contain invalid
|
||||||
// UTF-8, but a Rust `String` can't
|
// UTF-8, but a Rust `String` can't
|
||||||
let data2 = file.to_c_string().unwrap_or_default();
|
let data2 = file.to_c_string().unwrap_or_default();
|
||||||
data2.into_raw()
|
data2.into_raw()
|
||||||
}
|
}
|
||||||
EventType::MsgsChanged { .. }
|
_ => {
|
||||||
| EventType::ReactionsChanged { .. }
|
if let Some(data2) = event.get_data2_str() {
|
||||||
| EventType::IncomingMsg { .. }
|
data2.to_c_string().unwrap_or_default().into_raw()
|
||||||
| EventType::MsgsNoticed(_)
|
|
||||||
| EventType::MsgDelivered { .. }
|
|
||||||
| EventType::MsgFailed { .. }
|
|
||||||
| EventType::MsgRead { .. }
|
|
||||||
| EventType::ChatModified(_)
|
|
||||||
| EventType::ContactsChanged(_)
|
|
||||||
| EventType::LocationChanged(_)
|
|
||||||
| EventType::ImexProgress(_)
|
|
||||||
| EventType::SecurejoinInviterProgress { .. }
|
|
||||||
| EventType::SecurejoinJoinerProgress { .. }
|
|
||||||
| EventType::ConnectivityChanged
|
|
||||||
| EventType::SelfavatarChanged
|
|
||||||
| EventType::WebxdcStatusUpdate { .. }
|
|
||||||
| EventType::WebxdcInstanceDeleted { .. }
|
|
||||||
| EventType::ChatEphemeralTimerModified { .. } => ptr::null_mut(),
|
|
||||||
EventType::ConfigureProgress { comment, .. } => {
|
|
||||||
if let Some(comment) = comment {
|
|
||||||
comment.to_c_string().unwrap_or_default().into_raw()
|
|
||||||
} else {
|
} else {
|
||||||
ptr::null_mut()
|
ptr::null_mut()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EventType::ImexFileWritten(file) => {
|
|
||||||
let data2 = file.to_c_string().unwrap_or_default();
|
|
||||||
data2.into_raw()
|
|
||||||
}
|
|
||||||
EventType::IncomingMsgBunch { msg_ids } => serde_json::to_string(msg_ids)
|
|
||||||
.unwrap_or_default()
|
|
||||||
.to_c_string()
|
|
||||||
.unwrap_or_default()
|
|
||||||
.into_raw(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ use crate::message::{self, Message, MsgId, Viewtype};
|
|||||||
use crate::mimefactory::RECOMMENDED_FILE_SIZE;
|
use crate::mimefactory::RECOMMENDED_FILE_SIZE;
|
||||||
use crate::provider::{get_provider_by_id, Provider};
|
use crate::provider::{get_provider_by_id, Provider};
|
||||||
use crate::tools::{get_abs_path, improve_single_line_input, EmailAddress};
|
use crate::tools::{get_abs_path, improve_single_line_input, EmailAddress};
|
||||||
use crate::{chat, webxdc};
|
|
||||||
|
|
||||||
/// The available configuration keys.
|
/// The available configuration keys.
|
||||||
#[derive(
|
#[derive(
|
||||||
@@ -197,7 +196,7 @@ pub enum Config {
|
|||||||
///
|
///
|
||||||
/// See `crate::authres::update_authservid_candidates`.
|
/// See `crate::authres::update_authservid_candidates`.
|
||||||
AuthservIdCandidates,
|
AuthservIdCandidates,
|
||||||
|
|
||||||
// TODO docs, deltachat.h
|
// TODO docs, deltachat.h
|
||||||
/// Let the core save all events to the database. You should expose this as an advanced
|
/// Let the core save all events to the database. You should expose this as an advanced
|
||||||
/// setting to the user. When they enable it, the core automatically adds a webxdc
|
/// setting to the user. When they enable it, the core automatically adds a webxdc
|
||||||
@@ -336,15 +335,15 @@ impl Context {
|
|||||||
Config::DebugLogging => {
|
Config::DebugLogging => {
|
||||||
if value == Some("0") || value == Some("") || value == None {
|
if value == Some("0") || value == Some("") || value == None {
|
||||||
if let Some(webxdc_message_id) =
|
if let Some(webxdc_message_id) =
|
||||||
self.sql.get_raw_config_u32(Config::DebugLogging).await?
|
self.sql.get_raw_config_u32(Config::DebugLogging.as_ref()).await?
|
||||||
{
|
{
|
||||||
message::delete_msgs(self, &[MsgId::new(webxdc_message_id)]).await?;
|
message::delete_msgs(self, &[MsgId::new(webxdc_message_id)]).await?;
|
||||||
}
|
}
|
||||||
self.sql.set_raw_config(key, None).await?;
|
self.sql.set_raw_config(key.as_ref(), None).await?;
|
||||||
self.debug_logging.store(0, atomic::Ordering::Relaxed);
|
self.debug_logging.store(0, atomic::Ordering::Relaxed);
|
||||||
} else if self
|
} else if self
|
||||||
.sql
|
.sql
|
||||||
.get_raw_config_u32(Config::DebugLogging)
|
.get_raw_config_u32(Config::DebugLogging.as_ref())
|
||||||
.await?
|
.await?
|
||||||
.unwrap_or(0)
|
.unwrap_or(0)
|
||||||
== 0
|
== 0
|
||||||
@@ -360,7 +359,7 @@ impl Context {
|
|||||||
);
|
);
|
||||||
let msg_id = chat::add_device_msg(self, None, Some(&mut instance)).await?;
|
let msg_id = chat::add_device_msg(self, None, Some(&mut instance)).await?;
|
||||||
self.sql
|
self.sql
|
||||||
.set_raw_config(key, Some(&msg_id.to_u32().to_string()))
|
.set_raw_config(key.as_ref(), Some(&msg_id.to_u32().to_string()))
|
||||||
.await?;
|
.await?;
|
||||||
self.debug_logging
|
self.debug_logging
|
||||||
.store(msg_id.to_u32(), atomic::Ordering::Relaxed);
|
.store(msg_id.to_u32(), atomic::Ordering::Relaxed);
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ pub struct InnerContext {
|
|||||||
/// The text of the last error logged and emitted as an event.
|
/// The text of the last error logged and emitted as an event.
|
||||||
/// If the ui wants to display an error after a failure,
|
/// If the ui wants to display an error after a failure,
|
||||||
/// `last_error` should be used to avoid races with the event thread.
|
/// `last_error` should be used to avoid races with the event thread.
|
||||||
pub(crate) last_error: RwLock<String>,
|
pub(crate) last_error: std::sync::RwLock<String>,
|
||||||
|
|
||||||
pub(crate) debug_logging: AtomicU32,
|
pub(crate) debug_logging: AtomicU32,
|
||||||
}
|
}
|
||||||
@@ -364,7 +364,7 @@ impl Context {
|
|||||||
server_id: RwLock::new(None),
|
server_id: RwLock::new(None),
|
||||||
creation_time: std::time::SystemTime::now(),
|
creation_time: std::time::SystemTime::now(),
|
||||||
last_full_folder_scan: Mutex::new(None),
|
last_full_folder_scan: Mutex::new(None),
|
||||||
last_error: RwLock::new("".to_string()),
|
last_error: std::sync::RwLock::new("".to_string()),
|
||||||
debug_logging: AtomicU32::default(),
|
debug_logging: AtomicU32::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -464,7 +464,8 @@ impl Context {
|
|||||||
.as_millis() as i64;
|
.as_millis() as i64;
|
||||||
|
|
||||||
let context = self.clone();
|
let context = self.clone();
|
||||||
async_std::task::block_on(async move {
|
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||||
|
rt.block_on(async move {
|
||||||
let webxdc_instance_id = MsgId::new(debug_logging as u32);
|
let webxdc_instance_id = MsgId::new(debug_logging as u32);
|
||||||
|
|
||||||
match context
|
match context
|
||||||
|
|||||||
@@ -2,11 +2,9 @@
|
|||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use async_std::channel::{self, Receiver, Sender, TrySendError};
|
use async_channel::{self as channel, Receiver, Sender, TrySendError};
|
||||||
use async_std::path::PathBuf;
|
|
||||||
use num_traits::ToPrimitive;
|
use num_traits::ToPrimitive;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use strum::EnumProperty;
|
|
||||||
|
|
||||||
use crate::chat::ChatId;
|
use crate::chat::ChatId;
|
||||||
use crate::contact::ContactId;
|
use crate::contact::ContactId;
|
||||||
@@ -110,27 +108,7 @@ pub struct Event {
|
|||||||
pub typ: EventType,
|
pub typ: EventType,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deref for Event {
|
#[derive(Debug, Clone, PartialEq, Eq, Display)]
|
||||||
type Target = EventType;
|
|
||||||
|
|
||||||
fn deref(&self) -> &EventType {
|
|
||||||
&self.typ
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EventType {
|
|
||||||
/// Returns the corresponding Event ID.
|
|
||||||
///
|
|
||||||
/// These are the IDs used in the `DC_EVENT_*` constants in `deltachat.h`.
|
|
||||||
pub fn as_id(&self) -> i32 {
|
|
||||||
self.get_str("id")
|
|
||||||
.expect("missing id")
|
|
||||||
.parse()
|
|
||||||
.expect("invalid id")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, EnumProperty, Display)]
|
|
||||||
pub enum EventType {
|
pub enum EventType {
|
||||||
/// The library-user may write an informational string to the log.
|
/// The library-user may write an informational string to the log.
|
||||||
///
|
///
|
||||||
@@ -309,7 +287,7 @@ pub enum EventType {
|
|||||||
/// 1000=Protocol finished for this contact.
|
/// 1000=Protocol finished for this contact.
|
||||||
SecurejoinInviterProgress {
|
SecurejoinInviterProgress {
|
||||||
contact_id: ContactId,
|
contact_id: ContactId,
|
||||||
progress: u32,
|
progress: usize,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Progress information of a secure-join handshake from the view of the joiner
|
/// Progress information of a secure-join handshake from the view of the joiner
|
||||||
@@ -322,7 +300,7 @@ pub enum EventType {
|
|||||||
/// (Bob has verified alice and waits until Alice does the same for him)
|
/// (Bob has verified alice and waits until Alice does the same for him)
|
||||||
SecurejoinJoinerProgress {
|
SecurejoinJoinerProgress {
|
||||||
contact_id: ContactId,
|
contact_id: ContactId,
|
||||||
progress: u32,
|
progress: usize,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// The connectivity to the server changed.
|
/// The connectivity to the server changed.
|
||||||
@@ -345,12 +323,6 @@ pub enum EventType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl EventType {
|
impl EventType {
|
||||||
/// Get data associated with an event object.
|
|
||||||
/// This is meant to be used for the FFI and serializing; Rust code
|
|
||||||
/// can usually just match on the EventType.
|
|
||||||
///
|
|
||||||
/// data1 is always an int.
|
|
||||||
/// For events that have no number associacted with them, this returns 0.
|
|
||||||
pub fn get_data1_int(&self) -> u32 {
|
pub fn get_data1_int(&self) -> u32 {
|
||||||
match self {
|
match self {
|
||||||
EventType::Info(_)
|
EventType::Info(_)
|
||||||
@@ -365,9 +337,10 @@ impl EventType {
|
|||||||
| EventType::Error(_)
|
| EventType::Error(_)
|
||||||
| EventType::ConnectivityChanged
|
| EventType::ConnectivityChanged
|
||||||
| EventType::SelfavatarChanged
|
| EventType::SelfavatarChanged
|
||||||
| EventType::ErrorSelfNotInGroup(_)
|
| EventType::IncomingMsgBunch { .. }
|
||||||
| EventType::ImexFileWritten(_) => 0,
|
| EventType::ErrorSelfNotInGroup(_) => 0,
|
||||||
EventType::MsgsChanged { chat_id, .. }
|
EventType::MsgsChanged { chat_id, .. }
|
||||||
|
| EventType::ReactionsChanged { chat_id, .. }
|
||||||
| EventType::IncomingMsg { chat_id, .. }
|
| EventType::IncomingMsg { chat_id, .. }
|
||||||
| EventType::MsgsNoticed(chat_id)
|
| EventType::MsgsNoticed(chat_id)
|
||||||
| EventType::MsgDelivered { chat_id, .. }
|
| EventType::MsgDelivered { chat_id, .. }
|
||||||
@@ -376,25 +349,19 @@ impl EventType {
|
|||||||
| EventType::ChatModified(chat_id)
|
| EventType::ChatModified(chat_id)
|
||||||
| EventType::ChatEphemeralTimerModified { chat_id, .. } => chat_id.to_u32(),
|
| EventType::ChatEphemeralTimerModified { chat_id, .. } => chat_id.to_u32(),
|
||||||
EventType::ContactsChanged(id) | EventType::LocationChanged(id) => {
|
EventType::ContactsChanged(id) | EventType::LocationChanged(id) => {
|
||||||
let id = id.unwrap_or_default();
|
id.unwrap_or_default().to_u32()
|
||||||
id.to_u32()
|
|
||||||
}
|
}
|
||||||
EventType::ConfigureProgress { progress, .. } | EventType::ImexProgress(progress) => {
|
EventType::ConfigureProgress { progress, .. } | EventType::ImexProgress(progress) => {
|
||||||
progress.to_u32().unwrap_or_default()
|
(*progress).to_u32().unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
EventType::ImexFileWritten(_) => 0,
|
||||||
EventType::SecurejoinInviterProgress { contact_id, .. }
|
EventType::SecurejoinInviterProgress { contact_id, .. }
|
||||||
| EventType::SecurejoinJoinerProgress { contact_id, .. } => contact_id.to_u32(),
|
| EventType::SecurejoinJoinerProgress { contact_id, .. } => contact_id.to_u32(),
|
||||||
EventType::WebxdcStatusUpdate { msg_id, .. } => msg_id.to_u32(),
|
EventType::WebxdcStatusUpdate { msg_id, .. } => msg_id.to_u32(),
|
||||||
|
EventType::WebxdcInstanceDeleted { msg_id, .. } => msg_id.to_u32(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get data associated with an event object.
|
|
||||||
///
|
|
||||||
/// data2 sometimes is a string and sometimes an int; if it's a string or
|
|
||||||
/// there is no data2, this function returns `None`.
|
|
||||||
///
|
|
||||||
/// This is meant to be used for the FFI and serializing; Rust code
|
|
||||||
/// can usually just `match` the EventType.
|
|
||||||
pub fn get_data2_int(&self) -> Option<u32> {
|
pub fn get_data2_int(&self) -> Option<u32> {
|
||||||
match self {
|
match self {
|
||||||
EventType::Info(_)
|
EventType::Info(_)
|
||||||
@@ -415,15 +382,18 @@ impl EventType {
|
|||||||
| EventType::ImexFileWritten(_)
|
| EventType::ImexFileWritten(_)
|
||||||
| EventType::MsgsNoticed(_)
|
| EventType::MsgsNoticed(_)
|
||||||
| EventType::ConnectivityChanged
|
| EventType::ConnectivityChanged
|
||||||
| EventType::SelfavatarChanged
|
| EventType::WebxdcInstanceDeleted { .. }
|
||||||
| EventType::ChatModified(_) => None,
|
| EventType::IncomingMsgBunch { .. }
|
||||||
|
| EventType::ChatModified(_)
|
||||||
|
| EventType::SelfavatarChanged => None,
|
||||||
EventType::MsgsChanged { msg_id, .. }
|
EventType::MsgsChanged { msg_id, .. }
|
||||||
|
| EventType::ReactionsChanged { msg_id, .. }
|
||||||
| EventType::IncomingMsg { msg_id, .. }
|
| EventType::IncomingMsg { msg_id, .. }
|
||||||
| EventType::MsgDelivered { msg_id, .. }
|
| EventType::MsgDelivered { msg_id, .. }
|
||||||
| EventType::MsgFailed { msg_id, .. }
|
| EventType::MsgFailed { msg_id, .. }
|
||||||
| EventType::MsgRead { msg_id, .. } => Some(msg_id.to_u32()),
|
| EventType::MsgRead { msg_id, .. } => Some(msg_id.to_u32()),
|
||||||
EventType::SecurejoinInviterProgress { progress, .. }
|
EventType::SecurejoinInviterProgress { progress, .. }
|
||||||
| EventType::SecurejoinJoinerProgress { progress, .. } => Some(*progress),
|
| EventType::SecurejoinJoinerProgress { progress, .. } => (*progress).to_u32(),
|
||||||
EventType::ChatEphemeralTimerModified { timer, .. } => Some(timer.to_u32()),
|
EventType::ChatEphemeralTimerModified { timer, .. } => Some(timer.to_u32()),
|
||||||
EventType::WebxdcStatusUpdate {
|
EventType::WebxdcStatusUpdate {
|
||||||
status_update_serial,
|
status_update_serial,
|
||||||
@@ -432,13 +402,6 @@ impl EventType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get data associated with an event object.
|
|
||||||
///
|
|
||||||
/// data2 sometimes is a string and sometimes an int; if it's an int or
|
|
||||||
/// there is no data2, this function returns `None`.
|
|
||||||
///
|
|
||||||
/// This is meant to be used for the FFI and serializing; Rust code
|
|
||||||
/// can usually just `match` the EventType.
|
|
||||||
pub fn get_data2_str(&self) -> Option<&str> {
|
pub fn get_data2_str(&self) -> Option<&str> {
|
||||||
match self {
|
match self {
|
||||||
EventType::Info(msg)
|
EventType::Info(msg)
|
||||||
@@ -453,6 +416,7 @@ impl EventType {
|
|||||||
| EventType::Error(msg)
|
| EventType::Error(msg)
|
||||||
| EventType::ErrorSelfNotInGroup(msg) => Some(msg),
|
| EventType::ErrorSelfNotInGroup(msg) => Some(msg),
|
||||||
EventType::MsgsChanged { .. }
|
EventType::MsgsChanged { .. }
|
||||||
|
| EventType::ReactionsChanged { .. }
|
||||||
| EventType::IncomingMsg { .. }
|
| EventType::IncomingMsg { .. }
|
||||||
| EventType::MsgsNoticed(_)
|
| EventType::MsgsNoticed(_)
|
||||||
| EventType::MsgDelivered { .. }
|
| EventType::MsgDelivered { .. }
|
||||||
@@ -467,10 +431,20 @@ impl EventType {
|
|||||||
| EventType::ConnectivityChanged
|
| EventType::ConnectivityChanged
|
||||||
| EventType::SelfavatarChanged
|
| EventType::SelfavatarChanged
|
||||||
| EventType::WebxdcStatusUpdate { .. }
|
| EventType::WebxdcStatusUpdate { .. }
|
||||||
|
| EventType::WebxdcInstanceDeleted { .. }
|
||||||
| EventType::ChatEphemeralTimerModified { .. } => None,
|
| EventType::ChatEphemeralTimerModified { .. } => None,
|
||||||
EventType::ConfigureProgress { comment, .. } => comment.as_deref(),
|
EventType::ConfigureProgress { comment, .. } => {
|
||||||
// Note that `PathBuf::to_str()` returns None for invalid UTF-8:
|
if let Some(comment) = comment {
|
||||||
|
Some(comment)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
EventType::ImexFileWritten(file) => file.to_str(),
|
EventType::ImexFileWritten(file) => file.to_str(),
|
||||||
|
EventType::IncomingMsgBunch { .. } => {
|
||||||
|
//serde_json::to_string(msg_ids).ok().map(|str| str.as_str())
|
||||||
|
Some("fix me!!")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1286,7 +1286,7 @@ pub async fn delete_msgs(context: &Context, msg_ids: &[MsgId]) -> Result<()> {
|
|||||||
if context.get_config(Config::DebugLogging).await? == Some(msg_id.to_u32().to_string()) {
|
if context.get_config(Config::DebugLogging).await? == Some(msg_id.to_u32().to_string()) {
|
||||||
context
|
context
|
||||||
.sql
|
.sql
|
||||||
.set_raw_config(Config::DebugLogging, None)
|
.set_raw_config(Config::DebugLogging.as_ref(), None)
|
||||||
.await?;
|
.await?;
|
||||||
context.debug_logging.store(0, atomic::Ordering::Relaxed);
|
context.debug_logging.store(0, atomic::Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
@@ -1300,7 +1300,7 @@ pub async fn delete_msgs(context: &Context, msg_ids: &[MsgId]) -> Result<()> {
|
|||||||
// wouldn't compile ("recursion in an `async fn`")
|
// wouldn't compile ("recursion in an `async fn`")
|
||||||
context
|
context
|
||||||
.sql
|
.sql
|
||||||
.set_raw_config(Config::LastHousekeeping, None)
|
.set_raw_config(Config::LastHousekeeping.as_ref(), None)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -243,7 +243,7 @@ enum JoinerProgress {
|
|||||||
// Succeeded,
|
// Succeeded,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<JoinerProgress> for u32 {
|
impl From<JoinerProgress> for usize {
|
||||||
fn from(progress: JoinerProgress) -> Self {
|
fn from(progress: JoinerProgress) -> Self {
|
||||||
match progress {
|
match progress {
|
||||||
JoinerProgress::Error => 0,
|
JoinerProgress::Error => 0,
|
||||||
|
|||||||
@@ -343,7 +343,9 @@ impl Sql {
|
|||||||
info!(context, "Opened database {:?}.", self.dbfile);
|
info!(context, "Opened database {:?}.", self.dbfile);
|
||||||
*self.is_encrypted.write().await = Some(passphrase_nonempty);
|
*self.is_encrypted.write().await = Some(passphrase_nonempty);
|
||||||
|
|
||||||
let debug_logging = self.get_raw_config_u32(Config::DebugLogging).await?;
|
let debug_logging = self
|
||||||
|
.get_raw_config_u32(Config::DebugLogging.as_ref())
|
||||||
|
.await?;
|
||||||
context
|
context
|
||||||
.debug_logging
|
.debug_logging
|
||||||
.store(debug_logging.unwrap_or(0), atomic::Ordering::Relaxed);
|
.store(debug_logging.unwrap_or(0), atomic::Ordering::Relaxed);
|
||||||
@@ -599,13 +601,13 @@ impl Sql {
|
|||||||
.map(|s| s.and_then(|s| s.parse().ok()))
|
.map(|s| s.and_then(|s| s.parse().ok()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_raw_config_bool(&self, key: &str) -> Result<bool> {
|
pub async fn get_raw_config_u32(&self, key: &str) -> Result<Option<u32>> {
|
||||||
self.get_raw_config(key)
|
self.get_raw_config(key)
|
||||||
.await
|
.await
|
||||||
.map(|s| s.and_then(|s| s.parse().ok()))
|
.map(|s| s.and_then(|s| s.parse().ok()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_raw_config_bool(&self, key: impl AsRef<str>) -> Result<bool> {
|
pub async fn get_raw_config_bool(&self, key: &str) -> Result<bool> {
|
||||||
// Not the most obvious way to encode bool as string, but it is matter
|
// Not the most obvious way to encode bool as string, but it is matter
|
||||||
// of backward compatibility.
|
// of backward compatibility.
|
||||||
let res = self.get_raw_config_int(key).await?;
|
let res = self.get_raw_config_int(key).await?;
|
||||||
|
|||||||
@@ -327,8 +327,6 @@ impl Context {
|
|||||||
.write_status_update_inner(&instance.id, status_update_item)
|
.write_status_update_inner(&instance.id, status_update_item)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let status_update_serial = StatusUpdateSerial(u32::try_from(rowid)?);
|
|
||||||
|
|
||||||
if instance.viewtype == Viewtype::Webxdc {
|
if instance.viewtype == Viewtype::Webxdc {
|
||||||
self.emit_event(EventType::WebxdcStatusUpdate {
|
self.emit_event(EventType::WebxdcStatusUpdate {
|
||||||
msg_id: instance.id,
|
msg_id: instance.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user