bring back false deleted logic

pull/731/head
Ryan ZHAO 1 year ago
parent 79eafa7df8
commit c9df2a73e7

@ -373,6 +373,23 @@ public struct Interaction: Codable, Identifiable, Equatable, FetchableRecord, Mu
// Automatically mark interactions which can't be unread as read so the unread count // Automatically mark interactions which can't be unread as read so the unread count
// isn't impacted // isn't impacted
self.wasRead = (self.wasRead || !self.variant.canBeUnread) self.wasRead = (self.wasRead || !self.variant.canBeUnread)
// Automatically add disapeparing messages configuration
if self.variant.shouldFollowDisappearingMessagesConfiguration,
self.expiresInSeconds == nil,
self.expiresStartedAtMs == nil
{
guard
let disappearingMessagesConfiguration = try? DisappearingMessagesConfiguration.fetchOne(db, id: self.threadId),
disappearingMessagesConfiguration.isEnabled
else {
self.expiresInSeconds = 0
return
}
self.expiresInSeconds = disappearingMessagesConfiguration.durationSeconds
}
} }
public func aroundInsert(_ db: Database, insert: () throws -> InsertionSuccess) throws { public func aroundInsert(_ db: Database, insert: () throws -> InsertionSuccess) throws {

@ -196,24 +196,20 @@ extension MessageSender {
// MARK: - Convenience // MARK: - Convenience
internal static func getSpecifiedTTL( internal static func getSpecifiedTTL(
_ db: Database,
threadId: String,
message: Message, message: Message,
isSyncMessage: Bool isSyncMessage: Bool
) -> UInt64? { ) -> UInt64? {
guard let expiresInSeconds = message.expiresInSeconds else { return nil } guard
let disappearingMessagesConfiguration = try? DisappearingMessagesConfiguration.fetchOne(db, id: threadId),
// Sync message disappearingMessagesConfiguration.isEnabled,
if isSyncMessage { (
return UInt64(expiresInSeconds * 1000) disappearingMessagesConfiguration.type == .disappearAfterSend ||
} isSyncMessage
)
// Disappear after send else { return nil }
if let expiresStartedAtMs = message.expiresStartedAtMs,
let sentTimestamp = message.sentTimestamp,
UInt64(expiresStartedAtMs) == sentTimestamp
{
return UInt64(expiresInSeconds * 1000)
}
return nil return UInt64(disappearingMessagesConfiguration.durationSeconds * 1000)
} }
} }

@ -349,7 +349,7 @@ public final class MessageSender {
recipient: message.recipient!, recipient: message.recipient!,
data: base64EncodedData, data: base64EncodedData,
ttl: MessageSender ttl: MessageSender
.getSpecifiedTTL(message: message, isSyncMessage: isSyncMessage) .getSpecifiedTTL(db, threadId: threadId, message: message, isSyncMessage: isSyncMessage)
.defaulting(to: message.ttl), .defaulting(to: message.ttl),
timestampMs: UInt64(messageSendTimestamp) timestampMs: UInt64(messageSendTimestamp)
) )

Loading…
Cancel
Save