Skip to content

Commit

Permalink
Improve account reset implementation accessible from debug menu
Browse files Browse the repository at this point in the history
  • Loading branch information
tmolitor-stud-tu committed Jan 24, 2025
1 parent 0567437 commit bcf0dfb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
22 changes: 13 additions & 9 deletions Monal/Classes/MLXMPPManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -627,17 +627,21 @@ -(void) disconnectAll

-(void) resetAllAccountStates
{
NSArray* allAccounts = [[DataLayer sharedInstance] accountList];
NSMutableDictionary* dic = [xmpp invalidateState:nil];
//reset disabled accounts
for(NSDictionary* account in allAccounts)
if(![[account objectForKey:kEnabled] boolValue])
[[DataLayer sharedInstance] persistState:dic forAccount:[account objectForKey:kAccountID]];
//make sure now account transitions from enabled to disabled while resetting everything
//(accounts transitioned, will still be present in connectedXMPP and thus resetted by [xmppAccount resetAccountState], too)
@synchronized(_connectedXMPP) {
//reset disabled accounts
NSMutableDictionary* newState = [xmpp invalidateState:nil];
for(NSDictionary* account in [[DataLayer sharedInstance] accountList])
if(![account[kEnabled] boolValue])
[[DataLayer sharedInstance] persistState:newState forAccount:account[kAccountID]];

//reset enabled accounts
for(xmpp* xmppAccount in [self connectedXMPP])
[xmppAccount resetAccountState];
//reset enabled accounts
for(xmpp* xmppAccount in [self connectedXMPP])
[xmppAccount resetAccountState];
}
}

-(void) connectIfNecessary
{
DDLogVerbose(@"manager connectIfNecessary");
Expand Down
12 changes: 7 additions & 5 deletions Monal/Classes/xmpp.m
Original file line number Diff line number Diff line change
Expand Up @@ -1310,17 +1310,19 @@ -(void) reconnectWithStreamError:(MLXMLNode* _Nullable) streamError andWaitingTi

-(void) resetAccountState
{
NSMutableDictionary* dic = [xmpp invalidateState:nil];
if ([[DataLayer sharedInstance] isAccountEnabled:self.accountID])
NSMutableDictionary* newState = [xmpp invalidateState:nil];
if([[DataLayer sharedInstance] isAccountEnabled:self.accountID])
{
[self dispatchAsyncOnReceiveQueue: ^{
[[DataLayer sharedInstance] persistState:dic forAccount:self.accountID];
[self readState];
[self disconnect:YES]; //make sure we are in a safe state before resetting our state
[[DataLayer sharedInstance] persistState:newState forAccount:self.accountID];
[self connect]; //this will reread persisted state saved above
}];
}
else
{
[[DataLayer sharedInstance] persistState:dic forAccount:self.accountID];
[[DataLayer sharedInstance] persistState:newState forAccount:self.accountID];
[self readState]; //better safe than sorry
}
}

Expand Down

0 comments on commit bcf0dfb

Please sign in to comment.