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 {
|
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
|
||||||
}
|
}
|
||||||
|
@ -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,
|
|
||||||
mode,
|
|
||||||
dbExpirationMetadata.updatedTimestampMs
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else if (recipient.isContactRecipient && recipient.address.serialize().startsWith(IdPrefix.STANDARD.value)) {
|
|
||||||
// read it from contacts config if exists
|
// read it from contacts config if exists
|
||||||
configFactory.contacts?.get(recipient.address.serialize())?.let { contact ->
|
recipient.address.serialize().takeIf { it.startsWith(IdPrefix.STANDARD.value) }
|
||||||
val mode = contact.expiryMode
|
?.let { configFactory.contacts?.get(it)?.expiryMode }
|
||||||
ExpirationConfiguration(
|
|
||||||
threadId,
|
|
||||||
mode,
|
|
||||||
dbExpirationMetadata.updatedTimestampMs
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
} else if (recipient.isClosedGroupRecipient) {
|
recipient.isClosedGroupRecipient -> {
|
||||||
// read it from group config if exists
|
// read it from group config if exists
|
||||||
val groupPublicKey = GroupUtil.doubleDecodeGroupId(recipient.address.serialize())
|
GroupUtil.doubleDecodeGroupId(recipient.address.serialize())
|
||||||
configFactory.userGroups?.getLegacyGroupInfo(groupPublicKey)?.let { group ->
|
.let { configFactory.userGroups?.getLegacyGroupInfo(it) }
|
||||||
val expiry = group.disappearingTimer
|
?.run { disappearingTimer.takeIf { it != 0L }?.let(ExpiryMode::AfterSend) ?: ExpiryMode.NONE }
|
||||||
ExpirationConfiguration(
|
|
||||||
threadId,
|
|
||||||
if (expiry != 0L) ExpiryMode.AfterRead(expiry) else ExpiryMode.NONE,
|
|
||||||
dbExpirationMetadata.updatedTimestampMs
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
} else null
|
else -> null
|
||||||
|
}?.let { ExpirationConfiguration(threadId, it, dbExpirationMetadata.updatedTimestampMs) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setExpirationConfiguration(config: ExpirationConfiguration) {
|
override fun setExpirationConfiguration(config: ExpirationConfiguration) {
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user