Skip to main content

deltachat/events/
payload.rs

1//! # Event payloads.
2
3use serde::{Deserialize, Serialize};
4use std::path::PathBuf;
5
6use crate::chat::ChatId;
7use crate::config::Config;
8use crate::constants::Chattype;
9use crate::contact::ContactId;
10use crate::ephemeral::Timer as EphemeralTimer;
11use crate::message::MsgId;
12use crate::reaction::Reaction;
13use crate::webxdc::StatusUpdateSerial;
14
15/// Event payload.
16#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
17pub enum EventType {
18    /// The library-user may write an informational string to the log.
19    ///
20    /// This event should *not* be reported to the end-user using a popup or something like
21    /// that.
22    Info(String),
23
24    /// Emitted when SMTP connection is established and login was successful.
25    SmtpConnected(String),
26
27    /// Emitted when IMAP connection is established and login was successful.
28    ImapConnected(String),
29
30    /// Emitted when a message was successfully sent to the SMTP server.
31    SmtpMessageSent(String),
32
33    /// Emitted when an IMAP message has been marked as deleted
34    ImapMessageDeleted(String),
35
36    /// Emitted when an IMAP message has been moved
37    ImapMessageMoved(String),
38
39    /// Emitted before going into IDLE on the Inbox folder.
40    ImapInboxIdle,
41
42    /// Emitted when an new file in the $BLOBDIR was created
43    NewBlobFile(String),
44
45    /// Emitted when an file in the $BLOBDIR was deleted
46    DeletedBlobFile(String),
47
48    /// The library-user should write a warning string to the log.
49    ///
50    /// This event should *not* be reported to the end-user using a popup or something like
51    /// that.
52    Warning(String),
53
54    /// The library-user should report an error to the end-user.
55    ///
56    /// As most things are asynchronous, things may go wrong at any time and the user
57    /// should not be disturbed by a dialog or so.  Instead, use a bubble or so.
58    ///
59    /// However, for ongoing processes (eg. configure())
60    /// or for functions that are expected to fail
61    /// it might be better to delay showing these events until the function has really
62    /// failed (returned false). It should be sufficient to report only the *last* error
63    /// in a message box then.
64    Error(String),
65
66    /// An action cannot be performed because the user is not in the group.
67    /// Reported eg. after a call to
68    /// dc_set_chat_name(), dc_set_chat_profile_image(),
69    /// dc_add_contact_to_chat(), dc_remove_contact_from_chat(),
70    /// dc_send_text_msg() or another sending function.
71    ErrorSelfNotInGroup(String),
72
73    /// Messages or chats changed.  One or more messages or chats changed for various
74    /// reasons in the database:
75    /// - Messages sent, received or removed
76    /// - Chats created, deleted or archived
77    /// - A draft has been set
78    ///
79    MsgsChanged {
80        /// Set if only a single chat is affected by the changes, otherwise 0.
81        chat_id: ChatId,
82
83        /// Set if only a single message is affected by the changes, otherwise 0.
84        msg_id: MsgId,
85    },
86
87    /// Reactions for the message changed.
88    ReactionsChanged {
89        /// ID of the chat which the message belongs to.
90        chat_id: ChatId,
91
92        /// ID of the message for which reactions were changed.
93        msg_id: MsgId,
94
95        /// ID of the contact whose reaction set is changed.
96        contact_id: ContactId,
97    },
98
99    /// A reaction to one's own sent message received.
100    /// Typically, the UI will show a notification for that.
101    ///
102    /// In addition to this event, ReactionsChanged is emitted.
103    IncomingReaction {
104        /// ID of the chat which the message belongs to.
105        chat_id: ChatId,
106
107        /// ID of the contact whose reaction set is changed.
108        contact_id: ContactId,
109
110        /// ID of the message for which reactions were changed.
111        msg_id: MsgId,
112
113        /// The reaction.
114        reaction: Reaction,
115    },
116
117    /// A webxdc wants an info message or a changed summary to be notified.
118    IncomingWebxdcNotify {
119        /// ID of the chat.
120        chat_id: ChatId,
121
122        /// ID of the contact sending.
123        contact_id: ContactId,
124
125        /// ID of the added info message or webxdc instance in case of summary change.
126        msg_id: MsgId,
127
128        /// Text to notify.
129        text: String,
130
131        /// Link assigned to this notification, if any.
132        href: Option<String>,
133    },
134
135    /// There is a fresh message. Typically, the user will show an notification
136    /// when receiving this message.
137    ///
138    /// There is no extra #DC_EVENT_MSGS_CHANGED event send together with this event.
139    IncomingMsg {
140        /// ID of the chat where the message is assigned.
141        chat_id: ChatId,
142
143        /// ID of the message.
144        msg_id: MsgId,
145    },
146
147    /// Downloading a bunch of messages just finished.
148    IncomingMsgBunch,
149
150    /// Messages were seen or noticed.
151    /// chat id is always set.
152    MsgsNoticed(ChatId),
153
154    /// A single message is sent successfully. State changed from  DC_STATE_OUT_PENDING to
155    /// DC_STATE_OUT_DELIVERED, see dc_msg_get_state().
156    MsgDelivered {
157        /// ID of the chat which the message belongs to.
158        chat_id: ChatId,
159
160        /// ID of the message that was successfully sent.
161        msg_id: MsgId,
162    },
163
164    /// A single message could not be sent. State changed from DC_STATE_OUT_PENDING or DC_STATE_OUT_DELIVERED to
165    /// DC_STATE_OUT_FAILED, see dc_msg_get_state().
166    MsgFailed {
167        /// ID of the chat which the message belongs to.
168        chat_id: ChatId,
169
170        /// ID of the message that could not be sent.
171        msg_id: MsgId,
172    },
173
174    /// A single message is read by the receiver. State changed from DC_STATE_OUT_DELIVERED to
175    /// DC_STATE_OUT_MDN_RCVD, see dc_msg_get_state().
176    MsgRead {
177        /// ID of the chat which the message belongs to.
178        chat_id: ChatId,
179
180        /// ID of the message that was read.
181        msg_id: MsgId,
182    },
183
184    /// Like [`EventType::MsgRead`], but also fires on subsequent MDNs,
185    /// if there are multiple receivers, i.e. in groups and channels.
186    #[serde(rename_all = "camelCase")]
187    MsgReadCountChanged {
188        /// ID of the chat which the message belongs to.
189        chat_id: ChatId,
190
191        /// ID of the message that was read.
192        msg_id: MsgId,
193    },
194
195    /// A single message was deleted.
196    ///
197    /// This event means that the message will no longer appear in the messagelist.
198    /// UI should remove the message from the messagelist
199    /// in response to this event if the message is currently displayed.
200    ///
201    /// The message may have been explicitly deleted by the user or expired.
202    /// Internally the message may have been removed from the database,
203    /// moved to the trash chat or hidden.
204    ///
205    /// This event does not indicate the message
206    /// deletion from the server.
207    MsgDeleted {
208        /// ID of the chat where the message was prior to deletion.
209        /// Never 0 or trash chat.
210        chat_id: ChatId,
211
212        /// ID of the deleted message. Never 0.
213        msg_id: MsgId,
214    },
215
216    /// Chat changed.  The name or the image of a chat group was changed or members were added or removed.
217    /// Or the verify state of a chat has changed.
218    /// See dc_set_chat_name(), dc_set_chat_profile_image(), dc_add_contact_to_chat()
219    /// and dc_remove_contact_from_chat().
220    ///
221    /// This event does not include ephemeral timer modification, which
222    /// is a separate event.
223    ChatModified(ChatId),
224
225    /// Chat ephemeral timer changed.
226    ChatEphemeralTimerModified {
227        /// Chat ID.
228        chat_id: ChatId,
229
230        /// New ephemeral timer value.
231        timer: EphemeralTimer,
232    },
233
234    /// Chat was deleted.
235    ChatDeleted {
236        /// Chat ID.
237        chat_id: ChatId,
238    },
239
240    /// Contact(s) created, renamed, blocked, deleted or changed their "recently seen" status.
241    ///
242    /// @param data1 (int) If set, this is the contact_id of an added contact that should be selected.
243    ContactsChanged(Option<ContactId>),
244
245    /// Location of one or more contact has changed.
246    ///
247    /// @param data1 (u32) contact_id of the contact for which the location has changed.
248    ///     If the locations of several contacts have been changed, this parameter is set to `None`.
249    LocationChanged(Option<ContactId>),
250
251    /// Inform about the configuration progress started by configure().
252    ConfigureProgress {
253        /// Progress.
254        ///
255        /// 0=error, 1-999=progress in permille, 1000=success and done
256        progress: u16,
257
258        /// Progress comment or error, something to display to the user.
259        comment: Option<String>,
260    },
261
262    /// Inform about the import/export progress started by imex().
263    ///
264    /// @param data1 (usize) 0=error, 1-999=progress in permille, 1000=success and done
265    /// @param data2 0
266    ImexProgress(u16),
267
268    /// A file has been exported. A file has been written by imex().
269    /// This event may be sent multiple times by a single call to imex().
270    ///
271    /// A typical purpose for a handler of this event may be to make the file public to some system
272    /// services.
273    ///
274    /// @param data2 0
275    ImexFileWritten(PathBuf),
276
277    /// Progress information of a secure-join handshake from the view of the inviter
278    /// (Alice, the person who shows the QR code).
279    ///
280    /// These events are typically sent after a joiner has scanned the QR code
281    /// generated by dc_get_securejoin_qr().
282    SecurejoinInviterProgress {
283        /// ID of the contact that wants to join.
284        contact_id: ContactId,
285
286        /// ID of the chat in case of success.
287        chat_id: ChatId,
288
289        /// The type of the joined chat.
290        chat_type: Chattype,
291
292        /// Progress, always 1000.
293        progress: u16,
294    },
295
296    /// Progress information of a secure-join handshake from the view of the joiner
297    /// (Bob, the person who scans the QR code).
298    /// The events are typically sent while dc_join_securejoin(), which
299    /// may take some time, is executed.
300    SecurejoinJoinerProgress {
301        /// ID of the inviting contact.
302        contact_id: ContactId,
303
304        /// Progress as:
305        /// 400=vg-/vc-request-with-auth sent, typically shown as "alice@addr verified, introducing myself."
306        /// (Bob has verified alice and waits until Alice does the same for him)
307        /// 1000=vg-member-added/vc-contact-confirm received
308        progress: u16,
309    },
310
311    /// The connectivity to the server changed.
312    /// This means that you should refresh the connectivity view
313    /// and possibly the connectivtiy HTML; see dc_get_connectivity() and
314    /// dc_get_connectivity_html() for details.
315    ConnectivityChanged,
316
317    /// The user's avatar changed.
318    /// Deprecated by `ConfigSynced`.
319    SelfavatarChanged,
320
321    /// A multi-device synced config value changed. Maybe the app needs to refresh smth. For
322    /// uniformity this is emitted on the source device too. The value isn't here, otherwise it
323    /// would be logged which might not be good for privacy.
324    ConfigSynced {
325        /// Configuration key.
326        key: Config,
327    },
328
329    /// Webxdc status update received.
330    WebxdcStatusUpdate {
331        /// Message ID.
332        msg_id: MsgId,
333
334        /// Status update ID.
335        status_update_serial: StatusUpdateSerial,
336    },
337
338    /// Data received over an ephemeral peer channel.
339    WebxdcRealtimeData {
340        /// Message ID.
341        msg_id: MsgId,
342
343        /// Realtime data.
344        data: Vec<u8>,
345    },
346
347    /// Advertisement received over an ephemeral peer channel.
348    /// This can be used by bots to initiate peer-to-peer communication from their side.
349    WebxdcRealtimeAdvertisementReceived {
350        /// Message ID of the webxdc instance.
351        msg_id: MsgId,
352    },
353
354    /// Inform that a message containing a webxdc instance has been deleted.
355    WebxdcInstanceDeleted {
356        /// ID of the deleted message.
357        msg_id: MsgId,
358    },
359
360    /// Tells that the Background fetch was completed (or timed out).
361    /// This event acts as a marker, when you reach this event you can be sure
362    /// that all events emitted during the background fetch were processed.
363    ///
364    /// This event is only emitted by the account manager
365    AccountsBackgroundFetchDone,
366    /// Inform that set of chats or the order of the chats in the chatlist has changed.
367    ///
368    /// Sometimes this is emitted together with `UIChatlistItemChanged`.
369    ChatlistChanged,
370
371    /// Inform that a single chat list item changed and needs to be rerendered.
372    /// If `chat_id` is set to None, then all currently visible chats need to be rerendered, and all not-visible items need to be cleared from cache if the UI has a cache.
373    ChatlistItemChanged {
374        /// ID of the changed chat
375        chat_id: Option<ChatId>,
376    },
377
378    /// Inform that the list of accounts has changed (an account removed or added or (not yet implemented) the account order changes)
379    ///
380    /// This event is only emitted by the account manager
381    AccountsChanged,
382
383    /// Inform that an account property that might be shown in the account list changed, namely:
384    /// - is_configured (see [crate::context::Context::is_configured])
385    /// - displayname
386    /// - selfavatar
387    /// - private_tag
388    ///
389    /// This event is emitted from the account whose property changed.
390    AccountsItemChanged,
391
392    /// Incoming call.
393    IncomingCall {
394        /// ID of the message referring to the call.
395        msg_id: MsgId,
396        /// ID of the chat which the message belongs to.
397        chat_id: ChatId,
398        /// User-defined info as passed to place_outgoing_call()
399        place_call_info: String,
400        /// True if incoming call is a video call.
401        has_video: bool,
402    },
403
404    /// Incoming call accepted.
405    IncomingCallAccepted {
406        /// ID of the message referring to the call.
407        msg_id: MsgId,
408        /// ID of the chat which the message belongs to.
409        chat_id: ChatId,
410        /// The call was accepted from this device (process).
411        from_this_device: bool,
412    },
413
414    /// Outgoing call accepted.
415    OutgoingCallAccepted {
416        /// ID of the message referring to the call.
417        msg_id: MsgId,
418        /// ID of the chat which the message belongs to.
419        chat_id: ChatId,
420        /// User-defined info as passed to accept_incoming_call()
421        accept_call_info: String,
422    },
423
424    /// Call ended.
425    CallEnded {
426        /// ID of the message referring to the call.
427        msg_id: MsgId,
428        /// ID of the chat which the message belongs to.
429        chat_id: ChatId,
430    },
431
432    /// One or more transports has changed or another transport is primary now.
433    ///
434    /// UI should update the list.
435    ///
436    /// This event is emitted when a transport
437    /// synchronization message modifies transports,
438    /// but not when the UI modifies the transport list by itself.
439    TransportsModified,
440
441    /// Event for using in tests, e.g. as a fence between normally generated events.
442    #[cfg(test)]
443    Test,
444
445    /// Inform than some events have been skipped due to event channel overflow.
446    EventChannelOverflow {
447        /// Number of events skipped.
448        n: u64,
449    },
450}