ExpirationTimerUpdate implementation + classes structure changes

This commit is contained in:
Brice 2020-11-27 16:41:21 +11:00
parent 888eda4ba9
commit 8f409faefc
11 changed files with 101 additions and 27 deletions

View File

@ -53,7 +53,6 @@ class ClosedGroupUpdate() : ControlMessage() {
return ClosedGroupUpdate(kind) return ClosedGroupUpdate(kind)
} }
} }
//private val TAG: String = ClosedGroupUpdate::class.java.simpleName
// Kind enum // Kind enum
sealed class Kind { sealed class Kind {
@ -65,11 +64,12 @@ class ClosedGroupUpdate() : ControlMessage() {
var kind: Kind? = null var kind: Kind? = null
// constructors // constructor
internal constructor(kind: Kind?) : this() { internal constructor(kind: Kind?) : this() {
this.kind = kind this.kind = kind
} }
// validation
override fun isValid(): Boolean { override fun isValid(): Boolean {
if (!super.isValid() || kind == null) return false if (!super.isValid() || kind == null) return false
val kind = kind ?: return false val kind = kind ?: return false

View File

@ -1,13 +1,51 @@
package org.session.libsession.messaging.messages.control package org.session.libsession.messaging.messages.control
import org.session.libsignal.libsignal.logging.Log
import org.session.libsignal.service.internal.push.SignalServiceProtos import org.session.libsignal.service.internal.push.SignalServiceProtos
class ExpirationTimerUpdate : ControlMessage() { class ExpirationTimerUpdate() : ControlMessage() {
override fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? {
TODO("Not yet implemented") var duration: Int? = 0
companion object {
const val TAG = "ExpirationTimerUpdate"
fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? {
val dataMessageProto = proto.dataMessage ?: return null
val isExpirationTimerUpdate = (dataMessageProto.flags and SignalServiceProtos.DataMessage.Flags.EXPIRATION_TIMER_UPDATE_VALUE) != 0
if (!isExpirationTimerUpdate) return null
val duration = dataMessageProto.expireTimer
return ExpirationTimerUpdate(duration)
}
}
//constructor
internal constructor(duration: Int) : this() {
this.duration = duration
}
// validation
override fun isValid(): Boolean {
if (!super.isValid()) return false
return duration != null
} }
override fun toProto(): SignalServiceProtos.Content? { override fun toProto(): SignalServiceProtos.Content? {
TODO("Not yet implemented") val duration = duration
if (duration == null) {
Log.w(TAG, "Couldn't construct expiration timer update proto from: $this")
return null
}
val dataMessageProto = SignalServiceProtos.DataMessage.newBuilder()
dataMessageProto.flags = SignalServiceProtos.DataMessage.Flags.EXPIRATION_TIMER_UPDATE_VALUE
dataMessageProto.expireTimer = duration
val contentProto = SignalServiceProtos.Content.newBuilder()
try {
contentProto.dataMessage = dataMessageProto.build()
return contentProto.build()
} catch (e: Exception) {
Log.w(TAG, "Couldn't construct expiration timer update proto from: $this")
return null
}
} }
} }

View File

@ -2,10 +2,14 @@ package org.session.libsession.messaging.messages.control
import org.session.libsignal.service.internal.push.SignalServiceProtos import org.session.libsignal.service.internal.push.SignalServiceProtos
class ReadReceipt : ControlMessage() { class ReadReceipt() : ControlMessage() {
override fun fromProto(proto: SignalServiceProtos.Content): ReadReceipt? {
companion object {
fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? {
TODO("Not yet implemented") TODO("Not yet implemented")
} }
}
override fun toProto(): SignalServiceProtos.Content? { override fun toProto(): SignalServiceProtos.Content? {
TODO("Not yet implemented") TODO("Not yet implemented")

View File

@ -3,9 +3,12 @@ package org.session.libsession.messaging.messages.control
import org.session.libsignal.service.internal.push.SignalServiceProtos import org.session.libsignal.service.internal.push.SignalServiceProtos
class TypingIndicator : ControlMessage() { class TypingIndicator : ControlMessage() {
override fun fromProto(proto: SignalServiceProtos.Content): TypingIndicator?{
companion object {
fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? {
TODO("Not yet implemented") TODO("Not yet implemented")
} }
}
override fun toProto(): SignalServiceProtos.Content? { override fun toProto(): SignalServiceProtos.Content? {
TODO("Not yet implemented") TODO("Not yet implemented")

View File

@ -1,12 +1,17 @@
package org.session.libsession.messaging.messages.control.unused package org.session.libsession.messaging.messages.control.unused
import org.session.libsession.messaging.messages.control.ControlMessage import org.session.libsession.messaging.messages.control.ControlMessage
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate
import org.session.libsignal.service.internal.push.SignalServiceProtos import org.session.libsignal.service.internal.push.SignalServiceProtos
class NullMessage : ControlMessage() { class NullMessage() : ControlMessage() {
override fun fromProto(proto: SignalServiceProtos.Content): NullMessage? {
companion object {
fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? {
TODO("Not yet implemented") TODO("Not yet implemented")
} }
}
override fun toProto(): SignalServiceProtos.Content? { override fun toProto(): SignalServiceProtos.Content? {
TODO("Not yet implemented") TODO("Not yet implemented")

View File

@ -1,12 +1,16 @@
package org.session.libsession.messaging.messages.control.unused package org.session.libsession.messaging.messages.control.unused
import org.session.libsession.messaging.messages.control.ControlMessage import org.session.libsession.messaging.messages.control.ControlMessage
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate
import org.session.libsignal.service.internal.push.SignalServiceProtos import org.session.libsignal.service.internal.push.SignalServiceProtos
class SessionRequest : ControlMessage() { class SessionRequest() : ControlMessage() {
override fun fromProto(proto: SignalServiceProtos.Content): SessionRequest? {
companion object {
fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? {
TODO("Not yet implemented") TODO("Not yet implemented")
} }
}
override fun toProto(): SignalServiceProtos.Content? { override fun toProto(): SignalServiceProtos.Content? {
TODO("Not yet implemented") TODO("Not yet implemented")

View File

@ -1,11 +1,15 @@
package org.session.libsession.messaging.messages.visible package org.session.libsession.messaging.messages.visible
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate
import org.session.libsignal.service.internal.push.SignalServiceProtos import org.session.libsignal.service.internal.push.SignalServiceProtos
internal class Contact : VisibleMessage() { internal class Contact : VisibleMessage() {
override fun fromProto(proto: SignalServiceProtos.Content): Contact? {
companion object {
fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? {
TODO("Not yet implemented") TODO("Not yet implemented")
} }
}
override fun toProto(): SignalServiceProtos.Content? { override fun toProto(): SignalServiceProtos.Content? {
TODO("Not yet implemented") TODO("Not yet implemented")

View File

@ -1,11 +1,15 @@
package org.session.libsession.messaging.messages.visible package org.session.libsession.messaging.messages.visible
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate
import org.session.libsignal.service.internal.push.SignalServiceProtos import org.session.libsignal.service.internal.push.SignalServiceProtos
internal class LinkPreview : VisibleMessage(){ internal class LinkPreview : VisibleMessage(){
override fun fromProto(proto: SignalServiceProtos.Content): LinkPreview? {
companion object {
fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? {
TODO("Not yet implemented") TODO("Not yet implemented")
} }
}
override fun toProto(): SignalServiceProtos.Content? { override fun toProto(): SignalServiceProtos.Content? {
TODO("Not yet implemented") TODO("Not yet implemented")

View File

@ -1,11 +1,15 @@
package org.session.libsession.messaging.messages.visible package org.session.libsession.messaging.messages.visible
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate
import org.session.libsignal.service.internal.push.SignalServiceProtos import org.session.libsignal.service.internal.push.SignalServiceProtos
internal class Profile : VisibleMessage() { internal class Profile : VisibleMessage() {
override fun fromProto(proto: SignalServiceProtos.Content): Profile? {
companion object {
fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? {
TODO("Not yet implemented") TODO("Not yet implemented")
} }
}
override fun toProto(): SignalServiceProtos.Content? { override fun toProto(): SignalServiceProtos.Content? {
TODO("Not yet implemented") TODO("Not yet implemented")

View File

@ -1,11 +1,15 @@
package org.session.libsession.messaging.messages.visible package org.session.libsession.messaging.messages.visible
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate
import org.session.libsignal.service.internal.push.SignalServiceProtos import org.session.libsignal.service.internal.push.SignalServiceProtos
internal class Quote : VisibleMessage() { internal class Quote : VisibleMessage() {
override fun fromProto(proto: SignalServiceProtos.Content): Quote? {
companion object {
fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? {
TODO("Not yet implemented") TODO("Not yet implemented")
} }
}
override fun toProto(): SignalServiceProtos.Content? { override fun toProto(): SignalServiceProtos.Content? {
TODO("Not yet implemented") TODO("Not yet implemented")

View File

@ -1,12 +1,16 @@
package org.session.libsession.messaging.messages.visible.attachments package org.session.libsession.messaging.messages.visible.attachments
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate
import org.session.libsession.messaging.messages.visible.VisibleMessage import org.session.libsession.messaging.messages.visible.VisibleMessage
import org.session.libsignal.service.internal.push.SignalServiceProtos import org.session.libsignal.service.internal.push.SignalServiceProtos
internal class Attachment : VisibleMessage() { internal class Attachment : VisibleMessage() {
override fun fromProto(proto: SignalServiceProtos.Content): Attachment? {
companion object {
fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? {
TODO("Not yet implemented") TODO("Not yet implemented")
} }
}
override fun toProto(): SignalServiceProtos.Content? { override fun toProto(): SignalServiceProtos.Content? {
TODO("Not yet implemented") TODO("Not yet implemented")