From 8f409faefcfb9af2de2dc2c162ee6fed4ad1920f Mon Sep 17 00:00:00 2001 From: Brice Date: Fri, 27 Nov 2020 16:41:21 +1100 Subject: [PATCH] ExpirationTimerUpdate implementation + classes structure changes --- .../messages/control/ClosedGroupUpdate.kt | 4 +- .../messages/control/ExpirationTimerUpdate.kt | 46 +++++++++++++++++-- .../messaging/messages/control/ReadReceipt.kt | 10 ++-- .../messages/control/TypingIndicator.kt | 7 ++- .../messages/control/unused/NullMessage.kt | 11 +++-- .../messages/control/unused/SessionRequest.kt | 10 ++-- .../messaging/messages/visible/Contact.kt | 8 +++- .../messaging/messages/visible/LinkPreview.kt | 8 +++- .../messaging/messages/visible/Profile.kt | 8 +++- .../messaging/messages/visible/Quote.kt | 8 +++- .../visible/attachments/Attachment.kt | 8 +++- 11 files changed, 101 insertions(+), 27 deletions(-) diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/control/ClosedGroupUpdate.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/control/ClosedGroupUpdate.kt index 18f424ba8e..9ff406e9e7 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/control/ClosedGroupUpdate.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/control/ClosedGroupUpdate.kt @@ -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 diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/control/ExpirationTimerUpdate.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/control/ExpirationTimerUpdate.kt index 8ba8b802bd..c392db9884 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/control/ExpirationTimerUpdate.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/control/ExpirationTimerUpdate.kt @@ -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 + } } } \ No newline at end of file diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/control/ReadReceipt.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/control/ReadReceipt.kt index 2aa507065b..152eac8729 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/control/ReadReceipt.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/control/ReadReceipt.kt @@ -2,9 +2,13 @@ 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? { - TODO("Not yet implemented") +class ReadReceipt() : ControlMessage() { + + + companion object { + fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? { + TODO("Not yet implemented") + } } override fun toProto(): SignalServiceProtos.Content? { diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/control/TypingIndicator.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/control/TypingIndicator.kt index a08d8f3ff0..da022a84c1 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/control/TypingIndicator.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/control/TypingIndicator.kt @@ -3,8 +3,11 @@ 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?{ - TODO("Not yet implemented") + + companion object { + fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? { + TODO("Not yet implemented") + } } override fun toProto(): SignalServiceProtos.Content? { diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/control/unused/NullMessage.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/control/unused/NullMessage.kt index 392d56caf5..df0887ee8d 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/control/unused/NullMessage.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/control/unused/NullMessage.kt @@ -1,11 +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 NullMessage : ControlMessage() { - override fun fromProto(proto: SignalServiceProtos.Content): NullMessage? { - TODO("Not yet implemented") +class NullMessage() : ControlMessage() { + + + companion object { + fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? { + TODO("Not yet implemented") + } } override fun toProto(): SignalServiceProtos.Content? { diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/control/unused/SessionRequest.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/control/unused/SessionRequest.kt index 8090d68f68..7285d5c4cb 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/control/unused/SessionRequest.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/control/unused/SessionRequest.kt @@ -1,11 +1,15 @@ 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? { - TODO("Not yet implemented") +class SessionRequest() : ControlMessage() { + + companion object { + fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? { + TODO("Not yet implemented") + } } override fun toProto(): SignalServiceProtos.Content? { diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/visible/Contact.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/visible/Contact.kt index cd67a4764e..f5f818e86e 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/visible/Contact.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/visible/Contact.kt @@ -1,10 +1,14 @@ 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? { - TODO("Not yet implemented") + + companion object { + fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? { + TODO("Not yet implemented") + } } override fun toProto(): SignalServiceProtos.Content? { diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/visible/LinkPreview.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/visible/LinkPreview.kt index 355d8bd0c0..d758a46cca 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/visible/LinkPreview.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/visible/LinkPreview.kt @@ -1,10 +1,14 @@ 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? { - TODO("Not yet implemented") + + companion object { + fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? { + TODO("Not yet implemented") + } } override fun toProto(): SignalServiceProtos.Content? { diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/visible/Profile.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/visible/Profile.kt index 0b125bb1f9..5b172bf5e1 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/visible/Profile.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/visible/Profile.kt @@ -1,10 +1,14 @@ 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? { - TODO("Not yet implemented") + + companion object { + fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? { + TODO("Not yet implemented") + } } override fun toProto(): SignalServiceProtos.Content? { diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/visible/Quote.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/visible/Quote.kt index 7c0179e293..aecf3dc3da 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/visible/Quote.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/visible/Quote.kt @@ -1,10 +1,14 @@ 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? { - TODO("Not yet implemented") + + companion object { + fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? { + TODO("Not yet implemented") + } } override fun toProto(): SignalServiceProtos.Content? { diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/visible/attachments/Attachment.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/visible/attachments/Attachment.kt index e0093d9831..94b7ace5d4 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/visible/attachments/Attachment.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/visible/attachments/Attachment.kt @@ -1,11 +1,15 @@ 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? { - TODO("Not yet implemented") + + companion object { + fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? { + TODO("Not yet implemented") + } } override fun toProto(): SignalServiceProtos.Content? {