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

View File

@ -1,13 +1,51 @@
package org.session.libsession.messaging.messages.control
import org.session.libsignal.libsignal.logging.Log
import org.session.libsignal.service.internal.push.SignalServiceProtos
class ExpirationTimerUpdate : ControlMessage() {
override fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? {
TODO("Not yet implemented")
class ExpirationTimerUpdate() : ControlMessage() {
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? {
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
class ReadReceipt : ControlMessage() {
override fun fromProto(proto: SignalServiceProtos.Content): ReadReceipt? {
class ReadReceipt() : ControlMessage() {
companion object {
fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? {
TODO("Not yet implemented")
}
}
override fun toProto(): SignalServiceProtos.Content? {
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
class TypingIndicator : ControlMessage() {
override fun fromProto(proto: SignalServiceProtos.Content): TypingIndicator?{
companion object {
fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? {
TODO("Not yet implemented")
}
}
override fun toProto(): SignalServiceProtos.Content? {
TODO("Not yet implemented")

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,12 +1,16 @@
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.libsignal.service.internal.push.SignalServiceProtos
internal class Attachment : VisibleMessage() {
override fun fromProto(proto: SignalServiceProtos.Content): Attachment? {
companion object {
fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? {
TODO("Not yet implemented")
}
}
override fun toProto(): SignalServiceProtos.Content? {
TODO("Not yet implemented")