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

@ -118,7 +118,7 @@ class ConversationActionBarView : LinearLayout {
}
settings.add(
ConversationSetting(
"$prefix - ${ExpirationUtil.getExpirationAbbreviatedDisplayValue(context, config.expiryMode?.expirySeconds!!)}" ,
"$prefix - ${ExpirationUtil.getExpirationAbbreviatedDisplayValue(context, config.expiryMode.expirySeconds)}" ,
ConversationSettingType.EXPIRATION,
R.drawable.ic_timer
)

View File

@ -1577,7 +1577,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
val message = VisibleMessage()
message.sentTimestamp = sentTimestamp
message.text = text
val expiresInMillis = (viewModel.expirationConfiguration?.expiryMode?.expirySeconds ?: 0) * 1000L
val expiresInMillis = viewModel.expirationConfiguration?.expiryMode?.expiryMillis ?: 0
val expireStartedAt = if (viewModel.expirationConfiguration?.expiryMode is ExpiryMode.AfterSend) {
message.sentTimestamp!!
} else 0
@ -1620,7 +1620,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
else it.individualRecipient.address
quote?.copy(author = sender)
}
val expiresInMs = (viewModel.expirationConfiguration?.expiryMode?.expirySeconds ?: 0) * 1000L
val expiresInMs = viewModel.expirationConfiguration?.expiryMode?.expiryMillis ?: 0
val expireStartedAtMs = if (viewModel.expirationConfiguration?.expiryMode is ExpiryMode.AfterSend) {
sentTimestamp
} else 0

View File

