Fix Message#expiryMode de/serialisation
parent
cb0327ecb2
commit
4c7485f53d
@ -1,59 +1,53 @@
|
|||||||
package org.session.libsession.messaging.messages.control
|
package org.session.libsession.messaging.messages.control
|
||||||
|
|
||||||
import network.loki.messenger.libsession_util.util.ExpiryMode
|
|
||||||
import org.session.libsession.messaging.MessagingModuleConfiguration
|
import org.session.libsession.messaging.MessagingModuleConfiguration
|
||||||
import org.session.libsession.messaging.messages.copyExpiration
|
import org.session.libsession.messaging.messages.copyExpiration
|
||||||
import org.session.libsession.messaging.messages.visible.VisibleMessage
|
import org.session.libsession.messaging.messages.visible.VisibleMessage
|
||||||
import org.session.libsignal.protos.SignalServiceProtos
|
import org.session.libsignal.protos.SignalServiceProtos
|
||||||
|
import org.session.libsignal.protos.SignalServiceProtos.DataMessage.Flags.EXPIRATION_TIMER_UPDATE_VALUE
|
||||||
import org.session.libsignal.utilities.Log
|
import org.session.libsignal.utilities.Log
|
||||||
|
|
||||||
/** In the case of a sync message, the public key of the person the message was targeted at.
|
/** In the case of a sync message, the public key of the person the message was targeted at.
|
||||||
*
|
*
|
||||||
* **Note:** `nil` if this isn't a sync message.
|
* **Note:** `nil` if this isn't a sync message.
|
||||||
*/
|
*/
|
||||||
data class ExpirationTimerUpdate(var syncTarget: String? = null) : ControlMessage() {
|
data class ExpirationTimerUpdate(var syncTarget: String? = null, val isGroup: Boolean = false) : ControlMessage() {
|
||||||
override val isSelfSendValid: Boolean = true
|
override val isSelfSendValid: Boolean = true
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val TAG = "ExpirationTimerUpdate"
|
const val TAG = "ExpirationTimerUpdate"
|
||||||
|
private val storage = MessagingModuleConfiguration.shared.storage
|
||||||
|
|
||||||
fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? {
|
fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? =
|
||||||
val dataMessageProto = if (proto.hasDataMessage()) proto.dataMessage else return null
|
proto.dataMessage?.takeIf { it.flags and EXPIRATION_TIMER_UPDATE_VALUE != 0 }?.run {
|
||||||
val isExpirationTimerUpdate = dataMessageProto.flags.and(
|
ExpirationTimerUpdate(syncTarget, hasGroup()).copyExpiration(proto)
|
||||||
SignalServiceProtos.DataMessage.Flags.EXPIRATION_TIMER_UPDATE_VALUE
|
}
|
||||||
) != 0
|
|
||||||
if (!isExpirationTimerUpdate) return null
|
|
||||||
|
|
||||||
return ExpirationTimerUpdate(dataMessageProto.syncTarget)
|
|
||||||
.copyExpiration(proto)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toProto(): SignalServiceProtos.Content? {
|
override fun toProto(): SignalServiceProtos.Content? {
|
||||||
val dataMessageProto = SignalServiceProtos.DataMessage.newBuilder()
|
val dataMessageProto = SignalServiceProtos.DataMessage.newBuilder().apply {
|
||||||
dataMessageProto.flags = SignalServiceProtos.DataMessage.Flags.EXPIRATION_TIMER_UPDATE_VALUE
|
flags = EXPIRATION_TIMER_UPDATE_VALUE
|
||||||
dataMessageProto.expireTimer = expiryMode.expirySeconds.toInt()
|
expireTimer = expiryMode.expirySeconds.toInt()
|
||||||
// Sync target
|
|
||||||
if (syncTarget != null) {
|
|
||||||
dataMessageProto.syncTarget = syncTarget
|
|
||||||
}
|
}
|
||||||
|
// Sync target
|
||||||
|
syncTarget?.let { dataMessageProto.syncTarget = it }
|
||||||
// Group context
|
// Group context
|
||||||
if (MessagingModuleConfiguration.shared.storage.isClosedGroup(recipient!!)) {
|
if (storage.isClosedGroup(recipient!!)) {
|
||||||
try {
|
try {
|
||||||
setGroupContext(dataMessageProto)
|
setGroupContext(dataMessageProto)
|
||||||
} catch(e: Exception) {
|
} catch(e: Exception) {
|
||||||
Log.w(VisibleMessage.TAG, "Couldn't construct visible message proto from: $this")
|
Log.w(TAG, "Couldn't construct visible message proto from: $this", e)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return try {
|
return try {
|
||||||
SignalServiceProtos.Content.newBuilder().apply {
|
SignalServiceProtos.Content.newBuilder()
|
||||||
dataMessage = dataMessageProto.build()
|
.setDataMessage(dataMessageProto)
|
||||||
setExpirationConfigurationIfNeeded(threadID)
|
.applyExpiryMode()
|
||||||
}.build()
|
.build()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.w(TAG, "Couldn't construct expiration timer update proto from: $this")
|
Log.w(TAG, "Couldn't construct expiration timer update proto from: $this", e)
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue