From fd142c16d9bad2cdcdf1dbded6c9face93dd0a37 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 2 Oct 2024 21:05:43 +0200 Subject: [PATCH] Improve extension to fix a copy paste issue. --- .../DefaultNotifiableEventResolver.kt | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotifiableEventResolver.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotifiableEventResolver.kt index 283b28ab31..cfbac8de2e 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotifiableEventResolver.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotifiableEventResolver.kt @@ -103,7 +103,7 @@ class DefaultNotifiableEventResolver @Inject constructor( timestamp = this.timestamp, senderDisambiguatedDisplayName = senderDisambiguatedDisplayName, body = messageBody, - imageUriString = fetchImageIfPresent(client)?.toString(), + imageUriString = content.fetchImageIfPresent(client)?.toString(), roomName = roomDisplayName, roomIsDm = isDm, roomAvatarPath = roomAvatarUrl, @@ -148,7 +148,6 @@ class DefaultNotifiableEventResolver @Inject constructor( timestamp = this.timestamp, senderDisambiguatedDisplayName = getDisambiguatedDisplayName(content.senderId), body = stringProvider.getString(CommonStrings.common_call_invite), - imageUriString = fetchImageIfPresent(client)?.toString(), roomName = roomDisplayName, roomIsDm = isDm, roomAvatarPath = roomAvatarUrl, @@ -288,22 +287,18 @@ class DefaultNotifiableEventResolver @Inject constructor( } } - private suspend fun NotificationData.fetchImageIfPresent(client: MatrixClient): Uri? { - val fileResult = when (val content = this.content) { - is NotificationContent.MessageLike.RoomMessage -> { - when (val messageType = content.messageType) { - is ImageMessageType -> notificationMediaRepoFactory.create(client) - .getMediaFile( - mediaSource = messageType.source, - mimeType = messageType.info?.mimetype, - body = messageType.body, - ) - is VideoMessageType -> null // Use the thumbnail here? - else -> null - } - } + private suspend fun NotificationContent.MessageLike.RoomMessage.fetchImageIfPresent(client: MatrixClient): Uri? { + val fileResult = when (val messageType = messageType) { + is ImageMessageType -> notificationMediaRepoFactory.create(client) + .getMediaFile( + mediaSource = messageType.source, + mimeType = messageType.info?.mimetype, + body = messageType.body, + ) + is VideoMessageType -> null // Use the thumbnail here? else -> null - } ?: return null + } + ?: return null return fileResult .onFailure {