refactor on adding expiration on interactions before inserted into database

pull/941/head
ryanzhao 1 year ago
parent ae78abc5a4
commit 2df820339c

@ -373,22 +373,17 @@ public struct Interaction: Codable, Identifiable, Equatable, FetchableRecord, Mu
self.wasRead = (self.wasRead || !self.variant.canBeUnread) self.wasRead = (self.wasRead || !self.variant.canBeUnread)
// Automatically add disapeparing messages configuration // Automatically add disapeparing messages configuration
if if self.variant.shouldFollowDisappearingMessagesConfiguration {
self.variant.shouldFollowDisappearingMessagesConfiguration && guard
self.expiresInSeconds == nil &&
self.expiresStartedAtMs == nil
{
if
let disappearingMessagesConfiguration = try? DisappearingMessagesConfiguration.fetchOne(db, id: self.threadId), let disappearingMessagesConfiguration = try? DisappearingMessagesConfiguration.fetchOne(db, id: self.threadId),
disappearingMessagesConfiguration.isEnabled disappearingMessagesConfiguration.isEnabled
{ else {
self.expiresInSeconds = disappearingMessagesConfiguration.durationSeconds self.expiresInSeconds = self.expiresInSeconds ?? 0
if disappearingMessagesConfiguration.type == .disappearAfterSend { return
self.expiresStartedAtMs = Double(self.timestampMs)
}
} else {
self.expiresInSeconds = 0
} }
self.expiresInSeconds = self.expiresInSeconds ?? disappearingMessagesConfiguration.durationSeconds
self.expiresStartedAtMs = disappearingMessagesConfiguration.type == .disappearAfterSend ? Double(self.timestampMs) : nil
} }
} }

Loading…
Cancel
Save