Skip to content

Commit

Permalink
MXSession: handleSyncResponse: Decrypt asynchronously to_device events
Browse files Browse the repository at this point in the history
MXCrypto.handleRoomKeyEvent() has been added to know exactly when we can start decrypting.
  • Loading branch information
manuroe committed May 11, 2021
1 parent b3cfb97 commit 4791c86
Show file tree
Hide file tree
Showing 4 changed files with 257 additions and 211 deletions.
8 changes: 8 additions & 0 deletions MatrixSDK/Crypto/MXCrypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ extern NSString *const MXDeviceListDidUpdateUsersDevicesNotification;
*/
- (void)handleDeviceOneTimeKeysCount:(NSDictionary<NSString *, NSNumber*>*)deviceOneTimeKeysCount;

/**
Handle a room key event.
@param event the room key event.
@param onComplete the block called when the operation completes.
*/
- (void)handleRoomKeyEvent:(MXEvent*)event onComplete:(void (^)(void))onComplete;

/**
Handle the completion of a /sync.
Expand Down
13 changes: 12 additions & 1 deletion MatrixSDK/Crypto/MXCrypto.m
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,18 @@ - (void)handleDeviceListsChanges:(MXDeviceListResponse*)deviceLists
#endif
}

- (void)handleRoomKeyEvent:(MXEvent*)event onComplete:(void (^)(void))onComplete
{
// Use decryptionQueue as synchronisation because decryptions require room keys
dispatch_async(decryptionQueue, ^{
[self onRoomKeyEvent:event];

dispatch_async(dispatch_get_main_queue(), ^{
onComplete();
});
});
}

- (void)handleDeviceOneTimeKeysCount:(NSDictionary<NSString *, NSNumber*>*)deviceOneTimeKeysCount
{
#ifdef MX_CRYPTO
Expand Down Expand Up @@ -2518,7 +2530,6 @@ - (void)onToDeviceEvent:(NSNotification *)notification
MXWeakify(self);
switch (event.eventType)
{
case MXEventTypeRoomKey:
case MXEventTypeRoomForwardedKey:
{
dispatch_async(_cryptoQueue, ^{
Expand Down

0 comments on commit 4791c86

Please sign in to comment.