Skip to content

Commit ece2e8f

Browse files
authored
Merge pull request #1437 from matrix-org/langleyd/4470_notify_verification_acceptance
Notify other devices of verification acceptance
2 parents 46aa52c + eb2ac99 commit ece2e8f

File tree

5 files changed

+39
-0
lines changed

5 files changed

+39
-0
lines changed

MatrixSDK/Crypto/Verification/Data/MXTransactionCancelCode.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ NS_ASSUME_NONNULL_BEGIN
7171
// The QR code is invalid
7272
+ (instancetype)qrCodeInvalid;
7373

74+
// Verification request accepted by another device
75+
+ (instancetype)accepted;
76+
7477
@end
7578

7679
NS_ASSUME_NONNULL_END

MatrixSDK/Crypto/Verification/Data/MXTransactionCancelCode.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,9 @@ + (instancetype)qrCodeInvalid
8787
return [[MXTransactionCancelCode alloc] initWithValue:@"m.qr_code.invalid" humanReadable:@"Invalid QR code"];
8888
}
8989

90+
+ (instancetype)accepted
91+
{
92+
return [[MXTransactionCancelCode alloc] initWithValue:@"m.accepted" humanReadable:@"Verification request accepted by another device"];
93+
}
94+
9095
@end

MatrixSDK/Crypto/Verification/MXKeyVerificationManager.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,13 @@ FOUNDATION_EXPORT NSString *const MXKeyVerificationManagerNotificationTransactio
203203
*/
204204
- (void)removeQRCodeTransactionWithTransactionId:(NSString*)transactionId;
205205

206+
207+
- (void)notifyOthersOfAcceptanceWithTransactionId:(NSString*)transactionId
208+
acceptedUserId:(NSString*)acceptedUserId
209+
acceptedDeviceId:(NSString*)acceptedDeviceId
210+
success:(void(^)(void))success
211+
failure:(void(^)(NSError *error))failure;
212+
206213
@end
207214

208215
NS_ASSUME_NONNULL_END

MatrixSDK/Crypto/Verification/MXKeyVerificationManager.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,25 @@ - (MXHTTPOperation*)sendToOtherInRequest:(MXKeyVerificationRequest*)request
687687
return operation;
688688
}
689689

690+
- (void)notifyOthersOfAcceptanceWithTransactionId:(NSString*)transactionId
691+
acceptedUserId:(NSString*)acceptedUserId
692+
acceptedDeviceId:(NSString*)acceptedDeviceId
693+
success:(void(^)(void))success
694+
failure:(void(^)(NSError *error))failure
695+
{
696+
[self otherDeviceIdsOfUser:acceptedUserId success:^(NSArray<NSString *> *deviceIds) {
697+
NSMutableArray *nonChosenDevices = [deviceIds mutableCopy];
698+
[nonChosenDevices removeObject:acceptedDeviceId];
699+
700+
MXKeyVerificationCancel *cancel = [MXKeyVerificationCancel new];
701+
MXTransactionCancelCode *cancelCode = MXTransactionCancelCode.accepted;
702+
cancel.transactionId = transactionId;
703+
cancel.code = cancelCode.value;
704+
cancel.reason = cancelCode.humanReadable;
705+
[self sendToDevices:acceptedUserId deviceIds:nonChosenDevices eventType:kMXEventTypeStringKeyVerificationCancel content:cancel.JSONDictionary success:success failure:failure];
706+
} failure:failure];
707+
}
708+
690709
- (void)cancelVerificationRequest:(MXKeyVerificationRequest*)request
691710
success:(void(^)(void))success
692711
failure:(void(^)(NSError *error))failure

MatrixSDK/Crypto/Verification/Requests/MXKeyVerificationRequest.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ - (void)handleReady:(MXKeyVerificationReady*)readyContent
197197
{
198198
[self updateState:MXKeyVerificationRequestStateReady notifiy:YES];
199199
}
200+
[self.manager notifyOthersOfAcceptanceWithTransactionId:self.requestId acceptedUserId:self.otherUser acceptedDeviceId: self.otherDevice success:^{
201+
MXLogDebug(@"[MXKeyVerificationRequest] handleReady notified others of acceptance");
202+
} failure:^(NSError * _Nonnull error) {
203+
MXLogError(@"[MXKeyVerificationRequest] handleReady failed notify others of acceptance");
204+
}];
200205
}
201206

202207
- (void)handleCancel:(MXKeyVerificationCancel *)cancelContent

0 commit comments

Comments
 (0)