Skip to content

Commit

Permalink
Add a debug setting to invalidate all account states
Browse files Browse the repository at this point in the history
This can be useful if monal is in a crash loop
  • Loading branch information
lissine0 authored and tmolitor-stud-tu committed Jan 24, 2025
1 parent aa5aa76 commit 32cf646
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Monal/Classes/DebugView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,18 @@ struct CrashTestingView: View {

var body: some View {
VStack(alignment:.leading, spacing: 25) {
Section(header: Text("Some debug settings.")) {
Section(header: Text("Some debug settings:")) {
Toggle(isOn: $defaultDB.hasCompletedOnboarding) {
Text("Don't show onboarding")
}

Toggle(isOn: $defaultDB.showNewChatView) {
Text("Show new SwiftUI ChatView")
}

Button("Reset the state of all accounts") {
MLXMPPManager.sharedInstance().resetAllAccountStates()
}
}

Text("The following buttons allow you to forcefully crash the app using several different methods to test the crash handling.")
Expand Down
5 changes: 5 additions & 0 deletions Monal/Classes/MLXMPPManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
-(void) connectAccount:(NSNumber*) accountID;

/**
does a full reset for every account, as if they were freshly created
*/
-(void) resetAllAccountStates;

#pragma mark XMPP commands
/**
Remove a contact from an account
Expand Down
13 changes: 13 additions & 0 deletions Monal/Classes/MLXMPPManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,19 @@ -(void) disconnectAll
DDLogVerbose(@"manager disconnecAll done");
}

-(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]];

//reset enabled accounts
for(xmpp* xmppAccount in [self connectedXMPP])
[xmppAccount resetAccountState];
}
-(void) connectIfNecessary
{
DDLogVerbose(@"manager connectIfNecessary");
Expand Down
3 changes: 2 additions & 1 deletion Monal/Classes/xmpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ typedef void (^monal_iq_handler_t)(XMPPIQ* _Nullable);
-(void) disconnect:(BOOL) explicitLogout;
-(void) reconnect;
-(void) reconnect:(double) wait;
-(void) resetAccountState;

-(void) setPubSubNotificationsForNodes:(NSArray* _Nonnull) nodes persistState:(BOOL) persistState;

Expand Down Expand Up @@ -235,7 +236,7 @@ typedef void (^monal_iq_handler_t)(XMPPIQ* _Nullable);
-(void) publishStatusMessage:(NSString*) message;
-(void) delayIncomingMessageStanzasForArchiveJid:(NSString*) archiveJid;

+(NSMutableDictionary*) invalidateState:(NSDictionary*) dic;
+(NSMutableDictionary*) invalidateState:(NSDictionary* _Nullable) dic;
-(void) updateIqHandlerTimeouts;

-(void) addReconnectionHandler:(MLHandler*) handler;
Expand Down
16 changes: 16 additions & 0 deletions Monal/Classes/xmpp.m
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,22 @@ -(void) reconnectWithStreamError:(MLXMLNode* _Nullable) streamError andWaitingTi
}];
}

-(void) resetAccountState
{
NSMutableDictionary* dic = [xmpp invalidateState:nil];
if ([[DataLayer sharedInstance] isAccountEnabled:self.accountID])
{
[self dispatchAsyncOnReceiveQueue: ^{
[[DataLayer sharedInstance] persistState:dic forAccount:self.accountID];
[self readState];
}];
}
else
{
[[DataLayer sharedInstance] persistState:dic forAccount:self.accountID];
}
}

#pragma mark XMPP

-(void) prepareXMPPParser
Expand Down

0 comments on commit 32cf646

Please sign in to comment.