mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 00:37:47 +00:00
code review, minor changes
This commit is contained in:
parent
aefe721fa4
commit
a699168956
@ -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(...)
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -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<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()
|
||||
}
|
||||
|
||||
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 -> {
|
||||
|
@ -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)
|
||||
|
@ -33,7 +33,7 @@ class SessionRequest() : ControlMessage() {
|
||||
null, //TODO preKeyBundleProto.signedKeyId,
|
||||
preKeyBundleProto.signature.toByteArray(),
|
||||
null, //TODO preKeyBundleProto.identityKey
|
||||
) ?: return null
|
||||
)
|
||||
return SessionRequest(preKeyBundle)
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ class Attachment : VisibleMessage<SignalServiceProtos.AttachmentPointer?>() {
|
||||
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
|
||||
|
@ -21,14 +21,18 @@ class BaseVisibleMessage() : VisibleMessage<SignalServiceProtos.Content?>() {
|
||||
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<SignalServiceProtos.Content?>() {
|
||||
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<SignalServiceProtos.Content?>() {
|
||||
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<SignalServiceProtos.Content?>() {
|
||||
// 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()
|
||||
|
@ -42,7 +42,7 @@ class LinkPreview() : VisibleMessage<SignalServiceProtos.DataMessage.Preview?>()
|
||||
}
|
||||
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
|
||||
|
@ -47,7 +47,7 @@ class Quote() : VisibleMessage<SignalServiceProtos.DataMessage.Quote?>() {
|
||||
quoteProto.id = timestamp
|
||||
quoteProto.author = publicKey
|
||||
text?.let { quoteProto.text = text }
|
||||
//TODO addAttachmentsIfNeeded(quoteProto, transaction)
|
||||
addAttachmentsIfNeeded(quoteProto, transaction)
|
||||
// Build
|
||||
try {
|
||||
return quoteProto.build()
|
||||
|
@ -9,7 +9,7 @@ abstract class VisibleMessage<out T: com.google.protobuf.MessageOrBuilder?> : 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")
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user