set ttl as disappearing message config

pull/941/head
Ryan Zhao 2 years ago
parent f9ebef9ba6
commit 70ba0bdc13

@ -440,6 +440,7 @@ extension ConversationVC:
body: text,
timestampMs: sentTimestampMs,
hasMention: Interaction.isUserMentioned(db, threadId: threadId, body: text),
// No matter the disappearing message type is D.A.R or D.A.S, it is the same on the sender's side
expiresInSeconds: try? DisappearingMessagesConfiguration
.select(.durationSeconds)
.filter(id: threadId)

@ -13,7 +13,7 @@ public final class ClosedGroupControlMessage: ControlMessage {
public var kind: Kind?
public override var ttl: UInt64 {
public override var defaultTtl: UInt64 {
switch kind {
case .encryptionKeyPair: return 14 * 24 * 60 * 60 * 1000
default: return 14 * 24 * 60 * 60 * 1000

@ -11,7 +11,7 @@ public final class TypingIndicator: ControlMessage {
public var kind: Kind?
public override var ttl: UInt64 { 20 * 1000 }
public override var defaultTtl: UInt64 { 20 * 1000 }
// MARK: - Kind

@ -16,8 +16,10 @@ public class Message: Codable {
public var groupPublicKey: String?
public var openGroupServerMessageId: UInt64?
public var serverHash: String?
public var ttl: UInt64 { 14 * 24 * 60 * 60 * 1000 }
public var specifiedTtl: UInt64?
public var ttl: UInt64 { specifiedTtl ?? defaultTtl }
public var defaultTtl: UInt64 { 14 * 24 * 60 * 60 * 1000 }
public var isSelfSendValid: Bool { false }
public var shouldBeRetryable: Bool { false }
@ -41,7 +43,8 @@ public class Message: Codable {
sender: String? = nil,
groupPublicKey: String? = nil,
openGroupServerMessageId: UInt64? = nil,
serverHash: String? = nil
serverHash: String? = nil,
specifiedTtl: UInt64? = nil
) {
self.id = id
self.threadId = threadId
@ -52,6 +55,7 @@ public class Message: Codable {
self.groupPublicKey = groupPublicKey
self.openGroupServerMessageId = openGroupServerMessageId
self.serverHash = serverHash
self.specifiedTtl = specifiedTtl
}
// MARK: - Proto Conversion

@ -54,7 +54,8 @@ public final class VisibleMessage: Message {
linkPreview: VMLinkPreview? = nil,
profile: VMProfile? = nil,
openGroupInvitation: VMOpenGroupInvitation? = nil,
reaction: VMReaction? = nil
reaction: VMReaction? = nil,
specifiedTtl: UInt64? = nil
) {
self.syncTarget = syncTarget
self.text = text
@ -68,7 +69,8 @@ public final class VisibleMessage: Message {
super.init(
sentTimestamp: sentTimestamp,
recipient: recipient,
groupPublicKey: groupPublicKey
groupPublicKey: groupPublicKey,
specifiedTtl: specifiedTtl
)
}
@ -227,6 +229,17 @@ public extension VisibleMessage {
static func from(_ db: Database, interaction: Interaction) -> VisibleMessage {
let linkPreview: LinkPreview? = try? interaction.linkPreview.fetchOne(db)
let specifiedTtl: UInt64? = {
guard let disappearingMessagesConfiguration = try? DisappearingMessagesConfiguration.fetchOne(db, id: interaction.threadId),
disappearingMessagesConfiguration.isEnabled,
disappearingMessagesConfiguration.type == .disappearAfterSend
else {
return nil
}
return UInt64(disappearingMessagesConfiguration.durationSeconds) * 1000
}()
return VisibleMessage(
sentTimestamp: UInt64(interaction.timestampMs),
recipient: (try? interaction.recipientStates.fetchOne(db))?.recipientId,
@ -256,7 +269,8 @@ public extension VisibleMessage {
linkPreview: linkPreview
)
},
reaction: nil // Reactions are custom messages sent separately
reaction: nil, // Reactions are custom messages sent separately
specifiedTtl: specifiedTtl
)
}
}

Loading…
Cancel
Save