Skip to content

Commit 08fd59d

Browse files
Fix pending approval issue from half-finished presence requests
1 parent e74b8e7 commit 08fd59d

File tree

6 files changed

+26
-14
lines changed

6 files changed

+26
-14
lines changed

ChatSecure/Classes/Controllers/OTROMEMOSignalCoordinator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ extension OTROMEMOSignalCoordinator: OMEMOModuleDelegate {
545545
result = true
546546
} catch let err as NSError {
547547
#if DEBUG
548-
NSLog("Error consuming incoming bundle %@", err)
548+
NSLog("Error consuming incoming bundle %@ %@", err, responseIq.prettyXMLString())
549549
#endif
550550
}
551551
self?.callAndRemoveOutstandingBundleBlock(elementId!, success: result)

ChatSecure/Classes/Controllers/XMPP/OTRXMPPManager.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
@import Foundation;
2424
@import UIKit;
2525
@import XMPPFramework;
26-
#import "OTRBuddy.h"
26+
#import "OTRXMPPBuddy.h"
2727
#import "OTRIncomingMessage.h"
2828
#import "OTROutgoingMessage.h"
2929
#import "OTRProtocol.h"
@@ -73,8 +73,8 @@ NS_ASSUME_NONNULL_BEGIN
7373

7474
- (void)changePassword:(NSString *)newPassword completion:(void (^)(BOOL,NSError*))completion;
7575

76-
/** Will send a probe to fetch last seen */
77-
- (void) sendPresenceProbeForBuddy:(OTRBuddy*)buddy;
76+
/** Will try to send a probe to fetch last seen. If buddy is still pendingApproval it will retry subscription request. */
77+
- (void) sendPresenceProbeForBuddy:(OTRXMPPBuddy*)buddy;
7878

7979
/** Will send an away presence with your last idle timestamp */
8080
- (void) goAway;

ChatSecure/Classes/Controllers/XMPP/OTRXMPPManager.m

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,11 +514,20 @@ - (BOOL)continueRegisteringNewAccount
514514
#pragma mark Public Methods
515515

516516
/** Will send a probe to fetch last seen */
517-
- (void) sendPresenceProbeForBuddy:(OTRBuddy*)buddy {
517+
- (void) sendPresenceProbeForBuddy:(OTRXMPPBuddy*)buddy {
518+
NSParameterAssert(buddy);
519+
if (!buddy) { return; }
520+
XMPPJID *jid = buddy.bareJID;
521+
if (!jid) { return; }
522+
523+
// We can't probe presence if we are still pending approval, so resend the request.
524+
if (buddy.pendingApproval) {
525+
[self.xmppRoster subscribePresenceToUser:jid];
526+
return;
527+
}
528+
518529
// https://xmpp.org/extensions/xep-0318.html
519530
// <presence from='juliet@capulet.com/balcony' to='romeo@montague.com' type='probe' />
520-
XMPPJID *jid = [XMPPJID jidWithString:buddy.username];
521-
if (!jid) { return; }
522531
XMPPPresence *probe = [XMPPPresence presenceWithType:@"probe" to:jid];
523532
if (!probe) { return; }
524533
[self.xmppStream sendElement:probe];

ChatSecure/Classes/Model/Yap Storage/OTRXMPPBuddy.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@
99
#import "OTRBuddy.h"
1010
#import "OTRvCard.h"
1111

12-
@class XMPPvCardTemp;
12+
@import XMPPFramework;
1313

1414
/** Contains userInfo with buddy object in "buddy" key */
1515
extern NSString * _Nonnull const OTRBuddyPendingApprovalDidChangeNotification;
1616

1717
@interface OTRXMPPBuddy : OTRBuddy <OTRvCard>
1818

19+
/** Returns the bare JID derived from the self.username property */
20+
@property (nonatomic, strong, readonly, nullable) XMPPJID *bareJID;
1921

2022
/** This is for outgoing subscription requests */
2123
@property (nonatomic) BOOL pendingApproval;
2224
/** Incoming subscription requests mean this object is a stub/placeholder */
2325
@property (nonatomic) BOOL hasIncomingSubscriptionRequest;
2426

25-
26-
27-
2827
@end

ChatSecure/Classes/Model/Yap Storage/OTRXMPPBuddy.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ - (NSString *)threadName
7171
return threadName;
7272
}
7373

74+
- (nullable XMPPJID*) bareJID {
75+
return [XMPPJID jidWithString:self.username];
76+
}
77+
7478
#pragma - mark Class Methods
7579

7680
+ (NSString *)collection

ChatSecure/Classes/View Controllers/OTRMessagesViewController.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,12 +376,12 @@ - (nullable OTRXMPPManager *)xmppManagerWithTransaction:(nonnull YapDatabaseRead
376376
/** Will send a probe to fetch last seen */
377377
- (void) sendPresenceProbe {
378378
__block OTRXMPPManager *xmpp = nil;
379-
__block OTRBuddy *buddy = nil;
379+
__block OTRXMPPBuddy *buddy = nil;
380380
[self.readOnlyDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction * _Nonnull transaction) {
381381
xmpp = [self xmppManagerWithTransaction:transaction];
382-
buddy = [self buddyWithTransaction:transaction];
382+
buddy = (OTRXMPPBuddy*)[self buddyWithTransaction:transaction];
383383
}];
384-
if (!xmpp || !buddy) { return; }
384+
if (!xmpp || ![buddy isKindOfClass:[OTRXMPPBuddy class]]) { return; }
385385
[xmpp sendPresenceProbeForBuddy:buddy];
386386
}
387387

0 commit comments

Comments
 (0)