incomplete Quote implementation

This commit is contained in:
Brice 2020-12-02 11:44:55 +11:00
parent feec22bf72
commit 344af77f0f
2 changed files with 56 additions and 6 deletions

View File

@ -23,20 +23,19 @@ class Profile() : VisibleMessage<SignalServiceProtos.DataMessage?>() {
profilePictureURL?.let {
return Profile(displayName = displayName, profileKey = profileKey.toByteArray(), profilePictureURL = profilePictureURL)
}
return Profile(displayName)
}
return Profile(displayName)
}
}
//constructor
internal constructor(displayName: String, profileKey: ByteArray? = nil, profilePictureURL: String? = nil) : this() {
internal constructor(displayName: String, profileKey: ByteArray? = null, profilePictureURL: String? = null) : this() {
this.displayName = displayName
this.profileKey = profileKey
this.profilePictureURL = profilePictureURL
}
fun toProto(): SignalServiceProtos.DataMessage? {
fun toSSProto(): SignalServiceProtos.DataMessage? {
return this.toProto("")
}

View File

@ -1,5 +1,6 @@
package org.session.libsession.messaging.messages.visible
import org.session.libsignal.libsignal.logging.Log
import org.session.libsignal.service.internal.push.SignalServiceProtos
class Quote() : VisibleMessage<SignalServiceProtos.DataMessage.Quote?>() {
@ -10,12 +11,62 @@ class Quote() : VisibleMessage<SignalServiceProtos.DataMessage.Quote?>() {
var attachmentID: String? = null
companion object {
const val TAG = "Quote"
fun fromProto(proto: SignalServiceProtos.DataMessage.Quote): Quote? {
TODO("Not yet implemented")
val timestamp = proto.id
val publicKey = proto.author
val text = proto.text
return Quote(timestamp, publicKey, text, null)
}
}
//constructor
internal constructor(timestamp: Long, publicKey: String, text: String?, attachmentID: String?) : this() {
this.timestamp = timestamp
this.publicKey = publicKey
this.text = text
this.attachmentID = attachmentID
}
// validation
override fun isValid(): Boolean {
if (!super.isValid()) return false
return (timestamp != null && publicKey != null)
}
override fun toProto(transaction: String): SignalServiceProtos.DataMessage.Quote? {
return null
val timestamp = timestamp
val publicKey = publicKey
if (timestamp == null || publicKey == null) {
Log.w(TAG, "Couldn't construct quote proto from: $this")
return null
}
val quoteProto = SignalServiceProtos.DataMessage.Quote.newBuilder()
quoteProto.id = timestamp
quoteProto.author = publicKey
text?.let { quoteProto.text = text }
//TODO addAttachmentsIfNeeded(quoteProto, transaction)
// Build
try {
return quoteProto.build()
} catch (e: Exception) {
Log.w(TAG, "Couldn't construct quote proto from: $this")
return null
}
}
private fun addAttachmentsIfNeeded(quoteProto: SignalServiceProtos.DataMessage.Quote.Builder, transaction: String) {
val attachmentID = attachmentID ?: return
//TODO databas stuff
val quotedAttachmentProto = SignalServiceProtos.DataMessage.Quote.QuotedAttachment.newBuilder()
//TODO more database related stuff
//quotedAttachmentProto.contentType =
try {
quoteProto.addAttachments(quotedAttachmentProto.build())
} catch (e: Exception) {
Log.w(TAG, "Couldn't construct quoted attachment proto from: $this")
}
}
}