Skip to content

Commit 0679810

Browse files
Cleanup of #9cf6d0f
1 parent 92441b5 commit 0679810

File tree

4 files changed

+34
-22
lines changed

4 files changed

+34
-22
lines changed

Monal/Classes/MLMucProcessor.m

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ -(id) initWithAccount:(xmpp*) account
8888
_hasFetchedBookmarks = NO;
8989

9090
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleResourceBound:) name:kMLResourceBoundNotice object:nil];
91-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleSessionInit:) name:kMLSessionInitNotice object:nil];
9291
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleCatchupDone:) name:kMonalFinishedCatchup object:nil];
9392
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleSentMessage:) name:kMonalSentMessageNotice object:nil];
9493
return self;
@@ -175,18 +174,6 @@ -(void) handleResourceBound:(NSNotification*) notification
175174
}
176175
}
177176

178-
-(void) handleSessionInit:(NSNotification*) notification
179-
{
180-
//this event will be called as soon as we are starting to initialize our session, but BEFORE mam catchup happens
181-
//NOTE: this event won't be called for smacks resumes!
182-
if(_account == ((xmpp*)notification.object))
183-
{
184-
//join MUCs from (current) muc_favorites db, the pending bookmarks fetch will join the remaining currently unknown mucs
185-
for(NSString* room in [[DataLayer sharedInstance] listMucsForAccount:_account.accountID])
186-
[self join:room];
187-
}
188-
}
189-
190177
-(void) handleCatchupDone:(NSNotification*) notification
191178
{
192179
//this event will be called as soon as mam OR smacks catchup on our account is done, it does not wait for muc mam catchups!

Monal/Classes/MLOMEMO.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ -(void) handleResourceBound:(NSNotification*) notification
173173
#ifndef DISABLE_OMEMO
174174
if(self.account.accountID.intValue == ((xmpp*)notification.object).accountID.intValue)
175175
{
176-
DDLogInfo(@"We did a non-smacks-resume reconnect, resetting some of our state...");
176+
DDLogInfo(@"We did a non-smacks-resume reconnect, resetting some of our state (MLOMEMO instance=%@)...", self);
177177
DDLogVerbose(@"Current state: %@", self.state);
178178

179179
//we bound a new xmpp session --> reset our whole state

Monal/Classes/xmpp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ typedef NS_ENUM (NSInteger, xmppState) {
2727
kStateLoggedIn,
2828
kStateBinding,
2929
kStateBound,
30-
kStateInitStarted, //is operating normally
30+
kStateInitStarted, //initializing session (smacks resume and non-smacks resume)
31+
kStateCatchupDone, //is operating normally
3132
};
3233

3334
typedef NS_ENUM (NSInteger, xmppRegistrationState) {

Monal/Classes/xmpp.m

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
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
5555
NSString* 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: %@\nIncoming: %@", _cachedStreamFeaturesAfterAuth, parsedStanza);
2882+
DDLogDebug(@"Stream features (after auth) already read from cache, ignoring incoming stream features (but refreshing cache).\nCached: %@\nIncoming: %@", _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\tisDoingFullReconnect=%@,\n\tlastHandledInboundStanza=%@,\n\tlastHandledOutboundStanza=%@,\n\tlastOutboundStanza=%@,\n\t#unAckedStanzas=%lu%s,\n\tstreamID=%@\n\tlastInteractionDate=%@\n\tpersistentIqHandlers=%@\n\tsupportsHttpUpload=%d\n\tpushEnabled=%d\n\tsupportsPubSub=%d\n\tsupportsModernPubSub=%d\n\tsupportsPubSubMax=%d\n\taccountDiscoDone=%d\n\t_inCatchup=%@\n\tomemo.state=%@\n\thasSeenOmemoDeviceListAfterOwnDeviceid=%@\n",
3701+
DDLogVerbose(@"%@ --> persistState(saved at %@):\n\tisDoingFullReconnect=%@,\n\tlastHandledInboundStanza=%@,\n\tlastHandledOutboundStanza=%@,\n\tlastOutboundStanza=%@,\n\t#unAckedStanzas=%lu%s,\n\tstreamID=%@\n\tlastInteractionDate=%@\n\tpersistentIqHandlers=%@\n\tsupportsHttpUpload=%d\n\tpushEnabled=%d\n\tsupportsPubSub=%d\n\tsupportsModernPubSub=%d\n\tsupportsPubSubMax=%d\n\taccountDiscoDone=%d\n\t_inCatchup=%@\n\tomemo.state=%@\n\thasSeenOmemoDeviceListAfterOwnDeviceid=%@\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: %.3fMiB / %.3fMiB)...", 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\tisDoingFullReconnect=%@,\n\tlastHandledInboundStanza=%@,\n\tlastHandledOutboundStanza=%@,\n\tlastOutboundStanza=%@,\n\t#unAckedStanzas=%lu%s,\n\tstreamID=%@,\n\tlastInteractionDate=%@\n\tpersistentIqHandlers=%@\n\tsupportsHttpUpload=%d\n\tpushEnabled=%d\n\tsupportsPubSub=%d\n\tsupportsModernPubSub=%d\n\tsupportsPubSubMax=%d\n\taccountDiscoDone=%d\n\t_inCatchup=%@\n\tomemo.state=%@\n\thasSeenOmemoDeviceListAfterOwnDeviceid=%@\n",
3899+
DDLogVerbose(@"%@ --> readState(saved at %@):\n\tisDoingFullReconnect=%@,\n\tlastHandledInboundStanza=%@,\n\tlastHandledOutboundStanza=%@,\n\tlastOutboundStanza=%@,\n\t#unAckedStanzas=%lu%s,\n\tstreamID=%@,\n\tlastInteractionDate=%@\n\tpersistentIqHandlers=%@\n\tsupportsHttpUpload=%d\n\tpushEnabled=%d\n\tsupportsPubSub=%d\n\tsupportsModernPubSub=%d\n\tsupportsPubSubMax=%d\n\taccountDiscoDone=%d\n\t_inCatchup=%@\n\tomemo.state=%@\n\thasSeenOmemoDeviceListAfterOwnDeviceid=%@\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

Comments
 (0)