Simplify ExpirationTimerUpdate

This commit is contained in:
andrew 2023-11-10 12:52:35 +10:30
parent 29099901d1
commit a312ef2b25

View File

@ -6,13 +6,11 @@ import org.session.libsession.messaging.messages.visible.VisibleMessage
import org.session.libsignal.protos.SignalServiceProtos import org.session.libsignal.protos.SignalServiceProtos
import org.session.libsignal.utilities.Log import org.session.libsignal.utilities.Log
class ExpirationTimerUpdate() : ControlMessage() { /** 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 duration: Int? = 0, var syncTarget: String? = null) : ControlMessage() {
var syncTarget: String? = null
var duration: Int? = 0
override val isSelfSendValid: Boolean = true override val isSelfSendValid: Boolean = true
@ -32,20 +30,10 @@ class ExpirationTimerUpdate() : ControlMessage() {
if (!isExpirationTimerUpdate) return null if (!isExpirationTimerUpdate) return null
val syncTarget = dataMessageProto.syncTarget val syncTarget = dataMessageProto.syncTarget
val duration = if (proto.hasExpirationTimer()) proto.expirationTimer else dataMessageProto.expireTimer val duration = if (proto.hasExpirationTimer()) proto.expirationTimer else dataMessageProto.expireTimer
return ExpirationTimerUpdate(syncTarget, duration) return ExpirationTimerUpdate(duration, syncTarget)
} }
} }
constructor(duration: Int) : this() {
this.syncTarget = null
this.duration = duration
}
internal constructor(syncTarget: String, duration: Int) : this() {
this.syncTarget = syncTarget
this.duration = duration
}
override fun toProto(): SignalServiceProtos.Content? { override fun toProto(): SignalServiceProtos.Content? {
val dataMessageProto = SignalServiceProtos.DataMessage.newBuilder() val dataMessageProto = SignalServiceProtos.DataMessage.newBuilder()
dataMessageProto.flags = SignalServiceProtos.DataMessage.Flags.EXPIRATION_TIMER_UPDATE_VALUE dataMessageProto.flags = SignalServiceProtos.DataMessage.Flags.EXPIRATION_TIMER_UPDATE_VALUE
@ -63,11 +51,11 @@ class ExpirationTimerUpdate() : ControlMessage() {
return null return null
} }
} }
val contentProto = SignalServiceProtos.Content.newBuilder()
return try { return try {
contentProto.dataMessage = dataMessageProto.build() SignalServiceProtos.Content.newBuilder().apply {
contentProto.setExpirationConfigurationIfNeeded(threadID) dataMessage = dataMessageProto.build()
contentProto.build() setExpirationConfigurationIfNeeded(threadID)
}.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")
null null