Skip to content

Commit ba68b87

Browse files
authored
feat: add href to IncomingWebxdcNotify event (#6266)
this PR adds the `href` from `update.href` to the IncomingWebxdcNotify event (DC_EVENT_INCOMING_WEBXDC_NOTIFY in cffi) purpose is to add a "Start" button to the notifications that allow starting the app immediately with the given href
1 parent b5f8995 commit ba68b87

File tree

5 files changed

+50
-8
lines changed

5 files changed

+50
-8
lines changed

deltachat-ffi/deltachat.h

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5901,15 +5901,26 @@ int dc_event_get_data2_int(dc_event_t* event);
59015901

59025902
/**
59035903
* Get data associated with an event object.
5904-
* The meaning of the data depends on the event ID
5905-
* returned as @ref DC_EVENT constants by dc_event_get_id().
5906-
* See also dc_event_get_data1_int() and dc_event_get_data2_int().
5904+
* The meaning of the data depends on the event ID returned as @ref DC_EVENT constants.
59075905
*
59085906
* @memberof dc_event_t
59095907
* @param event Event object as returned from dc_get_next_event().
5910-
* @return "data2" as a string or NULL.
5911-
* the meaning depends on the event type associated with this event.
5912-
* Once you're done with the string, you have to unref it using dc_unref_str().
5908+
* @return "data1" string or NULL.
5909+
* The meaning depends on the event type associated with this event.
5910+
* Must be freed using dc_str_unref().
5911+
*/
5912+
char* dc_event_get_data1_str(dc_event_t* event);
5913+
5914+
5915+
/**
5916+
* Get data associated with an event object.
5917+
* The meaning of the data depends on the event ID returned as @ref DC_EVENT constants.
5918+
*
5919+
* @memberof dc_event_t
5920+
* @param event Event object as returned from dc_get_next_event().
5921+
* @return "data2" string or NULL.
5922+
* The meaning depends on the event type associated with this event.
5923+
* Must be freed using dc_str_unref().
59135924
*/
59145925
char* dc_event_get_data2_str(dc_event_t* event);
59155926

@@ -6111,7 +6122,9 @@ void dc_event_unref(dc_event_t* event);
61116122
/**
61126123
* A webxdc wants an info message or a changed summary to be notified.
61136124
*
6114-
* @param data1 contact_id ID of the contact sending.
6125+
* @param data1 (int) contact_id ID _and_ (char*) href.
6126+
* - dc_event_get_data1_int() returns contact_id of the sending contact.
6127+
* - dc_event_get_data1_str() returns the href as set to `update.href`.
61156128
* @param data2 (int) msg_id _and_ (char*) text_to_notify.
61166129
* - dc_event_get_data2_int() returns the msg_id,
61176130
* referring to the webxdc-info-message, if there is any.

deltachat-ffi/src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,27 @@ pub unsafe extern "C" fn dc_event_get_data2_int(event: *mut dc_event_t) -> libc:
709709
}
710710
}
711711

712+
#[no_mangle]
713+
pub unsafe extern "C" fn dc_event_get_data1_str(event: *mut dc_event_t) -> *mut libc::c_char {
714+
if event.is_null() {
715+
eprintln!("ignoring careless call to dc_event_get_data1_str()");
716+
return ptr::null_mut();
717+
}
718+
719+
let event = &(*event).typ;
720+
721+
match event {
722+
EventType::IncomingWebxdcNotify { href, .. } => {
723+
if let Some(href) = href {
724+
href.to_c_string().unwrap_or_default().into_raw()
725+
} else {
726+
ptr::null_mut()
727+
}
728+
}
729+
_ => ptr::null_mut(),
730+
}
731+
}
732+
712733
#[no_mangle]
713734
pub unsafe extern "C" fn dc_event_get_data2_str(event: *mut dc_event_t) -> *mut libc::c_char {
714735
if event.is_null() {

deltachat-jsonrpc/src/api/types/events.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ pub enum EventType {
112112
contact_id: u32,
113113
msg_id: u32,
114114
text: String,
115+
href: Option<String>,
115116
},
116117

117118
/// There is a fresh message. Typically, the user will show an notification
@@ -345,10 +346,12 @@ impl From<CoreEventType> for EventType {
345346
contact_id,
346347
msg_id,
347348
text,
349+
href,
348350
} => IncomingWebxdcNotify {
349351
contact_id: contact_id.to_u32(),
350352
msg_id: msg_id.to_u32(),
351353
text,
354+
href,
352355
},
353356
CoreEventType::IncomingMsg { chat_id, msg_id } => IncomingMsg {
354357
chat_id: chat_id.to_u32(),

src/events/payload.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ pub enum EventType {
117117

118118
/// Text to notify.
119119
text: String,
120+
121+
/// Link assigned to this notification, if any.
122+
href: Option<String>,
120123
},
121124

122125
/// There is a fresh message. Typically, the user will show an notification

src/webxdc.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ impl Context {
393393
.await?;
394394
}
395395

396-
if let Some(href) = status_update_item.href {
396+
if let Some(ref href) = status_update_item.href {
397397
let mut notify_msg = Message::load_from_db(self, notify_msg_id).await?;
398398
notify_msg.param.set(Param::Arg, href);
399399
notify_msg.update_param(self).await?;
@@ -421,12 +421,14 @@ impl Context {
421421
contact_id: from_id,
422422
msg_id: notify_msg_id,
423423
text: notify_text.clone(),
424+
href: status_update_item.href,
424425
});
425426
} else if let Some(notify_text) = notify_list.get("*") {
426427
self.emit_event(EventType::IncomingWebxdcNotify {
427428
contact_id: from_id,
428429
msg_id: notify_msg_id,
429430
text: notify_text.clone(),
431+
href: status_update_item.href,
430432
});
431433
}
432434
}

0 commit comments

Comments
 (0)