From 2df820339c08907031ccb005dde2babe746cbb7c Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Tue, 13 Jun 2023 15:01:11 +1000 Subject: [PATCH] refactor on adding expiration on interactions before inserted into database --- .../Database/Models/Interaction.swift | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/SessionMessagingKit/Database/Models/Interaction.swift b/SessionMessagingKit/Database/Models/Interaction.swift index 3705d597d..73c56bbee 100644 --- a/SessionMessagingKit/Database/Models/Interaction.swift +++ b/SessionMessagingKit/Database/Models/Interaction.swift @@ -373,22 +373,17 @@ public struct Interaction: Codable, Identifiable, Equatable, FetchableRecord, Mu self.wasRead = (self.wasRead || !self.variant.canBeUnread) // Automatically add disapeparing messages configuration - if - self.variant.shouldFollowDisappearingMessagesConfiguration && - self.expiresInSeconds == nil && - self.expiresStartedAtMs == nil - { - if + if self.variant.shouldFollowDisappearingMessagesConfiguration { + guard let disappearingMessagesConfiguration = try? DisappearingMessagesConfiguration.fetchOne(db, id: self.threadId), disappearingMessagesConfiguration.isEnabled - { - self.expiresInSeconds = disappearingMessagesConfiguration.durationSeconds - if disappearingMessagesConfiguration.type == .disappearAfterSend { - self.expiresStartedAtMs = Double(self.timestampMs) - } - } else { - self.expiresInSeconds = 0 + else { + self.expiresInSeconds = self.expiresInSeconds ?? 0 + return } + + self.expiresInSeconds = self.expiresInSeconds ?? disappearingMessagesConfiguration.durationSeconds + self.expiresStartedAtMs = disappearingMessagesConfiguration.type == .disappearAfterSend ? Double(self.timestampMs) : nil } }