1- use deltachat:: { Event , EventType } ;
1+ use deltachat:: { Event as CoreEvent , EventType as CoreEventType } ;
22use serde:: Serialize ;
3- use serde_json:: { json, Value } ;
43use typescript_type_def:: TypeDef ;
54
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+ }
1221}
1322
1423#[ derive( Serialize , TypeDef ) ]
15- #[ serde( tag = "type" , rename = "Event" ) ]
16- pub enum JSONRPCEventType {
24+ #[ serde( tag = "type" ) ]
25+ pub enum EventType {
1726 /// The library-user may write an informational string to the log.
1827 ///
1928 /// This event should *not* be reported to the end-user using a popup or something like
@@ -286,27 +295,27 @@ pub enum JSONRPCEventType {
286295 } ,
287296}
288297
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 :: * ;
292301 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 {
306315 chat_id : chat_id. to_u32 ( ) ,
307316 msg_id : msg_id. to_u32 ( ) ,
308317 } ,
309- EventType :: ReactionsChanged {
318+ CoreEventType :: ReactionsChanged {
310319 chat_id,
311320 msg_id,
312321 contact_id,
@@ -315,92 +324,76 @@ impl From<EventType> for JSONRPCEventType {
315324 msg_id : msg_id. to_u32 ( ) ,
316325 contact_id : contact_id. to_u32 ( ) ,
317326 } ,
318- EventType :: IncomingMsg { chat_id, msg_id } => IncomingMsg {
327+ CoreEventType :: IncomingMsg { chat_id, msg_id } => IncomingMsg {
319328 chat_id : chat_id. to_u32 ( ) ,
320329 msg_id : msg_id. to_u32 ( ) ,
321330 } ,
322- EventType :: IncomingMsgBunch { msg_ids } => IncomingMsgBunch {
331+ CoreEventType :: IncomingMsgBunch { msg_ids } => IncomingMsgBunch {
323332 msg_ids : msg_ids. into_iter ( ) . map ( |id| id. to_u32 ( ) ) . collect ( ) ,
324333 } ,
325- EventType :: MsgsNoticed ( chat_id) => MsgsNoticed {
334+ CoreEventType :: MsgsNoticed ( chat_id) => MsgsNoticed {
326335 chat_id : chat_id. to_u32 ( ) ,
327336 } ,
328- EventType :: MsgDelivered { chat_id, msg_id } => MsgDelivered {
337+ CoreEventType :: MsgDelivered { chat_id, msg_id } => MsgDelivered {
329338 chat_id : chat_id. to_u32 ( ) ,
330339 msg_id : msg_id. to_u32 ( ) ,
331340 } ,
332- EventType :: MsgFailed { chat_id, msg_id } => MsgFailed {
341+ CoreEventType :: MsgFailed { chat_id, msg_id } => MsgFailed {
333342 chat_id : chat_id. to_u32 ( ) ,
334343 msg_id : msg_id. to_u32 ( ) ,
335344 } ,
336- EventType :: MsgRead { chat_id, msg_id } => MsgRead {
345+ CoreEventType :: MsgRead { chat_id, msg_id } => MsgRead {
337346 chat_id : chat_id. to_u32 ( ) ,
338347 msg_id : msg_id. to_u32 ( ) ,
339348 } ,
340- EventType :: ChatModified ( chat_id) => ChatModified {
349+ CoreEventType :: ChatModified ( chat_id) => ChatModified {
341350 chat_id : chat_id. to_u32 ( ) ,
342351 } ,
343- EventType :: ChatEphemeralTimerModified { chat_id, timer } => {
352+ CoreEventType :: ChatEphemeralTimerModified { chat_id, timer } => {
344353 ChatEphemeralTimerModified {
345354 chat_id : chat_id. to_u32 ( ) ,
346355 timer : timer. to_u32 ( ) ,
347356 }
348357 }
349- EventType :: ContactsChanged ( contact) => ContactsChanged {
358+ CoreEventType :: ContactsChanged ( contact) => ContactsChanged {
350359 contact_id : contact. map ( |c| c. to_u32 ( ) ) ,
351360 } ,
352- EventType :: LocationChanged ( contact) => LocationChanged {
361+ CoreEventType :: LocationChanged ( contact) => LocationChanged {
353362 contact_id : contact. map ( |c| c. to_u32 ( ) ) ,
354363 } ,
355- EventType :: ConfigureProgress { progress, comment } => {
364+ CoreEventType :: ConfigureProgress { progress, comment } => {
356365 ConfigureProgress { progress, comment }
357366 }
358- EventType :: ImexProgress ( progress) => ImexProgress { progress } ,
359- EventType :: ImexFileWritten ( path) => ImexFileWritten {
367+ CoreEventType :: ImexProgress ( progress) => ImexProgress { progress } ,
368+ CoreEventType :: ImexFileWritten ( path) => ImexFileWritten {
360369 path : path. to_str ( ) . unwrap_or_default ( ) . to_owned ( ) ,
361370 } ,
362- EventType :: SecurejoinInviterProgress {
371+ CoreEventType :: SecurejoinInviterProgress {
363372 contact_id,
364373 progress,
365374 } => SecurejoinInviterProgress {
366375 contact_id : contact_id. to_u32 ( ) ,
367376 progress,
368377 } ,
369- EventType :: SecurejoinJoinerProgress {
378+ CoreEventType :: SecurejoinJoinerProgress {
370379 contact_id,
371380 progress,
372381 } => SecurejoinJoinerProgress {
373382 contact_id : contact_id. to_u32 ( ) ,
374383 progress,
375384 } ,
376- EventType :: ConnectivityChanged => ConnectivityChanged ,
377- EventType :: SelfavatarChanged => SelfavatarChanged ,
378- EventType :: WebxdcStatusUpdate {
385+ CoreEventType :: ConnectivityChanged => ConnectivityChanged ,
386+ CoreEventType :: SelfavatarChanged => SelfavatarChanged ,
387+ CoreEventType :: WebxdcStatusUpdate {
379388 msg_id,
380389 status_update_serial,
381390 } => WebxdcStatusUpdate {
382391 msg_id : msg_id. to_u32 ( ) ,
383392 status_update_serial : status_update_serial. to_u32 ( ) ,
384393 } ,
385- EventType :: WebxdcInstanceDeleted { msg_id } => WebxdcInstanceDeleted {
394+ CoreEventType :: WebxdcInstanceDeleted { msg_id } => WebxdcInstanceDeleted {
386395 msg_id : msg_id. to_u32 ( ) ,
387396 } ,
388397 }
389398 }
390399}
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