@@ -9,14 +9,15 @@ use crate::config::Config;
99use crate :: constants:: Blocked ;
1010use crate :: contact:: ContactId ;
1111use crate :: context:: Context ;
12- use crate :: log:: LogExt ;
13- use crate :: log :: warn ;
12+ use crate :: log:: { LogExt as _ , warn } ;
13+ use crate :: login_param :: EnteredLoginParam ;
1414use crate :: message:: { Message , MsgId , Viewtype } ;
1515use crate :: mimeparser:: SystemMessage ;
1616use crate :: param:: Param ;
1717use crate :: sync:: SyncData :: { AddQrToken , AlterChat , DeleteQrToken } ;
1818use crate :: token:: Namespace ;
1919use crate :: tools:: time;
20+ use crate :: transport:: { ConfiguredLoginParamJson , sync_transports} ;
2021use crate :: { message, stock_str, token} ;
2122use std:: collections:: HashSet ;
2223
@@ -52,6 +53,29 @@ pub(crate) struct QrTokenData {
5253 pub ( crate ) grpid : Option < String > ,
5354}
5455
56+ #[ derive( Debug , Serialize , Deserialize ) ]
57+ pub ( crate ) struct TransportData {
58+ /// Configured login parameters.
59+ pub ( crate ) configured : ConfiguredLoginParamJson ,
60+
61+ /// Login parameters entered by the user.
62+ ///
63+ /// They can be used to reconfigure the transport.
64+ pub ( crate ) entered : EnteredLoginParam ,
65+
66+ /// Timestamp of when the transport was last time (re)configured.
67+ pub ( crate ) timestamp : i64 ,
68+ }
69+
70+ #[ derive( Debug , Serialize , Deserialize ) ]
71+ pub ( crate ) struct RemovedTransportData {
72+ /// Address of the removed transport.
73+ pub ( crate ) addr : String ,
74+
75+ /// Timestamp of when the transport was removed.
76+ pub ( crate ) timestamp : i64 ,
77+ }
78+
5579#[ derive( Debug , Serialize , Deserialize ) ]
5680pub ( crate ) enum SyncData {
5781 AddQrToken ( QrTokenData ) ,
@@ -71,6 +95,28 @@ pub(crate) enum SyncData {
7195 DeleteMessages {
7296 msgs : Vec < String > , // RFC724 id (i.e. "Message-Id" header)
7397 } ,
98+
99+ /// Update transport configuration.
100+ ///
101+ /// This message contains a list of all added transports
102+ /// together with their addition timestamp,
103+ /// and all removed transports together with
104+ /// the removal timestamp.
105+ ///
106+ /// In case of a tie, addition and removal timestamps
107+ /// being the same, removal wins.
108+ /// It is more likely that transport is added
109+ /// and then removed within a second,
110+ /// but unlikely the other way round
111+ /// as adding new transport takes time
112+ /// to run configuration.
113+ Transports {
114+ /// Active transports.
115+ transports : Vec < TransportData > ,
116+
117+ /// Removed transports with the timestamp of removal.
118+ removed_transports : Vec < RemovedTransportData > ,
119+ } ,
74120}
75121
76122#[ derive( Debug , Serialize , Deserialize ) ]
@@ -274,6 +320,10 @@ impl Context {
274320 SyncData :: Config { key, val } => self . sync_config ( key, val) . await ,
275321 SyncData :: SaveMessage { src, dest } => self . save_message ( src, dest) . await ,
276322 SyncData :: DeleteMessages { msgs } => self . sync_message_deletion ( msgs) . await ,
323+ SyncData :: Transports {
324+ transports,
325+ removed_transports,
326+ } => sync_transports ( self , transports, removed_transports) . await ,
277327 } ,
278328 SyncDataOrUnknown :: Unknown ( data) => {
279329 warn ! ( self , "Ignored unknown sync item: {data}." ) ;
0 commit comments