mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-23 00:17:34 +00:00
Fix groups
This commit is contained in:
parent
63713aeb88
commit
f1d3518f1c
@ -147,12 +147,15 @@ class ExpirationSettingsViewModel(
|
||||
|
||||
override fun onSetClick() = viewModelScope.launch {
|
||||
val state = _state.value
|
||||
val mode = (state.expiryMode ?: ExpiryMode.NONE).let {
|
||||
if (it is ExpiryMode.Legacy) ExpiryMode.AfterRead(it.expirySeconds)
|
||||
else it
|
||||
val mode = state.expiryMode.let {
|
||||
when {
|
||||
it !is ExpiryMode.Legacy -> it
|
||||
state.isGroup -> ExpiryMode.AfterSend(it.expirySeconds)
|
||||
else -> ExpiryMode.AfterRead(it.expirySeconds)
|
||||
} ?: ExpiryMode.NONE
|
||||
}
|
||||
val address = state.address
|
||||
if (address == null || expirationConfig?.expiryMode == mode) {
|
||||
if (address == null) {
|
||||
_event.send(Event.FAIL)
|
||||
return@launch
|
||||
}
|
||||
|
@ -645,7 +645,7 @@ open class Storage(
|
||||
} else {
|
||||
val mode =
|
||||
if (group.disappearingTimer == 0L) ExpiryMode.NONE
|
||||
else ExpiryMode.AfterRead(group.disappearingTimer)
|
||||
else ExpiryMode.AfterSend(group.disappearingTimer)
|
||||
val newConfig = ExpirationConfiguration(
|
||||
conversationThreadId, mode, messageTimestamp
|
||||
)
|
||||
@ -1698,36 +1698,21 @@ open class Storage(
|
||||
override fun getExpirationConfiguration(threadId: Long): ExpirationConfiguration? {
|
||||
val recipient = getRecipientForThread(threadId) ?: return null
|
||||
val dbExpirationMetadata = DatabaseComponent.get(context).expirationConfigurationDatabase().getExpirationConfiguration(threadId) ?: return null
|
||||
return if (recipient.isLocalNumber) {
|
||||
configFactory.user?.getNtsExpiry()?.let { mode ->
|
||||
ExpirationConfiguration(
|
||||
threadId,
|
||||
mode,
|
||||
dbExpirationMetadata.updatedTimestampMs
|
||||
)
|
||||
}
|
||||
} else if (recipient.isContactRecipient && recipient.address.serialize().startsWith(IdPrefix.STANDARD.value)) {
|
||||
return when {
|
||||
recipient.isLocalNumber -> configFactory.user?.getNtsExpiry()
|
||||
recipient.isContactRecipient -> {
|
||||
// read it from contacts config if exists
|
||||
configFactory.contacts?.get(recipient.address.serialize())?.let { contact ->
|
||||
val mode = contact.expiryMode
|
||||
ExpirationConfiguration(
|
||||
threadId,
|
||||
mode,
|
||||
dbExpirationMetadata.updatedTimestampMs
|
||||
)
|
||||
recipient.address.serialize().takeIf { it.startsWith(IdPrefix.STANDARD.value) }
|
||||
?.let { configFactory.contacts?.get(it)?.expiryMode }
|
||||
}
|
||||
} else if (recipient.isClosedGroupRecipient) {
|
||||
recipient.isClosedGroupRecipient -> {
|
||||
// read it from group config if exists
|
||||
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
|
||||
)
|
||||
GroupUtil.doubleDecodeGroupId(recipient.address.serialize())
|
||||
.let { configFactory.userGroups?.getLegacyGroupInfo(it) }
|
||||
?.run { disappearingTimer.takeIf { it != 0L }?.let(ExpiryMode::AfterSend) ?: ExpiryMode.NONE }
|
||||
}
|
||||
} else null
|
||||
else -> null
|
||||
}?.let { ExpirationConfiguration(threadId, it, dbExpirationMetadata.updatedTimestampMs) }
|
||||
}
|
||||
|
||||
override fun setExpirationConfiguration(config: ExpirationConfiguration) {
|
||||
|
@ -4,9 +4,9 @@ import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
sealed class ExpiryMode(val expirySeconds: Long) {
|
||||
object NONE: ExpiryMode(0)
|
||||
class Legacy(seconds: Long): ExpiryMode(seconds) // after read
|
||||
class AfterSend(seconds: Long): ExpiryMode(seconds)
|
||||
class AfterRead(seconds: Long): ExpiryMode(seconds)
|
||||
data class Legacy(private val seconds: Long): ExpiryMode(seconds) // after read
|
||||
data class AfterSend(private val seconds: Long): ExpiryMode(seconds)
|
||||
data class AfterRead(private val seconds: Long): ExpiryMode(seconds)
|
||||
|
||||
val duration get() = expirySeconds.seconds
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user