mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Updated the code to only add closed groups for the first config message received
This commit is contained in:
parent
a6ceaa3cc4
commit
0f78e1af61
1 changed files with 17 additions and 8 deletions
|
@ -190,6 +190,7 @@ extension MessageReceiver {
|
|||
SNLog("Configuration message received.")
|
||||
let storage = SNMessagingKitConfiguration.shared.storage
|
||||
let transaction = transaction as! YapDatabaseReadWriteTransaction
|
||||
let isInitialSync: Bool = (!UserDefaults.standard[.hasSyncedInitialConfiguration])
|
||||
let messageSentTimestamp: TimeInterval = TimeInterval((message.sentTimestamp ?? 0) / 1000) // `sentTimestamp` is in ms
|
||||
let lastConfigTimestamp: TimeInterval = (UserDefaults.standard[.lastConfigurationSync]?.timeIntervalSince1970 ?? Date(timeIntervalSince1970: 0).timeIntervalSince1970)
|
||||
|
||||
|
@ -199,8 +200,8 @@ extension MessageReceiver {
|
|||
updateProfileIfNeeded(publicKey: userPublicKey, name: message.displayName, profilePictureURL: message.profilePictureURL,
|
||||
profileKey: userProfileKey, sentTimestamp: message.sentTimestamp!, transaction: transaction)
|
||||
|
||||
if !UserDefaults.standard[.hasSyncedInitialConfiguration] || messageSentTimestamp > lastConfigTimestamp {
|
||||
if !UserDefaults.standard[.hasSyncedInitialConfiguration] {
|
||||
if isInitialSync || messageSentTimestamp > lastConfigTimestamp {
|
||||
if isInitialSync {
|
||||
UserDefaults.standard[.hasSyncedInitialConfiguration] = true
|
||||
NotificationCenter.default.post(name: .initialConfigurationMessageReceived, object: nil)
|
||||
}
|
||||
|
@ -257,13 +258,21 @@ extension MessageReceiver {
|
|||
}
|
||||
|
||||
// Closed groups
|
||||
let allClosedGroupPublicKeys = storage.getUserClosedGroupPublicKeys()
|
||||
for closedGroup in message.closedGroups {
|
||||
guard !allClosedGroupPublicKeys.contains(closedGroup.publicKey) else { continue }
|
||||
handleNewClosedGroup(groupPublicKey: closedGroup.publicKey, name: closedGroup.name, encryptionKeyPair: closedGroup.encryptionKeyPair,
|
||||
members: [String](closedGroup.members), admins: [String](closedGroup.admins), expirationTimer: closedGroup.expirationTimer,
|
||||
messageSentTimestamp: message.sentTimestamp!, using: transaction)
|
||||
//
|
||||
// Note: Only want to add these for initial sync to avoid re-adding closed groups the user
|
||||
// intentionally left (any closed groups joined since the first processed sync message should
|
||||
// get added via the 'handleNewClosedGroup' method anyway as they will have come through in the
|
||||
// past two weeks)
|
||||
if isInitialSync {
|
||||
let allClosedGroupPublicKeys = storage.getUserClosedGroupPublicKeys()
|
||||
for closedGroup in message.closedGroups {
|
||||
guard !allClosedGroupPublicKeys.contains(closedGroup.publicKey) else { continue }
|
||||
handleNewClosedGroup(groupPublicKey: closedGroup.publicKey, name: closedGroup.name, encryptionKeyPair: closedGroup.encryptionKeyPair,
|
||||
members: [String](closedGroup.members), admins: [String](closedGroup.admins), expirationTimer: closedGroup.expirationTimer,
|
||||
messageSentTimestamp: message.sentTimestamp!, using: transaction)
|
||||
}
|
||||
}
|
||||
|
||||
// Open groups
|
||||
for openGroupURL in message.openGroups {
|
||||
if let (room, server, publicKey) = OpenGroupManagerV2.parseV2OpenGroup(from: openGroupURL) {
|
||||
|
|
Loading…
Reference in a new issue