Skip to content

Commit 9e4c86b

Browse files
Allow users to ping the configured push appserver for debugging
1 parent 85af075 commit 9e4c86b

File tree

5 files changed

+57
-12
lines changed

5 files changed

+57
-12
lines changed

Monal/Classes/HelperTools.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ void swizzle(Class c, SEL orig, SEL new);
9292
+(void) postError:(NSString*) description withNode:(XMPPStanza* _Nullable) node andAccount:(xmpp*) account andIsSevere:(BOOL) isSevere andDisableAccount:(BOOL) disableAccount;
9393
+(void) postError:(NSString*) description withNode:(XMPPStanza* _Nullable) node andAccount:(xmpp*) account andIsSevere:(BOOL) isSevere;
9494
+(NSString*) extractXMPPError:(XMPPStanza*) stanza withDescription:(NSString* _Nullable) description;
95+
+(NSError*) getNSErrorFrom:(XMPPStanza*) stanza withDescription:(NSString*) description;
9596
+(void) showErrorOnAlpha:(NSString*) description withNode:(XMPPStanza* _Nullable) node andAccount:(xmpp* _Nullable) account andFile:(char*) file andLine:(int) line andFunc:(char*) func;
9697

9798
+(NSDictionary<NSString*, NSString*>*) getInvalidPushServers;

Monal/Classes/HelperTools.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,12 @@ +(NSString*) extractXMPPError:(XMPPStanza*) stanza withDescription:(NSString*) d
664664
return message;
665665
}
666666

667+
+(NSError*) getNSErrorFrom:(XMPPStanza*) stanza withDescription:(NSString*) description
668+
{
669+
NSString* errorMessage = [HelperTools extractXMPPError:stanza withDescription:description];
670+
return [NSError errorWithDomain:@"Monal" code:0 userInfo:@{NSLocalizedDescriptionKey: errorMessage}];
671+
}
672+
667673
+(void) initSystem
668674
{
669675
BOOL enableDefaultLogAndCrashFramework = YES;

Monal/Classes/NotificationDebugging.swift

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct NotificationDebugging: View {
2525

2626
@State private var pushPermissionEnabled = false // state because we get this value through an async call
2727
@State private var showPushToken = false
28+
@State var runningPings: [String:any View]
2829

2930
@ObservedObject var notificationDebuggingDefaultsDB = NotificationDebuggingDefaultsDB()
3031

@@ -35,6 +36,7 @@ struct NotificationDebugging: View {
3536

3637
// push server selector
3738
self.availablePushServers = HelperTools.getAvailablePushServers()
39+
self.runningPings = [:]
3840
}
3941

4042
var body: some View {
@@ -106,14 +108,35 @@ struct NotificationDebugging: View {
106108
}
107109
}
108110
}
109-
#if DEBUG
110111
Section(header: Text("Debugging").font(.title3)) {
112+
Button("Ping push servers") {
113+
for account in self.xmppAccountInfo {
114+
runningPings[account.connectionProperties.identity.jid] = Text("Running...")
115+
account.pingPushserver().done { _ in
116+
runningPings[account.connectionProperties.identity.jid] = Text("Successful").foregroundColor(.green)
117+
}.catch { error in
118+
runningPings[account.connectionProperties.identity.jid] = Text(error.localizedDescription).foregroundColor(.red)
119+
}
120+
}
121+
}
122+
123+
if self.runningPings.count > 0 {
124+
VStack(alignment: .leading, spacing:10) {
125+
ForEach(self.runningPings.sorted(by:{ $0.0 < $1.0 }), id: \.key) { key, view in
126+
HStack {
127+
Text("\(String(describing:key)): ")
128+
AnyView(view)
129+
}
130+
}
131+
}
132+
}
133+
#if DEBUG
111134
Button("Reregister push token") {
112135
UIApplication.shared.unregisterForRemoteNotifications()
113136
UIApplication.shared.registerForRemoteNotifications()
114137
}
115-
}
116138
#endif
139+
}
117140
}
118141
.navigationBarTitle(Text("Notifications"))
119142
.onAppear(perform: {

Monal/Classes/xmpp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ typedef void (^monal_iq_handler_t)(XMPPIQ* _Nullable);
150150
Adds the stanza to the output Queue
151151
*/
152152
-(void) send:(MLXMLNode*) stanza;
153+
-(AnyPromise*) sendIq:(XMPPIQ*) iq;
153154
-(void) sendIq:(XMPPIQ*) iq withResponseHandler:(monal_iq_handler_t) resultHandler andErrorHandler:(monal_iq_handler_t) errorHandler;
154155
-(void) sendIq:(XMPPIQ*) iq withHandler:(MLHandler* _Nullable) handler;
155156

@@ -204,6 +205,7 @@ typedef void (^monal_iq_handler_t)(XMPPIQ* _Nullable);
204205
*/
205206
-(void) enablePush;
206207
-(void) disablePush;
208+
-(AnyPromise*) pingPushserver;
207209

208210
-(void) mamFinishedFor:(NSString*) archiveJid;
209211

Monal/Classes/xmpp.m

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3774,16 +3774,21 @@ -(NSString* _Nullable) channelBindingToUse
37743774

37753775
#pragma mark stanza handling
37763776

3777-
// -(AnyPromise*) sendIq:(XMPPIQ*) iq
3778-
// {
3779-
// return [AnyPromise promiseWithResolverBlock:^(PMKResolver resolve) {
3780-
// [self sendIq:iq withResponseHandler:^(XMPPIQ* response) {
3781-
// resolve(response);
3782-
// } andErrorHandler:^(XMPPIQ* error) {
3783-
// resolve(error);
3784-
// }];
3785-
// }];
3786-
// }
3777+
-(AnyPromise*) sendIq:(XMPPIQ*) iq
3778+
{
3779+
return [self sendIq:iq withErrorDescription:nil];
3780+
}
3781+
3782+
-(AnyPromise*) sendIq:(XMPPIQ*) iq withErrorDescription:(NSString*) description
3783+
{
3784+
return [AnyPromise promiseWithResolverBlock:^(PMKResolver resolve) {
3785+
[self sendIq:iq withResponseHandler:^(XMPPIQ* response) {
3786+
resolve(response);
3787+
} andErrorHandler:^(XMPPIQ* error) {
3788+
resolve([HelperTools getNSErrorFrom:error withDescription:description]);
3789+
}];
3790+
}];
3791+
}
37873792

37883793
-(void) sendIq:(XMPPIQ*) iq withResponseHandler:(monal_iq_handler_t) resultHandler andErrorHandler:(monal_iq_handler_t) errorHandler
37893794
{
@@ -6054,6 +6059,14 @@ -(void) publishStatusMessage:(NSString*) message
60546059
[self sendPresence];
60556060
}
60566061

6062+
-(AnyPromise*) pingPushserver
6063+
{
6064+
NSString* selectedPushServer = [[HelperTools defaultsDB] objectForKey:@"selectedPushServer"];
6065+
XMPPIQ* ping = [[XMPPIQ alloc] initWithType:kiqGetType to:selectedPushServer];
6066+
[ping setPing];
6067+
return [self sendIq:ping withErrorDescription:@"Ping error"];
6068+
}
6069+
60576070
-(NSString*) description
60586071
{
60596072
return [NSString stringWithFormat:@"%@[%@]: %@", self.accountID, _internalID, self.connectionProperties.identity.jid];

0 commit comments

Comments
 (0)