Fix expiry timer millis conversion

This commit is contained in:
andrew
2023-09-05 14:07:41 +09:30
parent bb36b9361a
commit 96afa8d23f
11 changed files with 22 additions and 24 deletions

View File

@@ -62,7 +62,7 @@ abstract class Message {
expirationTimer = 0
return this
}
if (config.isEnabled && config.expiryMode != null) {
if (config.isEnabled) {
expirationTimer = config.expiryMode.expirySeconds.toInt()
lastDisappearingMessageChangeTimestamp = config.updatedTimestampMs
if (ExpirationConfiguration.isNewConfigEnabled) {

View File

@@ -256,10 +256,10 @@ object MessageSender {
val address = if (isSyncMessage && message is VisibleMessage) message.syncTarget else message.recipient
storage.getThreadId(Address.fromSerialized(address!!)) ?: return null
}
val config = storage.getExpirationConfiguration(threadId) ?: return null
val config = storage.getExpirationConfiguration(threadId)?.takeIf { it.isEnabled } ?: return null
val expiryMode = config.expiryMode
return if (config.isEnabled && (expiryMode is ExpiryMode.AfterSend || isSyncMessage)) {
(expiryMode?.expirySeconds ?: 0L) * 1000L
return if (expiryMode is ExpiryMode.AfterSend || isSyncMessage) {
expiryMode.expiryMillis
} else null
}

View File

@@ -303,12 +303,8 @@ fun MessageReceiver.updateExpiryIfNeeded(
proto.lastDisappearingMessageChangeTimestamp
)
val (shouldUpdateConfig, configToUse) =
if (localConfig != null && localConfig.updatedTimestampMs > proto.lastDisappearingMessageChangeTimestamp) {
false to localConfig
} else {
true to remoteConfig
}
val configToUse = localConfig?.takeIf { it.updatedTimestampMs > proto.lastDisappearingMessageChangeTimestamp } ?: remoteConfig
val shouldUpdateConfig = configToUse == remoteConfig
// don't update any values for open groups
if (recipient.isOpenGroupRecipient && type != null) throw MessageReceiver.Error.InvalidMessage
@@ -325,12 +321,12 @@ fun MessageReceiver.updateExpiryIfNeeded(
// handle a delete after send expired fetch
if (type == ExpirationType.DELETE_AFTER_SEND
&& sentTime + configToUse.expiryMode.expirySeconds <= SnodeAPI.nowWithOffset) {
&& sentTime + configToUse.expiryMode.expiryMillis <= SnodeAPI.nowWithOffset) {
throw MessageReceiver.Error.ExpiredMessage
}
// handle a delete after read last known config value
if (type == ExpirationType.DELETE_AFTER_READ
&& sentTime + configToUse.expiryMode.expirySeconds <= storage.getLastSeen(threadID)) {
&& sentTime + configToUse.expiryMode.expiryMillis <= storage.getLastSeen(threadID)) {
throw MessageReceiver.Error.ExpiredMessage
}