From a7db4485dff59c04117cb590764bbcc65f0625cd Mon Sep 17 00:00:00 2001 From: Ryan Zhao Date: Thu, 15 Jun 2023 10:58:36 +1000 Subject: [PATCH] resolve a race condition of expireTimerUpdate and configUpdate --- .../MessageReceiver+ExpirationTimers.swift | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+ExpirationTimers.swift b/SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+ExpirationTimers.swift index 06d9f9d77..640b2cac5 100644 --- a/SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+ExpirationTimers.swift +++ b/SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+ExpirationTimers.swift @@ -164,7 +164,7 @@ extension MessageReceiver { guard let localLastChangeTimestampMs = localConfig.lastChangeTimestampMs, - protoLastChangeTimestampMs > localLastChangeTimestampMs + protoLastChangeTimestampMs >= localLastChangeTimestampMs else { return } let durationSeconds: TimeInterval = (proto.hasExpirationTimer ? TimeInterval(proto.expirationTimer) : 0) @@ -180,33 +180,35 @@ extension MessageReceiver { lastChangeTimestampMs: protoLastChangeTimestampMs ) - _ = try remoteConfig.save(db) + if localConfig != remoteConfig { + _ = try remoteConfig.save(db) + + // Contacts & legacy closed groups need to update the SessionUtil + switch threadVariant { + case .contact: + try SessionUtil + .update( + db, + sessionId: threadId, + disappearingMessagesConfig: remoteConfig + ) + + case .legacyGroup: + try SessionUtil + .update( + db, + groupPublicKey: threadId, + disappearingConfig: remoteConfig + ) + + default: break + } + } _ = try Interaction .filter(Interaction.Columns.threadId == threadId) .filter(Interaction.Columns.variant == Interaction.Variant.infoDisappearingMessagesUpdate) .deleteAll(db) - - // Contacts & legacy closed groups need to update the SessionUtil - switch threadVariant { - case .contact: - try SessionUtil - .update( - db, - sessionId: threadId, - disappearingMessagesConfig: remoteConfig - ) - - case .legacyGroup: - try SessionUtil - .update( - db, - groupPublicKey: threadId, - disappearingConfig: remoteConfig - ) - - default: break - } _ = try Interaction( serverHash: message.serverHash,