@ -329,7 +329,7 @@ open class Storage(
}
val expirationConfig = getExpirationConfiguration(message.threadID ?: -1)
val expiryMode = expirationConfig?.expiryMode
val expiresInMillis = (expiryMode?.expirySeconds ?: 0) * 1000L
val expiresInMillis = expiryMode?.expiryMillis ?: 0
val expireStartedAt = if (expiryMode is ExpiryMode.AfterSend) message.sentTimestamp!! else 0
if (message.isMediaMessage() || attachments.isNotEmpty()) {
val quote: Optional<QuoteModel> = if (quotes != null) Optional.of(quotes) else Optional.absent()
@ -973,7 +973,7 @@ open class Storage(
val threadId = DatabaseComponent.get(context).threadDatabase().getOrCreateThreadIdFor(recipient)
val expirationConfig = getExpirationConfiguration(threadId)
val expiryMode = expirationConfig?.expiryMode
val expiresInMillis = (expiryMode?.expirySeconds ?: 0) * 1000L
val expiresInMillis = expiryMode?.expiryMillis ?: 0
val expireStartedAt = if (expiryMode is ExpiryMode.AfterSend) sentTimestamp else 0
val m = IncomingTextMessage(fromSerialized(senderPublicKey), 1, sentTimestamp, "", Optional.of(group), expiresInMillis, expireStartedAt, true, false)
val updateData = UpdateMessageData.buildGroupUpdate(type, name, members)?.toJSON()
@ -991,7 +991,7 @@ open class Storage(
val threadId = DatabaseComponent.get(context).threadDatabase().getOrCreateThreadIdFor(recipient)
val expirationConfig = getExpirationConfiguration(threadId)
val expiryMode = expirationConfig?.expiryMode
val expiresInMillis = (expiryMode?.expirySeconds ?: 0) * 1000L
val expiresInMillis = expiryMode?.expiryMillis ?: 0
val expireStartedAt = if (expiryMode is ExpiryMode.AfterSend) sentTimestamp else 0
val updateData = UpdateMessageData.buildGroupUpdate(type, name, members)?.toJSON() ?: ""
val infoMessage = OutgoingGroupMediaMessage(recipient, updateData, groupID, null, sentTimestamp, expiresInMillis, expireStartedAt, true, null, listOf(), listOf())
@ -1397,7 +1397,7 @@ open class Storage(
val threadId = getThreadId(recipient) ?: return
val expirationConfig = getExpirationConfiguration(threadId)
val expiryMode = expirationConfig?.expiryMode
val expiresInMillis = (expiryMode?.expirySeconds ?: 0) * 1000L
val expiresInMillis = expiryMode?.expiryMillis ?: 0
val expireStartedAt = if (expiryMode is ExpiryMode.AfterSend) sentTimestamp else 0
val mediaMessage = IncomingMediaMessage(
address,
@ -1551,7 +1551,7 @@ open class Storage(
val threadId = DatabaseComponent.get(context).threadDatabase().getOrCreateThreadIdFor(recipient)
val expirationConfig = getExpirationConfiguration(threadId)
val expiryMode = expirationConfig?.expiryMode
val expiresInMillis = (expiryMode?.expirySeconds ?: 0) * 1000L
val expiresInMillis = expiryMode?.expiryMillis ?: 0
val expireStartedAt = if (expiryMode is ExpiryMode.AfterSend) sentTimestamp else 0
val callMessage = IncomingTextMessage.fromCallInfo(callMessageType, address, Optional.absent(), sentTimestamp, expiresInMillis, expireStartedAt)
database.insertCallMessage(callMessage)

View File

@ -90,7 +90,7 @@ public class AndroidAutoReplyReceiver extends BroadcastReceiver {
MessageSender.send(message, recipient.getAddress());
ExpirationConfiguration config = DatabaseComponent.get(context).storage().getExpirationConfiguration(threadId);
ExpiryMode expiryMode = config == null ? null : config.getExpiryMode();
long expiresInMillis = expiryMode == null ? 0 : expiryMode.getExpirySeconds() * 1000L;
long expiresInMillis = expiryMode == null ? 0 : expiryMode.getExpiryMillis();
long expireStartedAt = expiryMode instanceof ExpiryMode.AfterSend ? message.getSentTimestamp() : 0L;
if (recipient.isGroupRecipient()) {

View File

@ -99,7 +99,7 @@ public class RemoteReplyReceiver extends BroadcastReceiver {
ExpirationConfiguration config = storage.getExpirationConfiguration(threadId);
ExpiryMode expiryMode = config == null ? null : config.getExpiryMode();
long expiresInMillis = expiryMode == null ? 0 : expiryMode.getExpirySeconds() * 1000L;
long expiresInMillis = expiryMode == null ? 0 : expiryMode.getExpiryMillis();
long expireStartedAt = expiryMode instanceof ExpiryMode.AfterSend ? message.getSentTimestamp() : 0L;
switch (replyMethod) {
case GroupMessage: {

View File

@ -149,7 +149,7 @@ class DefaultConversationRepository @Inject constructor(
openGroupInvitation.url = openGroup.joinURL
message.openGroupInvitation = openGroupInvitation
val expirationConfig = storage.getExpirationConfiguration(threadId)
val expiresInMillis = (expirationConfig?.expiryMode?.expirySeconds ?: 0) * 1000L
val expiresInMillis = (expirationConfig?.expiryMode?.expiryMillis ?: 0)
val expireStartedAt = if (expirationConfig?.expiryMode is ExpiryMode.AfterSend) message.sentTimestamp!! else 0
val outgoingTextMessage = OutgoingTextMessage.fromOpenGroupInvitation(
openGroupInvitation,

View File

@ -179,7 +179,7 @@ public class ExpiringMessageManager implements SSKEnvironment.MessageExpirationM
} else {
smsDatabase.markExpireStarted(messageRecord.getId(), expireStartedAt);
}
scheduleDeletion(messageRecord.getId(), mms, expireStartedAt, (mode != null ? mode.getExpirySeconds() : 0) * 1000L);
scheduleDeletion(messageRecord.getId(), mms, expireStartedAt, (mode != null ? mode.getExpiryMillis() : 0));
}
}

View File

@ -9,4 +9,6 @@ sealed class ExpiryMode(val expirySeconds: Long) {
data class AfterRead(private val seconds: Long): ExpiryMode(seconds)
val duration get() = expirySeconds.seconds
val expiryMillis get() = expirySeconds * 1000L
}

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
}