From 9074355b4ef69b9feb4daae6e94b7c321b391f82 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Mon, 17 May 2021 11:23:49 +1000 Subject: [PATCH] Fix attachment pointer conversion --- .../attachments/DatabaseAttachmentProvider.kt | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/attachments/DatabaseAttachmentProvider.kt b/app/src/main/java/org/thoughtcrime/securesms/attachments/DatabaseAttachmentProvider.kt index a083d94cda..1bc9e43de0 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/attachments/DatabaseAttachmentProvider.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/attachments/DatabaseAttachmentProvider.kt @@ -230,23 +230,24 @@ fun DatabaseAttachment.toAttachmentStream(context: Context): SessionServiceAttac fun DatabaseAttachment.toSignalAttachmentPointer(): SignalServiceAttachmentPointer? { if (TextUtils.isEmpty(location)) { return null } - if (TextUtils.isEmpty(key)) { return null } - + // `key` can be empty in an open group context (no encryption means no encryption key) return try { - val id: Long = location!!.toLong() - val key: ByteArray = Base64.decode(key!!) - SignalServiceAttachmentPointer(id, - contentType, - key, - Optional.of(Util.toIntExact(size)), - Optional.absent(), - width, - height, - Optional.fromNullable(digest), - Optional.fromNullable(fileName), - isVoiceNote, - Optional.fromNullable(caption), - url) + val id = location!!.toLong() + val key = Base64.decode(key!!) + SignalServiceAttachmentPointer( + id, + contentType, + key, + Optional.of(Util.toIntExact(size)), + Optional.absent(), + width, + height, + Optional.fromNullable(digest), + Optional.fromNullable(fileName), + isVoiceNote, + Optional.fromNullable(caption), + url + ) } catch (e: Exception) { null }