Skip to content

Commit 29de7c3

Browse files
r10sadbenitezlink2xt
authored
feat: webxdc notify (#6230)
this PR adds support for the property `update.notify` to notify about changes in `update.info` or `update.summary`. the property can be set to an array of addresses [^1] core emits then the event `IncomingWebxdcNotify`, resulting in all UIs to display a system notification, maybe even via PUSH. for using the existing `update.info` and `update.summary`: the message is no secret and should be visible to all group members as usual, to not break the UX of having same group messages on all devices of all users - as known already from the normal messages. also, that way, there is no question what happens if user have disabled notifications as the change is presented in the chat as well doc counterpart at webxdc/website#90 closes #6217 [^1]: addresses come in either via the payload as currently or as an explicit sender in the future - this does not affect this PR. same for translations, see discussions at #6217 and #6097 --------- Co-authored-by: adb <[email protected]> Co-authored-by: l <[email protected]>
1 parent f669f43 commit 29de7c3

File tree

10 files changed

+261
-31
lines changed

10 files changed

+261
-31
lines changed

deltachat-ffi/deltachat.h

+24-1
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,13 @@ uint32_t dc_send_videochat_invitation (dc_context_t* context, uint32_t chat_id);
11541154
* @memberof dc_context_t
11551155
* @param context The context object.
11561156
* @param msg_id The ID of the message with the webxdc instance.
1157-
* @param json program-readable data, the actual payload
1157+
* @param json program-readable data, this is created in JS land as:
1158+
* - `payload`: any JS object or primitive.
1159+
* - `info`: optional informational message. Will be shown in chat and may be added as system notification.
1160+
* note that also users that are not notified explicitly get the `info` or `summary` update shown in the chat.
1161+
* - `document`: optional document name. shown eg. in title bar.
1162+
* - `summary`: optional summary. shown beside app icon.
1163+
* - `notify`: optional array of other users `selfAddr` to be notified e.g. by a sound about `info` or `summary`.
11581164
* @param descr The user-visible description of JSON data,
11591165
* in case of a chess game, e.g. the move.
11601166
* @return 1=success, 0=error
@@ -6080,12 +6086,29 @@ void dc_event_unref(dc_event_t* event);
60806086
#define DC_EVENT_INCOMING_REACTION 2002
60816087

60826088

6089+
6090+
/**
6091+
* A webxdc wants an info message or a changed summary to be notified.
6092+
*
6093+
* @param data1 contact_id ID of the contact sending.
6094+
* @param data2 (int) msg_id + (char*) text_to_notify.
6095+
* msg_id in dc_event_get_data2_int(), referring to webxdc-info-message
6096+
* or webxdc-instance in case of summary change.
6097+
* text_to_notify in dc_event_get_data2_str().
6098+
* string must be passed to dc_str_unref() afterwards.
6099+
*/
6100+
#define DC_EVENT_INCOMING_WEBXDC_NOTIFY 2003
6101+
6102+
60836103
/**
60846104
* There is a fresh message. Typically, the user will show an notification
60856105
* when receiving this message.
60866106
*
60876107
* There is no extra #DC_EVENT_MSGS_CHANGED event send together with this event.
60886108
*
6109+
* If the message is a webxdc info message,
6110+
* dc_msg_get_parent() returns the webxdc instance the notification belongs to.
6111+
*
60896112
* @param data1 (int) chat_id
60906113
* @param data2 (int) msg_id
60916114
*/

deltachat-ffi/src/lib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ pub unsafe extern "C" fn dc_event_get_id(event: *mut dc_event_t) -> libc::c_int
542542
EventType::MsgsChanged { .. } => 2000,
543543
EventType::ReactionsChanged { .. } => 2001,
544544
EventType::IncomingReaction { .. } => 2002,
545+
EventType::IncomingWebxdcNotify { .. } => 2003,
545546
EventType::IncomingMsg { .. } => 2005,
546547
EventType::IncomingMsgBunch { .. } => 2006,
547548
EventType::MsgsNoticed { .. } => 2008,
@@ -602,7 +603,8 @@ pub unsafe extern "C" fn dc_event_get_data1_int(event: *mut dc_event_t) -> libc:
602603
| EventType::ErrorSelfNotInGroup(_)
603604
| EventType::AccountsBackgroundFetchDone => 0,
604605
EventType::ChatlistChanged => 0,
605-
EventType::IncomingReaction { contact_id, .. } => contact_id.to_u32() as libc::c_int,
606+
EventType::IncomingReaction { contact_id, .. }
607+
| EventType::IncomingWebxdcNotify { contact_id, .. } => contact_id.to_u32() as libc::c_int,
606608
EventType::MsgsChanged { chat_id, .. }
607609
| EventType::ReactionsChanged { chat_id, .. }
608610
| EventType::IncomingMsg { chat_id, .. }
@@ -681,6 +683,7 @@ pub unsafe extern "C" fn dc_event_get_data2_int(event: *mut dc_event_t) -> libc:
681683
EventType::MsgsChanged { msg_id, .. }
682684
| EventType::ReactionsChanged { msg_id, .. }
683685
| EventType::IncomingReaction { msg_id, .. }
686+
| EventType::IncomingWebxdcNotify { msg_id, .. }
684687
| EventType::IncomingMsg { msg_id, .. }
685688
| EventType::MsgDelivered { msg_id, .. }
686689
| EventType::MsgFailed { msg_id, .. }
@@ -775,6 +778,9 @@ pub unsafe extern "C" fn dc_event_get_data2_str(event: *mut dc_event_t) -> *mut
775778
.to_c_string()
776779
.unwrap_or_default()
777780
.into_raw(),
781+
EventType::IncomingWebxdcNotify { text, .. } => {
782+
text.to_c_string().unwrap_or_default().into_raw()
783+
}
778784
#[allow(unreachable_patterns)]
779785
#[cfg(test)]
780786
_ => unreachable!("This is just to silence a rust_analyzer false-positive"),

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

+17
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ pub enum EventType {
106106
reaction: String,
107107
},
108108

109+
/// Incoming webxdc info or summary update, should be notified.
110+
#[serde(rename_all = "camelCase")]
111+
IncomingWebxdcNotify {
112+
contact_id: u32,
113+
msg_id: u32,
114+
text: String,
115+
},
116+
109117
/// There is a fresh message. Typically, the user will show an notification
110118
/// when receiving this message.
111119
///
@@ -319,6 +327,15 @@ impl From<CoreEventType> for EventType {
319327
msg_id: msg_id.to_u32(),
320328
reaction: reaction.as_str().to_string(),
321329
},
330+
CoreEventType::IncomingWebxdcNotify {
331+
contact_id,
332+
msg_id,
333+
text,
334+
} => IncomingWebxdcNotify {
335+
contact_id: contact_id.to_u32(),
336+
msg_id: msg_id.to_u32(),
337+
text,
338+
},
322339
CoreEventType::IncomingMsg { chat_id, msg_id } => IncomingMsg {
323340
chat_id: chat_id.to_u32(),
324341
msg_id: msg_id.to_u32(),

node/constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ module.exports = {
5252
DC_EVENT_INCOMING_MSG: 2005,
5353
DC_EVENT_INCOMING_MSG_BUNCH: 2006,
5454
DC_EVENT_INCOMING_REACTION: 2002,
55+
DC_EVENT_INCOMING_WEBXDC_NOTIFY: 2003,
5556
DC_EVENT_INFO: 100,
5657
DC_EVENT_LOCATION_CHANGED: 2035,
5758
DC_EVENT_MSGS_CHANGED: 2000,

node/events.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
2000: 'DC_EVENT_MSGS_CHANGED',
1818
2001: 'DC_EVENT_REACTIONS_CHANGED',
1919
2002: 'DC_EVENT_INCOMING_REACTION',
20+
2003: 'DC_EVENT_INCOMING_WEBXDC_NOTIFY',
2021
2005: 'DC_EVENT_INCOMING_MSG',
2122
2006: 'DC_EVENT_INCOMING_MSG_BUNCH',
2223
2008: 'DC_EVENT_MSGS_NOTICED',

node/lib/constants.ts

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export enum C {
5252
DC_EVENT_INCOMING_MSG = 2005,
5353
DC_EVENT_INCOMING_MSG_BUNCH = 2006,
5454
DC_EVENT_INCOMING_REACTION = 2002,
55+
DC_EVENT_INCOMING_WEBXDC_NOTIFY = 2003,
5556
DC_EVENT_INFO = 100,
5657
DC_EVENT_LOCATION_CHANGED = 2035,
5758
DC_EVENT_MSGS_CHANGED = 2000,
@@ -325,6 +326,7 @@ export const EventId2EventName: { [key: number]: string } = {
325326
2000: 'DC_EVENT_MSGS_CHANGED',
326327
2001: 'DC_EVENT_REACTIONS_CHANGED',
327328
2002: 'DC_EVENT_INCOMING_REACTION',
329+
2003: 'DC_EVENT_INCOMING_WEBXDC_NOTIFY',
328330
2005: 'DC_EVENT_INCOMING_MSG',
329331
2006: 'DC_EVENT_INCOMING_MSG_BUNCH',
330332
2008: 'DC_EVENT_MSGS_NOTICED',

src/debug_logging.rs

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub async fn debug_logging_loop(context: &Context, events: Receiver<DebugEventLo
6363
summary: None,
6464
document: None,
6565
uid: None,
66+
notify: None,
6667
},
6768
time,
6869
)

src/events/payload.rs

+12
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ pub enum EventType {
107107
reaction: Reaction,
108108
},
109109

110+
/// A webxdc wants an info message or a changed summary to be notified.
111+
IncomingWebxdcNotify {
112+
/// ID of the contact sending.
113+
contact_id: ContactId,
114+
115+
/// ID of the added info message or webxdc instance in case of summary change.
116+
msg_id: MsgId,
117+
118+
/// Text to notify.
119+
text: String,
120+
},
121+
110122
/// There is a fresh message. Typically, the user will show an notification
111123
/// when receiving this message.
112124
///

0 commit comments

Comments
 (0)