update disappearing messages off config info message's expiration

pull/941/head
ryanzhao 2 years ago
parent e93c83b9f2
commit 123c458c32

@ -32,20 +32,21 @@ extension MessageReceiver {
}
}()
let config: DisappearingMessagesConfiguration = try thread.disappearingMessagesConfiguration
let localConfig: DisappearingMessagesConfiguration = try thread.disappearingMessagesConfiguration
.fetchOne(db)
.defaulting(to: DisappearingMessagesConfiguration.defaultWith(thread.id))
.with(
// If there is no duration then we should disable the expiration timer
isEnabled: ((message.duration ?? 0) > 0),
durationSeconds: (
message.duration.map { TimeInterval($0) } ??
DisappearingMessagesConfiguration.defaultDuration
),
type: defaultType
)
try config.save(db)
let remoteConfig: DisappearingMessagesConfiguration = localConfig.with(
// If there is no duration then we should disable the expiration timer
isEnabled: ((message.duration ?? 0) > 0),
durationSeconds: (
message.duration.map { TimeInterval($0) } ??
DisappearingMessagesConfiguration.defaultDuration
),
type: defaultType
)
try remoteConfig.save(db)
// Add an info message for the user
_ = try Interaction(
@ -53,14 +54,15 @@ extension MessageReceiver {
threadId: thread.id,
authorId: sender,
variant: .infoDisappearingMessagesUpdate,
body: config.messageInfoString(
body: remoteConfig.messageInfoString(
with: (sender != getUserHexEncodedPublicKey(db) ?
Profile.displayName(db, id: sender) :
nil
),
isPreviousOff: false
),
timestampMs: Int64(message.sentTimestamp ?? 0) // Default to `0` if not set
timestampMs: Int64(message.sentTimestamp ?? 0), // Default to `0` if not set
expiresInSeconds: remoteConfig.isEnabled ? nil : localConfig.durationSeconds
).inserted(db)
}
}

@ -357,8 +357,7 @@ public enum MessageReceiver {
let durationSeconds: TimeInterval = proto.hasExpirationTimer ? TimeInterval(proto.expirationTimer) : 0
let isEnable: Bool = (durationSeconds != 0)
let type: DisappearingMessagesConfiguration.DisappearingMessageType? = proto.hasExpirationType ? .init(protoType: proto.expirationType) : nil
let remoteConfig: DisappearingMessagesConfiguration = DisappearingMessagesConfiguration(
threadId: threadId,
let remoteConfig: DisappearingMessagesConfiguration = localConfig.with(
isEnabled: isEnable,
durationSeconds: durationSeconds,
type: type,
@ -379,7 +378,9 @@ public enum MessageReceiver {
),
isPreviousOff: !localConfig.isEnabled
),
timestampMs: protoLastChangeTimestampMs
timestampMs: protoLastChangeTimestampMs,
expiresInSeconds: remoteConfig.isEnabled ? nil : localConfig.durationSeconds,
expiresStartedAtMs: (!remoteConfig.isEnabled && localConfig.type == .disappearAfterSend) ? Double(protoLastChangeTimestampMs) : nil
).inserted(db)
}

Loading…
Cancel
Save