From 087a9231dd35b5669ed67c6f0e39e800f2a2f70b Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Tue, 26 Nov 2024 16:27:57 +0100 Subject: [PATCH] add href to IncomingWebxdcNotify event --- deltachat-ffi/deltachat.h | 27 +++++++++++++++++------ deltachat-ffi/src/lib.rs | 23 +++++++++++++++++++ deltachat-jsonrpc/src/api/types/events.rs | 3 +++ src/events/payload.rs | 3 +++ src/webxdc.rs | 4 +++- 5 files changed, 52 insertions(+), 8 deletions(-) diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index 55dd895bd5..fe79cf78dc 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -5901,15 +5901,26 @@ int dc_event_get_data2_int(dc_event_t* event); /** * Get data associated with an event object. - * The meaning of the data depends on the event ID - * returned as @ref DC_EVENT constants by dc_event_get_id(). - * See also dc_event_get_data1_int() and dc_event_get_data2_int(). + * The meaning of the data depends on the event ID returned as @ref DC_EVENT constants. * * @memberof dc_event_t * @param event Event object as returned from dc_get_next_event(). - * @return "data2" as a string or NULL. - * the meaning depends on the event type associated with this event. - * Once you're done with the string, you have to unref it using dc_unref_str(). + * @return "data1" string or NULL. + * The meaning depends on the event type associated with this event. + * Must be freed using dc_str_unref(). + */ +char* dc_event_get_data1_str(dc_event_t* event); + + +/** + * Get data associated with an event object. + * The meaning of the data depends on the event ID returned as @ref DC_EVENT constants. + * + * @memberof dc_event_t + * @param event Event object as returned from dc_get_next_event(). + * @return "data2" string or NULL. + * The meaning depends on the event type associated with this event. + * Must be freed using dc_str_unref(). */ char* dc_event_get_data2_str(dc_event_t* event); @@ -6111,7 +6122,9 @@ void dc_event_unref(dc_event_t* event); /** * A webxdc wants an info message or a changed summary to be notified. * - * @param data1 contact_id ID of the contact sending. + * @param data1 (int) contact_id ID _and_ (char*) href. + * - contact_id returned by dc_event_get_data1_int(). + * - href returned by dc_event_get_data1_str(). * @param data2 (int) msg_id _and_ (char*) text_to_notify. * - dc_event_get_data2_int() returns the msg_id, * referring to the webxdc-info-message, if there is any. diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index 090ffe359f..aa2a2c20d0 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -709,6 +709,29 @@ pub unsafe extern "C" fn dc_event_get_data2_int(event: *mut dc_event_t) -> libc: } } +#[no_mangle] +pub unsafe extern "C" fn dc_event_get_data1_str(event: *mut dc_event_t) -> *mut libc::c_char { + if event.is_null() { + eprintln!("ignoring careless call to dc_event_get_data1_str()"); + return ptr::null_mut(); + } + + let event = &(*event).typ; + + match event { + EventType::IncomingWebxdcNotify { href, .. } => { + if let Some(href) = href { + href.to_c_string().unwrap_or_default().into_raw() + } else { + ptr::null_mut() + } + } + #[allow(unreachable_patterns)] + #[cfg(test)] + _ => unreachable!("This is just to silence a rust_analyzer false-positive"), + } +} + #[no_mangle] pub unsafe extern "C" fn dc_event_get_data2_str(event: *mut dc_event_t) -> *mut libc::c_char { if event.is_null() { diff --git a/deltachat-jsonrpc/src/api/types/events.rs b/deltachat-jsonrpc/src/api/types/events.rs index 254463d4de..a04dd17add 100644 --- a/deltachat-jsonrpc/src/api/types/events.rs +++ b/deltachat-jsonrpc/src/api/types/events.rs @@ -112,6 +112,7 @@ pub enum EventType { contact_id: u32, msg_id: u32, text: String, + href: Option }, /// There is a fresh message. Typically, the user will show an notification @@ -345,10 +346,12 @@ impl From for EventType { contact_id, msg_id, text, + href, } => IncomingWebxdcNotify { contact_id: contact_id.to_u32(), msg_id: msg_id.to_u32(), text, + href, }, CoreEventType::IncomingMsg { chat_id, msg_id } => IncomingMsg { chat_id: chat_id.to_u32(), diff --git a/src/events/payload.rs b/src/events/payload.rs index 40634f0644..2707e6cd39 100644 --- a/src/events/payload.rs +++ b/src/events/payload.rs @@ -117,6 +117,9 @@ pub enum EventType { /// Text to notify. text: String, + + /// Link assigned to this notification, if any. + href: Option, }, /// There is a fresh message. Typically, the user will show an notification diff --git a/src/webxdc.rs b/src/webxdc.rs index 2933bcba5b..f012922990 100644 --- a/src/webxdc.rs +++ b/src/webxdc.rs @@ -393,7 +393,7 @@ impl Context { .await?; } - if let Some(href) = status_update_item.href { + if let Some(ref href) = status_update_item.href { let mut notify_msg = Message::load_from_db(self, notify_msg_id).await?; notify_msg.param.set(Param::Arg, href); notify_msg.update_param(self).await?; @@ -421,12 +421,14 @@ impl Context { contact_id: from_id, msg_id: notify_msg_id, text: notify_text.clone(), + href: status_update_item.href, }); } else if let Some(notify_text) = notify_list.get("*") { self.emit_event(EventType::IncomingWebxdcNotify { contact_id: from_id, msg_id: notify_msg_id, text: notify_text.clone(), + href: status_update_item.href, }); } }