refactor: move the legacy/updated expiring and add extra condition it is only set from one on one conversations (non self-send)

This commit is contained in:
0x330a 2023-01-16 14:51:53 +11:00
parent f0aba3a973
commit dd51c9ab41
No known key found for this signature in database
GPG Key ID: 267811D6E6A2698C

View File

@ -238,6 +238,7 @@ fun MessageReceiver.updateExpiryIfNeeded(message: Message, proto: SignalServiceP
if (!proto.hasLastDisappearingMessageChangeTimestamp()) return
val threadID = storage.getOrCreateThreadIdFor(message.sender!!, message.groupPublicKey, openGroupID)
if (threadID <= 0) throw MessageReceiver.Error.NoThread
val recipient = storage.getRecipientForThread(threadID) ?: throw MessageReceiver.Error.NoThread
val localConfig = storage.getExpirationConfiguration(threadID)
@ -257,8 +258,6 @@ fun MessageReceiver.updateExpiryIfNeeded(message: Message, proto: SignalServiceP
true to remoteConfig
}
val recipient = storage.getRecipientForThread(threadID) ?: throw MessageReceiver.Error.NoThread
// don't update any values for open groups
if (recipient.isOpenGroupRecipient && type != null) throw MessageReceiver.Error.InvalidMessage
if ((recipient.isGroupRecipient || recipient.isLocalNumber)
@ -267,6 +266,11 @@ fun MessageReceiver.updateExpiryIfNeeded(message: Message, proto: SignalServiceP
throw MessageReceiver.Error.InvalidMessage
}
if (!recipient.isGroupRecipient && !recipient.isLocalNumber) {
val disappearingState = if (proto.hasExpirationType()) Recipient.DisappearingState.UPDATED else Recipient.DisappearingState.LEGACY
storage.updateDisappearingState(threadID, disappearingState)
}
// handle a delete after send expired fetch
if (type == ExpirationType.DELETE_AFTER_SEND
&& sentTime + configToUse.durationSeconds <= SnodeAPI.nowWithClockOffset) {
@ -279,8 +283,6 @@ fun MessageReceiver.updateExpiryIfNeeded(message: Message, proto: SignalServiceP
}
if (shouldUpdateConfig) {
val disappearingState = if (proto.hasExpirationType()) Recipient.DisappearingState.UPDATED else Recipient.DisappearingState.LEGACY
storage.updateDisappearingState(threadID, disappearingState)
storage.setExpirationConfiguration(configToUse)
}