add delete event for webxdc

This commit is contained in:
Sebastian Klähn
2022-09-10 19:27:20 +02:00
parent 7cff681234
commit 24d9345ea0
4 changed files with 27 additions and 0 deletions

View File

@@ -504,6 +504,7 @@ pub unsafe extern "C" fn dc_event_get_id(event: *mut dc_event_t) -> libc::c_int
EventType::ConnectivityChanged => 2100, EventType::ConnectivityChanged => 2100,
EventType::SelfavatarChanged => 2110, EventType::SelfavatarChanged => 2110,
EventType::WebxdcStatusUpdate { .. } => 2120, EventType::WebxdcStatusUpdate { .. } => 2120,
EventType::WebXdInstanceDeleted { .. } => 2121,
} }
} }
@@ -550,6 +551,7 @@ pub unsafe extern "C" fn dc_event_get_data1_int(event: *mut dc_event_t) -> libc:
contact_id.to_u32() as libc::c_int contact_id.to_u32() as libc::c_int
} }
EventType::WebxdcStatusUpdate { msg_id, .. } => msg_id.to_u32() as libc::c_int, EventType::WebxdcStatusUpdate { msg_id, .. } => msg_id.to_u32() as libc::c_int,
EventType::WebXdInstanceDeleted { msg_id, .. } => msg_id.to_u32() as libc::c_int,
} }
} }
@@ -581,6 +583,7 @@ pub unsafe extern "C" fn dc_event_get_data2_int(event: *mut dc_event_t) -> libc:
| EventType::ImexFileWritten(_) | EventType::ImexFileWritten(_)
| EventType::MsgsNoticed(_) | EventType::MsgsNoticed(_)
| EventType::ConnectivityChanged | EventType::ConnectivityChanged
| EventType::WebXdInstanceDeleted { .. }
| EventType::SelfavatarChanged => 0, | EventType::SelfavatarChanged => 0,
EventType::ChatModified(_) => 0, EventType::ChatModified(_) => 0,
EventType::MsgsChanged { msg_id, .. } EventType::MsgsChanged { msg_id, .. }
@@ -637,6 +640,7 @@ pub unsafe extern "C" fn dc_event_get_data2_str(event: *mut dc_event_t) -> *mut
| EventType::ConnectivityChanged | EventType::ConnectivityChanged
| EventType::SelfavatarChanged | EventType::SelfavatarChanged
| EventType::WebxdcStatusUpdate { .. } | EventType::WebxdcStatusUpdate { .. }
| EventType::WebXdInstanceDeleted { .. }
| EventType::ChatEphemeralTimerModified { .. } => ptr::null_mut(), | EventType::ChatEphemeralTimerModified { .. } => ptr::null_mut(),
EventType::ConfigureProgress { comment, .. } => { EventType::ConfigureProgress { comment, .. } => {
if let Some(comment) = comment { if let Some(comment) = comment {

View File

@@ -302,4 +302,9 @@ pub enum EventType {
msg_id: MsgId, msg_id: MsgId,
status_update_serial: StatusUpdateSerial, status_update_serial: StatusUpdateSerial,
}, },
/// Inform that an instance cointaining a webxdc has been deleted
WebXdInstanceDeleted {
msg_id: MsgId,
},
} }

View File

@@ -1236,6 +1236,9 @@ pub async fn delete_msgs(context: &Context, msg_ids: &[MsgId]) -> Result<()> {
.trash(context) .trash(context)
.await .await
.with_context(|| format!("Unable to trash message {}", msg_id))?; .with_context(|| format!("Unable to trash message {}", msg_id))?;
context.emit_event(EventType::WebXdInstanceDeleted { msg_id: *msg_id });
context context
.sql .sql
.execute( .execute(

View File

@@ -753,6 +753,7 @@ mod tests {
use crate::chatlist::Chatlist; use crate::chatlist::Chatlist;
use crate::config::Config; use crate::config::Config;
use crate::contact::Contact; use crate::contact::Contact;
use crate::message;
use crate::receive_imf::{receive_imf, receive_imf_inner}; use crate::receive_imf::{receive_imf, receive_imf_inner};
use crate::test_utils::TestContext; use crate::test_utils::TestContext;
@@ -2377,4 +2378,18 @@ sth_for_the = "future""#
); );
Ok(()) Ok(())
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_webxdc_delete_event() -> Result<()> {
let alice = TestContext::new_alice().await;
let chat_id = create_group_chat(&alice, ProtectionStatus::Unprotected, "foo").await?;
let instance = send_webxdc_instance(&alice, chat_id).await?;
//let msg_id = alice.pop_sent_msg().await;
message::delete_msgs(&alice, &[instance.id]).await?;
alice
.evtracker
.get_matching(|evt| matches!(evt, EventType::WebXdInstanceDeleted { .. }))
.await;
Ok(())
}
} }