Fix closed group session establishment issue

This commit is contained in:
nielsandriesse 2020-05-06 10:20:29 +10:00
parent 0f20c15407
commit 0a3b1a20cd
5 changed files with 19 additions and 7 deletions

View File

@ -190,8 +190,11 @@ final class DeviceLinkingModal : Modal, DeviceLinkingSessionDelegate {
let thread = TSContactThread.getOrCreateThread(withContactId: slaveHexEncodedPublicKey, transaction: transaction)
thread.save(with: transaction)
}
let _ = SSKEnvironment.shared.syncManager.syncAllContacts()
let _ = SSKEnvironment.shared.syncManager.syncAllGroups()
let _ = SSKEnvironment.shared.syncManager.syncAllGroups().ensure {
// Closed groups first because we prefer the session request mechanism
// to the AFR mechanism
let _ = SSKEnvironment.shared.syncManager.syncAllContacts()
}
let _ = SSKEnvironment.shared.syncManager.syncAllOpenGroups()
storage.dbReadWriteConnection.readWrite { transaction in
storage.setFriendRequestStatus(.friends, for: slaveHexEncodedPublicKey, transaction: transaction)

View File

@ -270,8 +270,7 @@ NSString *const kSyncManagerLastContactSyncKey = @"kTSStorageManagerOWSSyncManag
- (AnyPromise *)syncContact:(NSString *)hexEncodedPubKey transaction:(YapDatabaseReadTransaction *)transaction
{
[LKSyncMessagesProtocol syncContactWithHexEncodedPublicKey:hexEncodedPubKey in:transaction];
return [AnyPromise promiseWithValue:@1];
return [LKSyncMessagesProtocol syncContactWithHexEncodedPublicKey:hexEncodedPubKey in:transaction];
}
- (AnyPromise *)syncAllContacts

View File

@ -42,6 +42,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)markRecipientAsRegistered:(NSString *)recipientId
deviceId:(UInt32)deviceId
transaction:(YapDatabaseReadWriteTransaction *)transaction;
+ (void)markRecipientAsUnregistered:(NSString *)recipientId transaction:(YapDatabaseReadWriteTransaction *)transaction;
@end

View File

@ -180,6 +180,7 @@ public final class SessionManagementProtocol : NSObject {
storage.setPreKeyBundle(preKeyBundle, forContact: hexEncodedPublicKey, transaction: transaction)
// If we received a friend request (i.e. also a new pre key bundle), but we were already friends with the other user, reset the session.
// The envelope type is set during UD decryption.
// TODO: Should this ignore session requests?
if envelope.type == .friendRequest,
let thread = TSContactThread.getWithContactId(hexEncodedPublicKey, transaction: transaction), // TODO: Should this be getOrCreate?
thread.isContactFriend {

View File

@ -37,14 +37,22 @@ public final class SyncMessagesProtocol : NSObject {
}
public static func syncAllContacts() -> Promise<Void> {
var friends: [SignalAccount] = []
// Collect all master devices with which a session has been established. Note that
// this is not the same as all master devices with which we're friends.
var hepks: Set<String> = []
TSContactThread.enumerateCollectionObjects { object, _ in
guard let thread = object as? TSContactThread else { return }
let hexEncodedPublicKey = thread.contactIdentifier()
guard thread.isContactFriend && thread.shouldThreadBeVisible && !thread.isSlaveThread else { return }
friends.append(SignalAccount(recipientId: hexEncodedPublicKey))
hepks.insert(hexEncodedPublicKey)
}
friends.append(SignalAccount(recipientId: getUserHexEncodedPublicKey())) // TODO: Are we sure about this?
TSGroupThread.enumerateCollectionObjects { object, _ in
guard let group = object as? TSGroupThread, group.groupModel.groupType == .closedGroup,
group.shouldThreadBeVisible else { return }
hepks.formUnion(group.groupModel.groupMemberIds)
}
hepks.insert(getUserHexEncodedPublicKey()) // TODO: Are we sure about this?
let friends = hepks.map { SignalAccount(recipientId: $0) }
let syncManager = SSKEnvironment.shared.syncManager
let promises = friends.chunked(by: 3).map { friends -> Promise<Void> in // TODO: Does this always fit?
return Promise(syncManager.syncContacts(for: friends)).map { _ in }