From e0d98641aae6c4e27ab88301796914b383fb3912 Mon Sep 17 00:00:00 2001 From: Brice Date: Thu, 3 Dec 2020 16:13:40 +1100 Subject: [PATCH] removal of 'transaction' parameter in toProto + code simplification --- .../session/libsession/messaging/messages/Message.kt | 4 ++-- .../messaging/messages/control/ControlMessage.kt | 3 ++- .../messaging/messages/visible/Attachment.kt | 2 +- .../libsession/messaging/messages/visible/Contact.kt | 2 +- .../messaging/messages/visible/LinkPreview.kt | 2 +- .../libsession/messaging/messages/visible/Profile.kt | 6 +----- .../libsession/messaging/messages/visible/Quote.kt | 6 +++--- .../messaging/messages/visible/VisibleMessage.kt | 8 ++++---- .../messaging/messages/visible/VisibleMessageProto.kt | 11 +---------- 9 files changed, 16 insertions(+), 28 deletions(-) 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 338b8e0855..7fd3aa8773 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 @@ -2,7 +2,7 @@ package org.session.libsession.messaging.messages import org.session.libsignal.service.internal.push.SignalServiceProtos -abstract class Message { +abstract class Message { var id: String? = null var threadID: String? = null @@ -21,6 +21,6 @@ abstract class Message { return sender != null && recipient != null } - abstract fun toProto(): SignalServiceProtos.Content? + abstract fun toProto(): T } \ No newline at end of file diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/control/ControlMessage.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/control/ControlMessage.kt index 44cd7ee4d8..74164054bd 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/control/ControlMessage.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/control/ControlMessage.kt @@ -1,6 +1,7 @@ package org.session.libsession.messaging.messages.control import org.session.libsession.messaging.messages.Message +import org.session.libsignal.service.internal.push.SignalServiceProtos -abstract class ControlMessage : Message() { +abstract class ControlMessage : Message() { } \ No newline at end of file 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 90a3ebbaca..8ff6e476f4 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 @@ -63,7 +63,7 @@ class Attachment : VisibleMessageProto() return (contentType != null && kind != null && size != null && sizeInBytes != null && url != null) } - override fun toProto(transaction: String): SignalServiceProtos.AttachmentPointer? { + override fun toProto(): SignalServiceProtos.AttachmentPointer? { TODO("Not implemented") } } \ No newline at end of file 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 96af6e8bbd..0c223a3896 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 @@ -10,7 +10,7 @@ class Contact : VisibleMessageProto() } } - override fun toProto(transaction: String): SignalServiceProtos.DataMessage.Contact? { + override fun toProto(): SignalServiceProtos.DataMessage.Contact? { TODO("Not yet implemented") } } \ No newline at end of file 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 87779f26e3..3e570f9e05 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 @@ -33,7 +33,7 @@ class LinkPreview() : VisibleMessageProto() { this.profilePictureURL = profilePictureURL } - fun toSSProto(): SignalServiceProtos.DataMessage? { - return this.toProto("") - } - - override fun toProto(transaction: String): SignalServiceProtos.DataMessage? { + override fun toProto(): SignalServiceProtos.DataMessage? { val displayName = displayName if (displayName == null) { Log.w(TAG, "Couldn't construct link preview proto from: $this") 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 4fb54f70a6..165899c044 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 @@ -36,7 +36,7 @@ class Quote() : VisibleMessageProto() { return (timestamp != null && publicKey != null) } - override fun toProto(transaction: String): SignalServiceProtos.DataMessage.Quote? { + override fun toProto(): SignalServiceProtos.DataMessage.Quote? { val timestamp = timestamp val publicKey = publicKey if (timestamp == null || publicKey == null) { @@ -47,7 +47,7 @@ class Quote() : VisibleMessageProto() { quoteProto.id = timestamp quoteProto.author = publicKey text?.let { quoteProto.text = text } - addAttachmentsIfNeeded(quoteProto, transaction) + addAttachmentsIfNeeded(quoteProto) // Build try { return quoteProto.build() @@ -57,7 +57,7 @@ class Quote() : VisibleMessageProto() { } } - private fun addAttachmentsIfNeeded(quoteProto: SignalServiceProtos.DataMessage.Quote.Builder, transaction: String) { + private fun addAttachmentsIfNeeded(quoteProto: SignalServiceProtos.DataMessage.Quote.Builder) { val attachmentID = attachmentID ?: return //TODO databas stuff val quotedAttachmentProto = SignalServiceProtos.DataMessage.Quote.QuotedAttachment.newBuilder() 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 89486f7481..dbdd8ffbf5 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 @@ -46,13 +46,13 @@ class VisibleMessage() : VisibleMessageProto() { return false } - override fun toProto(transaction: String): SignalServiceProtos.Content? { + override fun toProto(): SignalServiceProtos.Content? { val proto = SignalServiceProtos.Content.newBuilder() var attachmentIDs = this.attachmentIDs val dataMessage: SignalServiceProtos.DataMessage.Builder // Profile val profile = profile - val profileProto = profile?.toSSProto() + val profileProto = profile?.toProto() if (profileProto != null) { dataMessage = profileProto.toBuilder() } else { @@ -68,7 +68,7 @@ class VisibleMessage() : VisibleMessageProto() { } val quote = quote quote?.let { - val quoteProto = quote.toProto(transaction) + val quoteProto = quote.toProto() if (quoteProto != null) dataMessage.quote = quoteProto } //Link preview @@ -79,7 +79,7 @@ class VisibleMessage() : VisibleMessageProto() { } val linkPreview = linkPreview linkPreview?.let { - val linkPreviewProto = linkPreview.toProto(transaction) + val linkPreviewProto = linkPreview.toProto() linkPreviewProto?.let { dataMessage.addAllPreview(listOf(linkPreviewProto)) } diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/visible/VisibleMessageProto.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/visible/VisibleMessageProto.kt index d8dcd7090f..97b1506d6c 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/visible/VisibleMessageProto.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/visible/VisibleMessageProto.kt @@ -1,15 +1,6 @@ package org.session.libsession.messaging.messages.visible import org.session.libsession.messaging.messages.Message -import org.session.libsignal.service.internal.push.SignalServiceProtos -abstract class VisibleMessageProto : Message() { - - abstract fun toProto(transaction: String): T - - 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:) if that exists... - TODO("Not implemented") - } +abstract class VisibleMessageProto : Message() { } \ No newline at end of file