4949@import AVFoundation;
5050@import SAMKeychain;
5151
52- #define STATE_VERSION 19
52+ #define STATE_VERSION 20
5353#define CONNECT_TIMEOUT 7.0
5454#define IQ_TIMEOUT 60.0
5555NSString * const kQueueID = @" queueID" ;
@@ -921,6 +921,7 @@ -(void) connect
921921
922922 // mark this account as currently connecting
923923 self->_accountState = kStateReconnecting ;
924+ [self accountStatusChanged ];
924925
925926 // only proceed with connection if not concurrent with other processes
926927 DDLogVerbose (@" Checking remote process lock..." );
@@ -933,6 +934,7 @@ -(void) connect
933934 {
934935 DDLogInfo (@" MainApp is running, not connecting (this should transition us into idle state again which will terminate this extension)" );
935936 self->_accountState = kStateDisconnected ;
937+ [self accountStatusChanged ];
936938 return ;
937939 }
938940
@@ -952,6 +954,7 @@ -(void) connect
952954 {
953955 DDLogError (@" Server disallows xmpp connections for account '%@ ', ignoring login" , self.accountID );
954956 self->_accountState = kStateDisconnected ;
957+ [self accountStatusChanged ];
955958 return ;
956959 }
957960
@@ -1236,6 +1239,8 @@ -(void) closeSocket
12361239 // we don't throw away operations in the receive queue because they could be more than just stanzas
12371240 // (for example outgoing messages that should be written to the smacks queue instead of just vanishing in a void)
12381241 // all incoming stanzas in the receive queue will honor the _accountState being lower than kStateReconnecting and be dropped
1242+
1243+ [self accountStatusChanged ];
12391244 }];
12401245}
12411246
@@ -2404,12 +2409,13 @@ -(void) processInput:(MLXMLNode*) parsedStanza withDelayedReplay:(BOOL) delayedR
24042409 self.resuming = NO ;
24052410 self.isDoingFullReconnect = NO ;
24062411
2407- // now we are initialized again (the following block is *largely* taken from earlyInitSession
2412+ // now we are initialized again (the following block is *largely* taken from earlyInitSession)
24082413 DDLogInfo (@" Session resumed, initializing state..." );
24092414 self.isDoingFullReconnect = YES ;
24102415 _connectedTime = [NSDate date ];
24112416 _reconnectBackoffTime = 0 ;
24122417 _accountState = kStateInitStarted ;
2418+ [[MLNotificationQueue currentQueue ] postNotificationName: kMLSessionInitNotice object: self ];
24132419 [self accountStatusChanged ];
24142420
24152421 @synchronized (_stateLockObject) {
@@ -2562,6 +2568,7 @@ -(void) processInput:(MLXMLNode*) parsedStanza withDelayedReplay:(BOOL) delayedR
25622568
25632569 self->_accountState = kStateLoggedIn ;
25642570 [[MLNotificationQueue currentQueue ] postNotificationName: kMLIsLoggedInNotice object: self ];
2571+ [self accountStatusChanged ];
25652572
25662573 _usableServersList = [NSMutableArray new ]; // reset list to start again with the highest SRV priority on next connect
25672574 if (_loginTimer)
@@ -2793,6 +2800,8 @@ -(void) processInput:(MLXMLNode*) parsedStanza withDelayedReplay:(BOOL) delayedR
27932800 // NOTE: we don't have any stream restart when using SASL2
27942801 // NOTE: we don't need to pipeline anything here, because SASL2 sends out the new stream features immediately without a stream restart
27952802 _cachedStreamFeaturesAfterAuth = nil ; // make sure we don't accidentally try to do pipelining
2803+
2804+ [self accountStatusChanged ];
27962805 }
27972806 else if ([parsedStanza check: @" /{urn:xmpp:sasl:2}continue" ])
27982807 {
@@ -2843,7 +2852,10 @@ -(void) processInput:(MLXMLNode*) parsedStanza withDelayedReplay:(BOOL) delayedR
28432852 {
28442853 // prevent reconnect attempt
28452854 if (_accountState < kStateHasStream )
2855+ {
28462856 _accountState = kStateHasStream ;
2857+ [self accountStatusChanged ];
2858+ }
28472859
28482860 // perform logic to handle stream
28492861 if (self.accountState < kStateLoggedIn )
@@ -2867,7 +2879,7 @@ -(void) processInput:(MLXMLNode*) parsedStanza withDelayedReplay:(BOOL) delayedR
28672879 [self handleFeaturesAfterAuth: parsedStanza];
28682880 }
28692881 else
2870- DDLogDebug (@" Stream features (after auth) already read from cache, ignoring incoming stream features (but refreshing cache).\n Cached : %@ \n Incoming: %@ " , _cachedStreamFeaturesAfterAuth, parsedStanza);
2882+ DDLogDebug (@" Stream features (after auth) already read from cache, ignoring incoming stream features (but refreshing cache).\n Cached : %@ \n Incoming: %@ " , _cachedStreamFeaturesAfterAuth, parsedStanza);
28712883 _cachedStreamFeaturesAfterAuth = parsedStanza;
28722884 }
28732885 }
@@ -3686,7 +3698,7 @@ -(void) realPersistState
36863698 [[DataLayer sharedInstance ] persistState: values forAccount: self .accountID];
36873699
36883700 // debug output
3689- DDLogVerbose (@" %@ --> persistState(saved at %@ ):\n\t isDoingFullReconnect=%@ ,\n\t lastHandledInboundStanza=%@ ,\n\t lastHandledOutboundStanza=%@ ,\n\t lastOutboundStanza=%@ ,\n\t #unAckedStanzas=%lu%s ,\n\t streamID=%@ \n\t lastInteractionDate=%@ \n\t persistentIqHandlers=%@ \n\t supportsHttpUpload=%d \n\t pushEnabled=%d \n\t supportsPubSub=%d \n\t supportsModernPubSub=%d \n\t supportsPubSubMax=%d \n\t accountDiscoDone=%d \n\t _inCatchup=%@ \n\t omemo.state=%@ \n\t hasSeenOmemoDeviceListAfterOwnDeviceid=%@ \n " ,
3701+ DDLogVerbose (@" %@ --> persistState(saved at %@ ):\n\t isDoingFullReconnect=%@ ,\n\t lastHandledInboundStanza=%@ ,\n\t lastHandledOutboundStanza=%@ ,\n\t lastOutboundStanza=%@ ,\n\t #unAckedStanzas=%lu%s ,\n\t streamID=%@ \n\t lastInteractionDate=%@ \n\t persistentIqHandlers=%@ \n\t supportsHttpUpload=%d \n\t pushEnabled=%d \n\t supportsPubSub=%d \n\t supportsModernPubSub=%d \n\t supportsPubSubMax=%d \n\t accountDiscoDone=%d \n\t _inCatchup=%@ \n\t omemo.state=%@ \n\t hasSeenOmemoDeviceListAfterOwnDeviceid=%@ \n\t _cachedStreamFeaturesBeforeAuth= %@ \n\t _cachedStreamFeaturesAfterAuth= %@ \n " ,
36903702 self.accountID ,
36913703 values[@" stateSavedAt" ],
36923704 bool2str (self.isDoingFullReconnect ),
@@ -3705,7 +3717,9 @@ -(void) realPersistState
37053717 self.connectionProperties .accountDiscoDone ,
37063718 self->_inCatchup ,
37073719 self.omemo .state ,
3708- bool2str (self.hasSeenOmemoDeviceListAfterOwnDeviceid )
3720+ bool2str (self.hasSeenOmemoDeviceListAfterOwnDeviceid ),
3721+ bool2str (self->_cachedStreamFeaturesBeforeAuth !=nil ),
3722+ bool2str (self->_cachedStreamFeaturesAfterAuth !=nil )
37093723 );
37103724 DDLogVerbose (@" %@ --> realPersistState after: used/available memory: %.3f MiB / %.3f MiB)..." , self.accountID , [HelperTools report_memory ], (CGFloat)os_proc_available_memory () / 1048576 );
37113725 }
@@ -3882,7 +3896,7 @@ -(void) realReadState
38823896 }
38833897
38843898 // debug output
3885- DDLogVerbose (@" %@ --> readState(saved at %@ ):\n\t isDoingFullReconnect=%@ ,\n\t lastHandledInboundStanza=%@ ,\n\t lastHandledOutboundStanza=%@ ,\n\t lastOutboundStanza=%@ ,\n\t #unAckedStanzas=%lu%s ,\n\t streamID=%@ ,\n\t lastInteractionDate=%@ \n\t persistentIqHandlers=%@ \n\t supportsHttpUpload=%d \n\t pushEnabled=%d \n\t supportsPubSub=%d \n\t supportsModernPubSub=%d \n\t supportsPubSubMax=%d \n\t accountDiscoDone=%d \n\t _inCatchup=%@ \n\t omemo.state=%@ \n\t hasSeenOmemoDeviceListAfterOwnDeviceid=%@ \n " ,
3899+ DDLogVerbose (@" %@ --> readState(saved at %@ ):\n\t isDoingFullReconnect=%@ ,\n\t lastHandledInboundStanza=%@ ,\n\t lastHandledOutboundStanza=%@ ,\n\t lastOutboundStanza=%@ ,\n\t #unAckedStanzas=%lu%s ,\n\t streamID=%@ ,\n\t lastInteractionDate=%@ \n\t persistentIqHandlers=%@ \n\t supportsHttpUpload=%d \n\t pushEnabled=%d \n\t supportsPubSub=%d \n\t supportsModernPubSub=%d \n\t supportsPubSubMax=%d \n\t accountDiscoDone=%d \n\t _inCatchup=%@ \n\t omemo.state=%@ \n\t hasSeenOmemoDeviceListAfterOwnDeviceid=%@ \n\t _cachedStreamFeaturesBeforeAuth= %@ \n\t _cachedStreamFeaturesAfterAuth= %@ \n " ,
38863900 self.accountID ,
38873901 dic[@" stateSavedAt" ],
38883902 bool2str (self.isDoingFullReconnect ),
@@ -3901,7 +3915,9 @@ -(void) realReadState
39013915 self.connectionProperties .accountDiscoDone ,
39023916 self->_inCatchup ,
39033917 self.omemo .state ,
3904- bool2str (self.hasSeenOmemoDeviceListAfterOwnDeviceid )
3918+ bool2str (self.hasSeenOmemoDeviceListAfterOwnDeviceid ),
3919+ bool2str (self->_cachedStreamFeaturesBeforeAuth !=nil ),
3920+ bool2str (self->_cachedStreamFeaturesAfterAuth !=nil )
39053921 );
39063922 if (self.unAckedStanzas )
39073923 for (NSDictionary * dic in self.unAckedStanzas )
@@ -3987,6 +4003,7 @@ -(void) bindResource:(NSString*) resource
39874003
39884004 self.isDoingFullReconnect = YES ;
39894005 _accountState = kStateBinding ;
4006+ [self accountStatusChanged ];
39904007
39914008 // delete old resources because we get new presences once we're done initializing the session
39924009 [[DataLayer sharedInstance ] resetContactsForAccount: self .accountID];
@@ -4211,6 +4228,10 @@ -(void) initSession
42114228 // fetch current mds state
42124229 [self .pubsub fetchNode: @" urn:xmpp:mds:displayed:0" from: self .connectionProperties.identity.jid withItemsList: nil andHandler: $newHandler (MLPubSubProcessor, handleMdsFetchResult)];
42134230
4231+ // join MUCs from (current) muc_favorites db, the pending bookmarks fetch will join the remaining currently unknown mucs
4232+ for (NSString * room in [[DataLayer sharedInstance ] listMucsForAccount: self .accountID])
4233+ [self .mucProcessor join: room];
4234+
42144235 // NOTE: mam query will be done in MLIQProcessor once the disco result for our own jid/account returns
42154236
42164237 // initialize stanza counter for statistics
@@ -4854,6 +4875,7 @@ -(void)stream:(NSStream*) stream handleEvent:(NSStreamEvent) eventCode
48544875 self->_blockToCallOnTCPOpen ();
48554876 self->_blockToCallOnTCPOpen = nil ; // don't call this twice
48564877 }
4878+ [self accountStatusChanged ];
48574879 }];
48584880 }
48594881 break ;
@@ -5443,8 +5465,10 @@ -(void) handleFinishedCatchup
54435465 }
54445466 [self persistState ];
54455467
5468+ _accountState = kStateCatchupDone ;
54465469 // don't queue this notification because it should be handled INLINE inside the receive queue
54475470 [[NSNotificationCenter defaultCenter ] postNotificationName: kMonalFinishedCatchup object: self userInfo: nil ];
5471+ [self accountStatusChanged ];
54485472}
54495473
54505474-(void ) updateMdsData : (NSDictionary *) mdsData
0 commit comments