Fix groups

This commit is contained in:
andrew 2023-09-04 11:22:18 +09:30
parent 63713aeb88
commit f1d3518f1c
3 changed files with 24 additions and 36 deletions

View File

@ -147,12 +147,15 @@ class ExpirationSettingsViewModel(
override fun onSetClick() = viewModelScope.launch { override fun onSetClick() = viewModelScope.launch {
val state = _state.value val state = _state.value
val mode = (state.expiryMode ?: ExpiryMode.NONE).let { val mode = state.expiryMode.let {
if (it is ExpiryMode.Legacy) ExpiryMode.AfterRead(it.expirySeconds) when {
else it it !is ExpiryMode.Legacy -> it
state.isGroup -> ExpiryMode.AfterSend(it.expirySeconds)
else -> ExpiryMode.AfterRead(it.expirySeconds)
} ?: ExpiryMode.NONE
} }
val address = state.address val address = state.address
if (address == null || expirationConfig?.expiryMode == mode) { if (address == null) {
_event.send(Event.FAIL) _event.send(Event.FAIL)
return@launch return@launch
} }

View File

@ -645,7 +645,7 @@ open class Storage(
} else { } else {
val mode = val mode =
if (group.disappearingTimer == 0L) ExpiryMode.NONE if (group.disappearingTimer == 0L) ExpiryMode.NONE
else ExpiryMode.AfterRead(group.disappearingTimer) else ExpiryMode.AfterSend(group.disappearingTimer)
val newConfig = ExpirationConfiguration( val newConfig = ExpirationConfiguration(
conversationThreadId, mode, messageTimestamp conversationThreadId, mode, messageTimestamp
) )
@ -1698,36 +1698,21 @@ open class Storage(
override fun getExpirationConfiguration(threadId: Long): ExpirationConfiguration? { override fun getExpirationConfiguration(threadId: Long): ExpirationConfiguration? {
val recipient = getRecipientForThread(threadId) ?: return null val recipient = getRecipientForThread(threadId) ?: return null
val dbExpirationMetadata = DatabaseComponent.get(context).expirationConfigurationDatabase().getExpirationConfiguration(threadId) ?: return null val dbExpirationMetadata = DatabaseComponent.get(context).expirationConfigurationDatabase().getExpirationConfiguration(threadId) ?: return null
return if (recipient.isLocalNumber) { return when {
configFactory.user?.getNtsExpiry()?.let { mode -> recipient.isLocalNumber -> configFactory.user?.getNtsExpiry()
ExpirationConfiguration( recipient.isContactRecipient -> {
threadId, // read it from contacts config if exists
mode, recipient.address.serialize().takeIf { it.startsWith(IdPrefix.STANDARD.value) }
dbExpirationMetadata.updatedTimestampMs ?.let { configFactory.contacts?.get(it)?.expiryMode }
)
} }
} else if (recipient.isContactRecipient && recipient.address.serialize().startsWith(IdPrefix.STANDARD.value)) { recipient.isClosedGroupRecipient -> {
// read it from contacts config if exists // read it from group config if exists
configFactory.contacts?.get(recipient.address.serialize())?.let { contact -> GroupUtil.doubleDecodeGroupId(recipient.address.serialize())
val mode = contact.expiryMode .let { configFactory.userGroups?.getLegacyGroupInfo(it) }
ExpirationConfiguration( ?.run { disappearingTimer.takeIf { it != 0L }?.let(ExpiryMode::AfterSend) ?: ExpiryMode.NONE }
threadId,
mode,
dbExpirationMetadata.updatedTimestampMs
)
} }
} else if (recipient.isClosedGroupRecipient) { else -> null
// read it from group config if exists }?.let { ExpirationConfiguration(threadId, it, dbExpirationMetadata.updatedTimestampMs) }
val groupPublicKey = GroupUtil.doubleDecodeGroupId(recipient.address.serialize())
configFactory.userGroups?.getLegacyGroupInfo(groupPublicKey)?.let { group ->
val expiry = group.disappearingTimer
ExpirationConfiguration(
threadId,
if (expiry != 0L) ExpiryMode.AfterRead(expiry) else ExpiryMode.NONE,
dbExpirationMetadata.updatedTimestampMs
)
}
} else null
} }
override fun setExpirationConfiguration(config: ExpirationConfiguration) { override fun setExpirationConfiguration(config: ExpirationConfiguration) {

View File

@ -4,9 +4,9 @@ import kotlin.time.Duration.Companion.seconds
sealed class ExpiryMode(val expirySeconds: Long) { sealed class ExpiryMode(val expirySeconds: Long) {
object NONE: ExpiryMode(0) object NONE: ExpiryMode(0)
class Legacy(seconds: Long): ExpiryMode(seconds) // after read data class Legacy(private val seconds: Long): ExpiryMode(seconds) // after read
class AfterSend(seconds: Long): ExpiryMode(seconds) data class AfterSend(private val seconds: Long): ExpiryMode(seconds)
class AfterRead(seconds: Long): ExpiryMode(seconds) data class AfterRead(private val seconds: Long): ExpiryMode(seconds)
val duration get() = expirySeconds.seconds val duration get() = expirySeconds.seconds
} }