code review, minor changes

This commit is contained in:
Brice 2020-12-02 16:21:38 +11:00
parent aefe721fa4
commit a699168956
10 changed files with 27 additions and 21 deletions

View File

@ -6,4 +6,7 @@ sealed class Destination {
class ClosedGroup(val groupPublicKey: String) class ClosedGroup(val groupPublicKey: String)
class OpenGroup(val channel: Long, val server: String) class OpenGroup(val channel: Long, val server: String)
companion object {
//TODO need to implement the equivalent to TSThread and then implement from(...)
}
} }

View File

@ -16,10 +16,9 @@ abstract class Message {
companion object { companion object {
@JvmStatic @JvmStatic
val ttl = 2 * 24 * 60 * 60 * 1000 //TODO not sure about that declaration val ttl = 2 * 24 * 60 * 60 * 1000 //TODO not sure about that declaration
//TODO how to declare fromProto?
} }
// validation
open fun isValid(): Boolean { open fun isValid(): Boolean {
sentTimestamp = if (sentTimestamp!! > 0) sentTimestamp else return false sentTimestamp = if (sentTimestamp!! > 0) sentTimestamp else return false
receivedTimestamp = if (receivedTimestamp!! > 0) receivedTimestamp else return false receivedTimestamp = if (receivedTimestamp!! > 0) receivedTimestamp else return false

View File

@ -7,6 +7,8 @@ import org.session.libsignal.service.loki.protocol.closedgroups.ClosedGroupSende
class ClosedGroupUpdate() : ControlMessage() { class ClosedGroupUpdate() : ControlMessage() {
var kind: Kind? = null
// Kind enum // Kind enum
sealed class Kind { sealed class Kind {
class New(val groupPublicKey: ByteArray, val name: String, val groupPrivateKey: ByteArray, val senderKeys: Collection<org.session.libsignal.service.loki.protocol.closedgroups.ClosedGroupSenderKey>, val members: Collection<ByteArray>, val admins: Collection<ByteArray>) : Kind() class New(val groupPublicKey: ByteArray, val name: String, val groupPrivateKey: ByteArray, val senderKeys: Collection<org.session.libsignal.service.loki.protocol.closedgroups.ClosedGroupSenderKey>, val members: Collection<ByteArray>, val admins: Collection<ByteArray>) : Kind()
@ -15,15 +17,13 @@ class ClosedGroupUpdate() : ControlMessage() {
class SenderKey(val groupPublicKey: ByteArray, val senderKey: org.session.libsignal.service.loki.protocol.closedgroups.ClosedGroupSenderKey) : Kind() class SenderKey(val groupPublicKey: ByteArray, val senderKey: org.session.libsignal.service.loki.protocol.closedgroups.ClosedGroupSenderKey) : Kind()
} }
var kind: Kind? = null
companion object { companion object {
const val TAG = "ClosedGroupUpdate" const val TAG = "ClosedGroupUpdate"
fun fromProto(proto: SignalServiceProtos.Content): ClosedGroupUpdate? { fun fromProto(proto: SignalServiceProtos.Content): ClosedGroupUpdate? {
val closedGroupUpdateProto = proto.dataMessage?.closedGroupUpdate ?: return null val closedGroupUpdateProto = proto.dataMessage?.closedGroupUpdate ?: return null
val groupPublicKey = closedGroupUpdateProto.groupPublicKey val groupPublicKey = closedGroupUpdateProto.groupPublicKey
var kind: Kind? = null var kind: Kind
when(closedGroupUpdateProto.type) { when(closedGroupUpdateProto.type) {
SignalServiceProtos.ClosedGroupUpdate.Type.NEW -> { SignalServiceProtos.ClosedGroupUpdate.Type.NEW -> {
val name = closedGroupUpdateProto.name ?: return null val name = closedGroupUpdateProto.name ?: return null
@ -71,7 +71,7 @@ class ClosedGroupUpdate() : ControlMessage() {
// validation // validation
override fun isValid(): Boolean { override fun isValid(): Boolean {
if (!super.isValid() || kind == null) return false if (!super.isValid()) return false
val kind = kind ?: return false val kind = kind ?: return false
when(kind) { when(kind) {
is Kind.New -> { is Kind.New -> {

View File

@ -12,7 +12,7 @@ class ExpirationTimerUpdate() : ControlMessage() {
fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? { fun fromProto(proto: SignalServiceProtos.Content): ExpirationTimerUpdate? {
val dataMessageProto = proto.dataMessage ?: return null 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 if (!isExpirationTimerUpdate) return null
val duration = dataMessageProto.expireTimer val duration = dataMessageProto.expireTimer
return ExpirationTimerUpdate(duration) return ExpirationTimerUpdate(duration)

View File

@ -33,7 +33,7 @@ class SessionRequest() : ControlMessage() {
null, //TODO preKeyBundleProto.signedKeyId, null, //TODO preKeyBundleProto.signedKeyId,
preKeyBundleProto.signature.toByteArray(), preKeyBundleProto.signature.toByteArray(),
null, //TODO preKeyBundleProto.identityKey null, //TODO preKeyBundleProto.identityKey
) ?: return null )
return SessionRequest(preKeyBundle) return SessionRequest(preKeyBundle)
} }
} }

View File

@ -33,7 +33,7 @@ class Attachment : VisibleMessage<SignalServiceProtos.AttachmentPointer?>() {
result.key = proto.key.toByteArray() result.key = proto.key.toByteArray()
result.digest = proto.digest.toByteArray() result.digest = proto.digest.toByteArray()
val kind: Kind 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 kind = Kind.VOICEMESSAGE
} else { } else {
kind = Kind.GENERIC kind = Kind.GENERIC

View File

@ -21,14 +21,18 @@ class BaseVisibleMessage() : VisibleMessage<SignalServiceProtos.Content?>() {
result.text = dataMessage.body result.text = dataMessage.body
// Attachments are handled in MessageReceiver // Attachments are handled in MessageReceiver
val quoteProto = dataMessage.quote val quoteProto = dataMessage.quote
val quote = Quote.fromProto(quoteProto) quoteProto?.let {
quote?.let { result.quote = quote } val quote = Quote.fromProto(quoteProto)
quote?.let { result.quote = quote }
}
val linkPreviewProto = dataMessage.previewList.first() val linkPreviewProto = dataMessage.previewList.first()
val linkPreview = LinkPreview.fromProto(linkPreviewProto) linkPreviewProto?.let {
linkPreview?.let { result.linkPreview = linkPreview } val linkPreview = LinkPreview.fromProto(linkPreviewProto)
linkPreview?.let { result.linkPreview = linkPreview }
}
// TODO Contact // TODO Contact
val profile = Profile.fromProto(dataMessage) val profile = Profile.fromProto(dataMessage)
if (profile != null) { result.profile = profile } profile?.let { result.profile = profile }
return result return result
} }
} }
@ -38,7 +42,7 @@ class BaseVisibleMessage() : VisibleMessage<SignalServiceProtos.Content?>() {
if (!super.isValid()) return false if (!super.isValid()) return false
if (attachmentIDs.isNotEmpty()) return true if (attachmentIDs.isNotEmpty()) return true
val text = text?.trim() ?: return false val text = text?.trim() ?: return false
if (text.isEmpty()) return true if (text.isNotEmpty()) return true
return false return false
} }
@ -48,7 +52,7 @@ class BaseVisibleMessage() : VisibleMessage<SignalServiceProtos.Content?>() {
val dataMessage: SignalServiceProtos.DataMessage.Builder val dataMessage: SignalServiceProtos.DataMessage.Builder
// Profile // Profile
val profile = profile val profile = profile
val profileProto = profile?.toProto("") //TODO val profileProto = profile?.toSSProto()
if (profileProto != null) { if (profileProto != null) {
dataMessage = profileProto.toBuilder() dataMessage = profileProto.toBuilder()
} else { } else {
@ -84,7 +88,7 @@ class BaseVisibleMessage() : VisibleMessage<SignalServiceProtos.Content?>() {
// TODO I'm blocking on that one... // TODO I'm blocking on that one...
//swift: let attachments = attachmentIDs.compactMap { TSAttachmentStream.fetch(uniqueId: $0, transaction: transaction) } //swift: let attachments = attachmentIDs.compactMap { TSAttachmentStream.fetch(uniqueId: $0, transaction: transaction) }
// TODO Contact
// Build // Build
try { try {
proto.dataMessage = dataMessage.build() proto.dataMessage = dataMessage.build()

View File

@ -42,7 +42,7 @@ class LinkPreview() : VisibleMessage<SignalServiceProtos.DataMessage.Preview?>()
} }
val linkPreviewProto = SignalServiceProtos.DataMessage.Preview.newBuilder() val linkPreviewProto = SignalServiceProtos.DataMessage.Preview.newBuilder()
linkPreviewProto.url = url linkPreviewProto.url = url
title?. let { linkPreviewProto.title = title } title?.let { linkPreviewProto.title = title }
val attachmentID = attachmentID val attachmentID = attachmentID
attachmentID?.let { attachmentID?.let {
//TODO database stuff //TODO database stuff

View File

@ -47,7 +47,7 @@ class Quote() : VisibleMessage<SignalServiceProtos.DataMessage.Quote?>() {
quoteProto.id = timestamp quoteProto.id = timestamp
quoteProto.author = publicKey quoteProto.author = publicKey
text?.let { quoteProto.text = text } text?.let { quoteProto.text = text }
//TODO addAttachmentsIfNeeded(quoteProto, transaction) addAttachmentsIfNeeded(quoteProto, transaction)
// Build // Build
try { try {
return quoteProto.build() return quoteProto.build()

View File

@ -9,7 +9,7 @@ abstract class VisibleMessage<out T: com.google.protobuf.MessageOrBuilder?> : Me
final override fun toProto(): SignalServiceProtos.Content? { final override fun toProto(): SignalServiceProtos.Content? {
//we don't need to implement this method in subclasses //we don't need to implement this method in subclasses
//TODO it just needs an equivalent to swift: preconditionFailure("Use toProto(using:) instead.") //TODO it just needs an equivalent to swift: preconditionFailure("Use toProto(using:) if that exists...
TODO("Not yet implemented") TODO("Not implemented")
} }
} }