removal of 'transaction' parameter in toProto + code simplification

pull/420/head
Brice 4 years ago
parent 2b1655d688
commit e0d98641aa

@ -2,7 +2,7 @@ package org.session.libsession.messaging.messages
import org.session.libsignal.service.internal.push.SignalServiceProtos
abstract class Message {
abstract class Message<T: com.google.protobuf.MessageOrBuilder?> {
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
}

@ -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<SignalServiceProtos.Content?>() {
}

@ -63,7 +63,7 @@ class Attachment : VisibleMessageProto<SignalServiceProtos.AttachmentPointer?>()
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")
}
}

@ -10,7 +10,7 @@ class Contact : VisibleMessageProto<SignalServiceProtos.DataMessage.Contact?>()
}
}
override fun toProto(transaction: String): SignalServiceProtos.DataMessage.Contact? {
override fun toProto(): SignalServiceProtos.DataMessage.Contact? {
TODO("Not yet implemented")
}
}

@ -33,7 +33,7 @@ class LinkPreview() : VisibleMessageProto<SignalServiceProtos.DataMessage.Previe
return (title != null && url != null && attachmentID != null)
}
override fun toProto(transaction: String): SignalServiceProtos.DataMessage.Preview? {
override fun toProto(): SignalServiceProtos.DataMessage.Preview? {
val url = url
if (url == null) {
Log.w(TAG, "Couldn't construct link preview proto from: $this")

@ -35,11 +35,7 @@ class Profile() : VisibleMessageProto<SignalServiceProtos.DataMessage?>() {
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")

@ -36,7 +36,7 @@ class Quote() : VisibleMessageProto<SignalServiceProtos.DataMessage.Quote?>() {
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<SignalServiceProtos.DataMessage.Quote?>() {
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<SignalServiceProtos.DataMessage.Quote?>() {
}
}
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()

@ -46,13 +46,13 @@ class VisibleMessage() : VisibleMessageProto<SignalServiceProtos.Content?>() {
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<SignalServiceProtos.Content?>() {
}
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<SignalServiceProtos.Content?>() {
}
val linkPreview = linkPreview
linkPreview?.let {
val linkPreviewProto = linkPreview.toProto(transaction)
val linkPreviewProto = linkPreview.toProto()
linkPreviewProto?.let {
dataMessage.addAllPreview(listOf(linkPreviewProto))
}

@ -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<out T: com.google.protobuf.MessageOrBuilder?> : 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<T: com.google.protobuf.MessageOrBuilder?> : Message<T>() {
}
Loading…
Cancel
Save