mirror of
https://github.com/oxen-io/session-android.git
synced 2023-12-14 02:53:01 +01:00
quick code refactoring
This commit is contained in:
parent
7cdffc1801
commit
4fc0c3dddc
2 changed files with 9 additions and 11 deletions
|
@ -31,19 +31,17 @@ class Attachment {
|
||||||
result.contentType = proto.contentType ?: inferContentType()
|
result.contentType = proto.contentType ?: inferContentType()
|
||||||
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) { //TODO validate that 'and' operator = swift '&'
|
||||||
if (proto.hasFlags() && (proto.flags and SignalServiceProtos.AttachmentPointer.Flags.VOICE_MESSAGE_VALUE) > 0) { //TODO validate that 'and' operator = swift '&'
|
Kind.VOICE_MESSAGE
|
||||||
kind = Kind.VOICE_MESSAGE
|
|
||||||
} else {
|
} else {
|
||||||
kind = Kind.GENERIC
|
Kind.GENERIC
|
||||||
}
|
}
|
||||||
result.kind = kind
|
result.kind = kind
|
||||||
result.caption = if (proto.hasCaption()) proto.caption else null
|
result.caption = if (proto.hasCaption()) proto.caption else null
|
||||||
val size: Size
|
val size: Size = if (proto.hasWidth() && proto.width > 0 && proto.hasHeight() && proto.height > 0) {
|
||||||
if (proto.hasWidth() && proto.width > 0 && proto.hasHeight() && proto.height > 0) {
|
Size(proto.width, proto.height)
|
||||||
size = Size(proto.width, proto.height)
|
|
||||||
} else {
|
} else {
|
||||||
size = Size(0,0) //TODO check that it's equivalent to swift: CGSize.zero
|
Size(0,0) //TODO check that it's equivalent to swift: CGSize.zero
|
||||||
}
|
}
|
||||||
result.size = size
|
result.size = size
|
||||||
result.sizeInBytes = if (proto.size > 0) proto.size else null
|
result.sizeInBytes = if (proto.size > 0) proto.size else null
|
||||||
|
|
|
@ -48,7 +48,7 @@ class Quote() {
|
||||||
quoteProto.id = timestamp
|
quoteProto.id = timestamp
|
||||||
quoteProto.author = publicKey
|
quoteProto.author = publicKey
|
||||||
text?.let { quoteProto.text = text }
|
text?.let { quoteProto.text = text }
|
||||||
addAttachmentsIfNeeded(quoteProto, MessagingConfiguration.shared.messageDataProvider)
|
addAttachmentsIfNeeded(quoteProto)
|
||||||
// Build
|
// Build
|
||||||
try {
|
try {
|
||||||
return quoteProto.build()
|
return quoteProto.build()
|
||||||
|
@ -58,9 +58,9 @@ class Quote() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addAttachmentsIfNeeded(quoteProto: SignalServiceProtos.DataMessage.Quote.Builder, messageDataProvider: MessageDataProvider) {
|
private fun addAttachmentsIfNeeded(quoteProto: SignalServiceProtos.DataMessage.Quote.Builder) {
|
||||||
val attachmentID = attachmentID ?: return
|
val attachmentID = attachmentID ?: return
|
||||||
val attachmentProto = messageDataProvider.getAttachmentStream(attachmentID)
|
val attachmentProto = MessagingConfiguration.shared.messageDataProvider.getAttachmentStream(attachmentID)
|
||||||
if (attachmentProto == null) {
|
if (attachmentProto == null) {
|
||||||
Log.w(TAG, "Ignoring invalid attachment for quoted message.")
|
Log.w(TAG, "Ignoring invalid attachment for quoted message.")
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue