From 4fc0c3dddc2798d56160a5504620be75df59e722 Mon Sep 17 00:00:00 2001 From: Brice Date: Fri, 15 Jan 2021 17:08:08 +1100 Subject: [PATCH] quick code refactoring --- .../messaging/messages/visible/Attachment.kt | 14 ++++++-------- .../libsession/messaging/messages/visible/Quote.kt | 6 +++--- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/visible/Attachment.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/visible/Attachment.kt index 6bf441230f..40b804113a 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/visible/Attachment.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/visible/Attachment.kt @@ -31,19 +31,17 @@ class Attachment { result.contentType = proto.contentType ?: inferContentType() 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) { //TODO validate that 'and' operator = swift '&' - kind = Kind.VOICE_MESSAGE + val kind: Kind = if (proto.hasFlags() && (proto.flags and SignalServiceProtos.AttachmentPointer.Flags.VOICE_MESSAGE_VALUE) > 0) { //TODO validate that 'and' operator = swift '&' + Kind.VOICE_MESSAGE } else { - kind = Kind.GENERIC + Kind.GENERIC } result.kind = kind result.caption = if (proto.hasCaption()) proto.caption else null - val size: Size - if (proto.hasWidth() && proto.width > 0 && proto.hasHeight() && proto.height > 0) { - size = Size(proto.width, proto.height) + val size: Size = if (proto.hasWidth() && proto.width > 0 && proto.hasHeight() && proto.height > 0) { + Size(proto.width, proto.height) } 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.sizeInBytes = if (proto.size > 0) proto.size else null diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/visible/Quote.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/visible/Quote.kt index 178d715f66..e26527a9f2 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/visible/Quote.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/visible/Quote.kt @@ -48,7 +48,7 @@ class Quote() { quoteProto.id = timestamp quoteProto.author = publicKey text?.let { quoteProto.text = text } - addAttachmentsIfNeeded(quoteProto, MessagingConfiguration.shared.messageDataProvider) + addAttachmentsIfNeeded(quoteProto) // Build try { 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 attachmentProto = messageDataProvider.getAttachmentStream(attachmentID) + val attachmentProto = MessagingConfiguration.shared.messageDataProvider.getAttachmentStream(attachmentID) if (attachmentProto == null) { Log.w(TAG, "Ignoring invalid attachment for quoted message.") return