1
- use deltachat:: { Event , EventType } ;
1
+ use deltachat:: { Event as CoreEvent , EventType as CoreEventType } ;
2
2
use serde:: Serialize ;
3
- use serde_json:: { json, Value } ;
4
3
use typescript_type_def:: TypeDef ;
5
4
6
- pub fn event_to_json_rpc_notification ( event : Event ) -> Value {
7
- let id: JSONRPCEventType = event. typ . into ( ) ;
8
- json ! ( {
9
- "event" : id,
10
- "contextId" : event. id,
11
- } )
5
+ #[ derive( Serialize , TypeDef ) ]
6
+ pub struct Event {
7
+ /// Event payload.
8
+ event : EventType ,
9
+
10
+ /// Account ID.
11
+ context_id : u32 ,
12
+ }
13
+
14
+ impl From < CoreEvent > for Event {
15
+ fn from ( event : CoreEvent ) -> Self {
16
+ Event {
17
+ event : event. typ . into ( ) ,
18
+ context_id : event. id ,
19
+ }
20
+ }
12
21
}
13
22
14
23
#[ derive( Serialize , TypeDef ) ]
15
- #[ serde( tag = "type" , rename = "Event" ) ]
16
- pub enum JSONRPCEventType {
24
+ #[ serde( tag = "type" ) ]
25
+ pub enum EventType {
17
26
/// The library-user may write an informational string to the log.
18
27
///
19
28
/// This event should *not* be reported to the end-user using a popup or something like
@@ -286,27 +295,27 @@ pub enum JSONRPCEventType {
286
295
} ,
287
296
}
288
297
289
- impl From < EventType > for JSONRPCEventType {
290
- fn from ( event : EventType ) -> Self {
291
- use JSONRPCEventType :: * ;
298
+ impl From < CoreEventType > for EventType {
299
+ fn from ( event : CoreEventType ) -> Self {
300
+ use EventType :: * ;
292
301
match event {
293
- EventType :: Info ( msg) => Info { msg } ,
294
- EventType :: SmtpConnected ( msg) => SmtpConnected { msg } ,
295
- EventType :: ImapConnected ( msg) => ImapConnected { msg } ,
296
- EventType :: SmtpMessageSent ( msg) => SmtpMessageSent { msg } ,
297
- EventType :: ImapMessageDeleted ( msg) => ImapMessageDeleted { msg } ,
298
- EventType :: ImapMessageMoved ( msg) => ImapMessageMoved { msg } ,
299
- EventType :: ImapInboxIdle => ImapInboxIdle ,
300
- EventType :: NewBlobFile ( file) => NewBlobFile { file } ,
301
- EventType :: DeletedBlobFile ( file) => DeletedBlobFile { file } ,
302
- EventType :: Warning ( msg) => Warning { msg } ,
303
- EventType :: Error ( msg) => Error { msg } ,
304
- EventType :: ErrorSelfNotInGroup ( msg) => ErrorSelfNotInGroup { msg } ,
305
- EventType :: MsgsChanged { chat_id, msg_id } => MsgsChanged {
302
+ CoreEventType :: Info ( msg) => Info { msg } ,
303
+ CoreEventType :: SmtpConnected ( msg) => SmtpConnected { msg } ,
304
+ CoreEventType :: ImapConnected ( msg) => ImapConnected { msg } ,
305
+ CoreEventType :: SmtpMessageSent ( msg) => SmtpMessageSent { msg } ,
306
+ CoreEventType :: ImapMessageDeleted ( msg) => ImapMessageDeleted { msg } ,
307
+ CoreEventType :: ImapMessageMoved ( msg) => ImapMessageMoved { msg } ,
308
+ CoreEventType :: ImapInboxIdle => ImapInboxIdle ,
309
+ CoreEventType :: NewBlobFile ( file) => NewBlobFile { file } ,
310
+ CoreEventType :: DeletedBlobFile ( file) => DeletedBlobFile { file } ,
311
+ CoreEventType :: Warning ( msg) => Warning { msg } ,
312
+ CoreEventType :: Error ( msg) => Error { msg } ,
313
+ CoreEventType :: ErrorSelfNotInGroup ( msg) => ErrorSelfNotInGroup { msg } ,
314
+ CoreEventType :: MsgsChanged { chat_id, msg_id } => MsgsChanged {
306
315
chat_id : chat_id. to_u32 ( ) ,
307
316
msg_id : msg_id. to_u32 ( ) ,
308
317
} ,
309
- EventType :: ReactionsChanged {
318
+ CoreEventType :: ReactionsChanged {
310
319
chat_id,
311
320
msg_id,
312
321
contact_id,
@@ -315,92 +324,76 @@ impl From<EventType> for JSONRPCEventType {
315
324
msg_id : msg_id. to_u32 ( ) ,
316
325
contact_id : contact_id. to_u32 ( ) ,
317
326
} ,
318
- EventType :: IncomingMsg { chat_id, msg_id } => IncomingMsg {
327
+ CoreEventType :: IncomingMsg { chat_id, msg_id } => IncomingMsg {
319
328
chat_id : chat_id. to_u32 ( ) ,
320
329
msg_id : msg_id. to_u32 ( ) ,
321
330
} ,
322
- EventType :: IncomingMsgBunch { msg_ids } => IncomingMsgBunch {
331
+ CoreEventType :: IncomingMsgBunch { msg_ids } => IncomingMsgBunch {
323
332
msg_ids : msg_ids. into_iter ( ) . map ( |id| id. to_u32 ( ) ) . collect ( ) ,
324
333
} ,
325
- EventType :: MsgsNoticed ( chat_id) => MsgsNoticed {
334
+ CoreEventType :: MsgsNoticed ( chat_id) => MsgsNoticed {
326
335
chat_id : chat_id. to_u32 ( ) ,
327
336
} ,
328
- EventType :: MsgDelivered { chat_id, msg_id } => MsgDelivered {
337
+ CoreEventType :: MsgDelivered { chat_id, msg_id } => MsgDelivered {
329
338
chat_id : chat_id. to_u32 ( ) ,
330
339
msg_id : msg_id. to_u32 ( ) ,
331
340
} ,
332
- EventType :: MsgFailed { chat_id, msg_id } => MsgFailed {
341
+ CoreEventType :: MsgFailed { chat_id, msg_id } => MsgFailed {
333
342
chat_id : chat_id. to_u32 ( ) ,
334
343
msg_id : msg_id. to_u32 ( ) ,
335
344
} ,
336
- EventType :: MsgRead { chat_id, msg_id } => MsgRead {
345
+ CoreEventType :: MsgRead { chat_id, msg_id } => MsgRead {
337
346
chat_id : chat_id. to_u32 ( ) ,
338
347
msg_id : msg_id. to_u32 ( ) ,
339
348
} ,
340
- EventType :: ChatModified ( chat_id) => ChatModified {
349
+ CoreEventType :: ChatModified ( chat_id) => ChatModified {
341
350
chat_id : chat_id. to_u32 ( ) ,
342
351
} ,
343
- EventType :: ChatEphemeralTimerModified { chat_id, timer } => {
352
+ CoreEventType :: ChatEphemeralTimerModified { chat_id, timer } => {
344
353
ChatEphemeralTimerModified {
345
354
chat_id : chat_id. to_u32 ( ) ,
346
355
timer : timer. to_u32 ( ) ,
347
356
}
348
357
}
349
- EventType :: ContactsChanged ( contact) => ContactsChanged {
358
+ CoreEventType :: ContactsChanged ( contact) => ContactsChanged {
350
359
contact_id : contact. map ( |c| c. to_u32 ( ) ) ,
351
360
} ,
352
- EventType :: LocationChanged ( contact) => LocationChanged {
361
+ CoreEventType :: LocationChanged ( contact) => LocationChanged {
353
362
contact_id : contact. map ( |c| c. to_u32 ( ) ) ,
354
363
} ,
355
- EventType :: ConfigureProgress { progress, comment } => {
364
+ CoreEventType :: ConfigureProgress { progress, comment } => {
356
365
ConfigureProgress { progress, comment }
357
366
}
358
- EventType :: ImexProgress ( progress) => ImexProgress { progress } ,
359
- EventType :: ImexFileWritten ( path) => ImexFileWritten {
367
+ CoreEventType :: ImexProgress ( progress) => ImexProgress { progress } ,
368
+ CoreEventType :: ImexFileWritten ( path) => ImexFileWritten {
360
369
path : path. to_str ( ) . unwrap_or_default ( ) . to_owned ( ) ,
361
370
} ,
362
- EventType :: SecurejoinInviterProgress {
371
+ CoreEventType :: SecurejoinInviterProgress {
363
372
contact_id,
364
373
progress,
365
374
} => SecurejoinInviterProgress {
366
375
contact_id : contact_id. to_u32 ( ) ,
367
376
progress,
368
377
} ,
369
- EventType :: SecurejoinJoinerProgress {
378
+ CoreEventType :: SecurejoinJoinerProgress {
370
379
contact_id,
371
380
progress,
372
381
} => SecurejoinJoinerProgress {
373
382
contact_id : contact_id. to_u32 ( ) ,
374
383
progress,
375
384
} ,
376
- EventType :: ConnectivityChanged => ConnectivityChanged ,
377
- EventType :: SelfavatarChanged => SelfavatarChanged ,
378
- EventType :: WebxdcStatusUpdate {
385
+ CoreEventType :: ConnectivityChanged => ConnectivityChanged ,
386
+ CoreEventType :: SelfavatarChanged => SelfavatarChanged ,
387
+ CoreEventType :: WebxdcStatusUpdate {
379
388
msg_id,
380
389
status_update_serial,
381
390
} => WebxdcStatusUpdate {
382
391
msg_id : msg_id. to_u32 ( ) ,
383
392
status_update_serial : status_update_serial. to_u32 ( ) ,
384
393
} ,
385
- EventType :: WebxdcInstanceDeleted { msg_id } => WebxdcInstanceDeleted {
394
+ CoreEventType :: WebxdcInstanceDeleted { msg_id } => WebxdcInstanceDeleted {
386
395
msg_id : msg_id. to_u32 ( ) ,
387
396
} ,
388
397
}
389
398
}
390
399
}
391
-
392
- #[ cfg( test) ]
393
- #[ test]
394
- fn generate_events_ts_types_definition ( ) {
395
- let events = {
396
- let mut buf = Vec :: new ( ) ;
397
- let options = typescript_type_def:: DefinitionFileOptions {
398
- root_namespace : None ,
399
- ..typescript_type_def:: DefinitionFileOptions :: default ( )
400
- } ;
401
- typescript_type_def:: write_definition_file :: < _ , JSONRPCEventType > ( & mut buf, options)
402
- . unwrap ( ) ;
403
- String :: from_utf8 ( buf) . unwrap ( )
404
- } ;
405
- std:: fs:: write ( "typescript/generated/events.ts" , events) . unwrap ( ) ;
406
- }
0 commit comments