diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/Destination.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/Destination.kt index 8c255bdce5..a0573bd19c 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/Destination.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/Destination.kt @@ -6,4 +6,7 @@ sealed class Destination { class ClosedGroup(val groupPublicKey: String) class OpenGroup(val channel: Long, val server: String) + companion object { + //TODO need to implement the equivalent to TSThread and then implement from(...) + } } \ No newline at end of file diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/Message.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/Message.kt index 3f2c5b0fee..3e92077689 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/Message.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/Message.kt @@ -16,10 +16,9 @@ abstract class Message { companion object { @JvmStatic val ttl = 2 * 24 * 60 * 60 * 1000 //TODO not sure about that declaration - - //TODO how to declare fromProto? } + // validation open fun isValid(): Boolean { sentTimestamp = if (sentTimestamp!! > 0) sentTimestamp else return false receivedTimestamp = if (receivedTimestamp!! > 0) receivedTimestamp else return false 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 f72c8a1dce..75486b6557 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 @@ -7,6 +7,8 @@ import org.session.libsignal.service.loki.protocol.closedgroups.ClosedGroupSende class ClosedGroupUpdate() : ControlMessage() { + var kind: Kind? = null + // Kind enum sealed class Kind { class New(val groupPublicKey: ByteArray, val name: String, val groupPrivateKey: ByteArray, val senderKeys: Collection, val members: Collection, val admins: Collection) : Kind() @@ -15,15 +17,13 @@ class ClosedGroupUpdate() : ControlMessage() { class SenderKey(val groupPublicKey: ByteArray, val senderKey: org.session.libsignal.service.loki.protocol.closedgroups.ClosedGroupSenderKey) : Kind() } - var kind: Kind? = null - companion object { const val TAG = "ClosedGroupUpdate" fun fromProto(proto: SignalServiceProtos.Content): ClosedGroupUpdate? { val closedGroupUpdateProto = proto.dataMessage?.closedGroupUpdate ?: return null val groupPublicKey = closedGroupUpdateProto.groupPublicKey - var kind: Kind? = null + var kind: Kind when(closedGroupUpdateProto.type) { SignalServiceProtos.ClosedGroupUpdate.Type.NEW -> { val name = closedGroupUpdateProto.name ?: return null @@ -71,7 +71,7 @@ class ClosedGroupUpdate() : ControlMessage() { // validation override fun isValid(): Boolean { - if (!super.isValid() || kind == null) return false + if (!super.isValid()) return false val kind = kind ?: return false when(kind) { is Kind.New -> { 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 c392db9884..9f2a38c86c 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 @@ -12,7 +12,7 @@ class ExpirationTimerUpdate() : ControlMessage() { 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 + val isExpirationTimerUpdate = (dataMessageProto.flags and SignalServiceProtos.DataMessage.Flags.EXPIRATION_TIMER_UPDATE_VALUE) != 0 //TODO validate that 'and' operator equivalent to Swift '&' if (!isExpirationTimerUpdate) return null val duration = dataMessageProto.expireTimer return ExpirationTimerUpdate(duration) 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 8a25b5dccc..b078ce5545 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 @@ -33,7 +33,7 @@ class SessionRequest() : ControlMessage() { null, //TODO preKeyBundleProto.signedKeyId, preKeyBundleProto.signature.toByteArray(), null, //TODO preKeyBundleProto.identityKey - ) ?: return null + ) return SessionRequest(preKeyBundle) } } diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/visible/Attachment.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/visible/Attachment.kt index 3e1530f34e..7a37ef4849 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/visible/Attachment.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/visible/Attachment.kt @@ -33,7 +33,7 @@ class Attachment : VisibleMessage() { result.key = proto.key.toByteArray() result.digest = proto.digest.toByteArray() val kind: Kind - if (proto.hasFlags() && (proto.flags and SignalServiceProtos.AttachmentPointer.Flags.VOICE_MESSAGE_VALUE) > 0) { + if (proto.hasFlags() && (proto.flags and SignalServiceProtos.AttachmentPointer.Flags.VOICE_MESSAGE_VALUE) > 0) { //TODO validate that 'and' operator = swift '&' kind = Kind.VOICEMESSAGE } else { kind = Kind.GENERIC diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/visible/BaseVisibleMessage.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/visible/BaseVisibleMessage.kt index 1ea7768381..5e3fab2d1c 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/visible/BaseVisibleMessage.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/visible/BaseVisibleMessage.kt @@ -21,14 +21,18 @@ class BaseVisibleMessage() : VisibleMessage() { result.text = dataMessage.body // Attachments are handled in MessageReceiver val quoteProto = dataMessage.quote - val quote = Quote.fromProto(quoteProto) - quote?.let { result.quote = quote } + quoteProto?.let { + val quote = Quote.fromProto(quoteProto) + quote?.let { result.quote = quote } + } val linkPreviewProto = dataMessage.previewList.first() - val linkPreview = LinkPreview.fromProto(linkPreviewProto) - linkPreview?.let { result.linkPreview = linkPreview } + linkPreviewProto?.let { + val linkPreview = LinkPreview.fromProto(linkPreviewProto) + linkPreview?.let { result.linkPreview = linkPreview } + } // TODO Contact val profile = Profile.fromProto(dataMessage) - if (profile != null) { result.profile = profile } + profile?.let { result.profile = profile } return result } } @@ -38,7 +42,7 @@ class BaseVisibleMessage() : VisibleMessage() { if (!super.isValid()) return false if (attachmentIDs.isNotEmpty()) return true val text = text?.trim() ?: return false - if (text.isEmpty()) return true + if (text.isNotEmpty()) return true return false } @@ -48,7 +52,7 @@ class BaseVisibleMessage() : VisibleMessage() { val dataMessage: SignalServiceProtos.DataMessage.Builder // Profile val profile = profile - val profileProto = profile?.toProto("") //TODO + val profileProto = profile?.toSSProto() if (profileProto != null) { dataMessage = profileProto.toBuilder() } else { @@ -84,7 +88,7 @@ class BaseVisibleMessage() : VisibleMessage() { // TODO I'm blocking on that one... //swift: let attachments = attachmentIDs.compactMap { TSAttachmentStream.fetch(uniqueId: $0, transaction: transaction) } - + // TODO Contact // Build try { proto.dataMessage = dataMessage.build() 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 90521b6e30..7806e9fbe0 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 @@ -42,7 +42,7 @@ class LinkPreview() : VisibleMessage() } val linkPreviewProto = SignalServiceProtos.DataMessage.Preview.newBuilder() linkPreviewProto.url = url - title?. let { linkPreviewProto.title = title } + title?.let { linkPreviewProto.title = title } val attachmentID = attachmentID attachmentID?.let { //TODO database stuff 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 47a9e99626..0d07821e40 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 @@ -47,7 +47,7 @@ class Quote() : VisibleMessage() { quoteProto.id = timestamp quoteProto.author = publicKey text?.let { quoteProto.text = text } - //TODO addAttachmentsIfNeeded(quoteProto, transaction) + addAttachmentsIfNeeded(quoteProto, transaction) // Build try { return quoteProto.build() diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/visible/VisibleMessage.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/visible/VisibleMessage.kt index bb60a51817..dd1068cc45 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/visible/VisibleMessage.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/visible/VisibleMessage.kt @@ -9,7 +9,7 @@ abstract class VisibleMessage : Me final override fun toProto(): SignalServiceProtos.Content? { //we don't need to implement this method in subclasses - //TODO it just needs an equivalent to swift: preconditionFailure("Use toProto(using:) instead.") - TODO("Not yet implemented") + //TODO it just needs an equivalent to swift: preconditionFailure("Use toProto(using:) if that exists... + TODO("Not implemented") } } \ No newline at end of file