Skip to content

Commit 64b189c

Browse files
committed
Notification with image: provide the mimetype if available.
1 parent cd481d3 commit 64b189c

File tree

6 files changed

+22
-2
lines changed

6 files changed

+22
-2
lines changed

libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotifiableEventResolver.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class DefaultNotifiableEventResolver @Inject constructor(
107107
senderDisambiguatedDisplayName = senderDisambiguatedDisplayName,
108108
body = messageBody,
109109
imageUriString = content.fetchImageIfPresent(client)?.toString(),
110+
imageMimeType = content.getImageMimetype(),
110111
roomName = roomDisplayName,
111112
roomIsDm = isDm,
112113
roomAvatarPath = roomAvatarUrl,
@@ -316,6 +317,17 @@ class DefaultNotifiableEventResolver @Inject constructor(
316317
}
317318
.getOrNull()
318319
}
320+
321+
private suspend fun NotificationContent.MessageLike.RoomMessage.getImageMimetype(): String? {
322+
if (appPreferencesStore.doesHideImagesAndVideosFlow().first()) {
323+
return null
324+
}
325+
return when (val messageType = messageType) {
326+
is ImageMessageType -> messageType.info?.mimetype
327+
is VideoMessageType -> null // Use the thumbnail here?
328+
else -> null
329+
}
330+
}
319331
}
320332

321333
@Suppress("LongParameterList")
@@ -333,6 +345,7 @@ internal fun buildNotifiableMessageEvent(
333345
// We cannot use Uri? type here, as that could trigger a
334346
// NotSerializableException when persisting this to storage
335347
imageUriString: String? = null,
348+
imageMimeType: String? = null,
336349
threadId: ThreadId? = null,
337350
roomName: String? = null,
338351
roomIsDm: Boolean = false,
@@ -358,6 +371,7 @@ internal fun buildNotifiableMessageEvent(
358371
senderDisambiguatedDisplayName = senderDisambiguatedDisplayName,
359372
body = body,
360373
imageUriString = imageUriString,
374+
imageMimeType = imageMimeType,
361375
threadId = threadId,
362376
roomName = roomName,
363377
roomIsDm = roomIsDm,

libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationBroadcastReceiverHandler.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class NotificationBroadcastReceiverHandler @Inject constructor(
150150
?: stringProvider.getString(R.string.notification_sender_me),
151151
body = message,
152152
imageUriString = null,
153+
imageMimeType = null,
153154
threadId = threadId,
154155
roomName = room.displayName,
155156
roomIsDm = room.isDm,

libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/factories/NotificationCreator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ class DefaultNotificationCreator @Inject constructor(
419419
senderPerson
420420
).also { message ->
421421
event.imageUri?.let {
422-
message.setData("image/", it)
422+
message.setData(event.imageMimeType ?: "image/", it)
423423
}
424424
message.extras.putString(MESSAGE_EVENT_ID, event.eventId.value)
425425
}

libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/model/NotifiableMessageEvent.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ data class NotifiableMessageEvent(
3131
val body: String?,
3232
// We cannot use Uri? type here, as that could trigger a
3333
// NotSerializableException when persisting this to storage
34-
val imageUriString: String?,
34+
private val imageUriString: String?,
35+
val imageMimeType: String?,
3536
val threadId: ThreadId?,
3637
val roomName: String?,
3738
val roomIsDm: Boolean = false,

libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotifiableEventResolverTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ class DefaultNotifiableEventResolverTest {
590590
senderDisambiguatedDisplayName = A_USER_NAME_2,
591591
body = "Call in progress (unsupported)",
592592
imageUriString = null,
593+
imageMimeType = null,
593594
threadId = null,
594595
roomName = A_ROOM_NAME,
595596
roomAvatarPath = null,
@@ -669,6 +670,7 @@ class DefaultNotifiableEventResolverTest {
669670
canBeReplaced = false,
670671
isRedacted = false,
671672
imageUriString = null,
673+
imageMimeType = null,
672674
type = EventType.CALL_NOTIFY,
673675
)
674676
)
@@ -704,6 +706,7 @@ class DefaultNotifiableEventResolverTest {
704706
canBeReplaced = false,
705707
isRedacted = false,
706708
imageUriString = null,
709+
imageMimeType = null,
707710
type = EventType.CALL_NOTIFY,
708711
)
709712
)

libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/fixtures/NotifiableEventFixture.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ fun aNotifiableMessageEvent(
100100
canBeReplaced = false,
101101
isRedacted = isRedacted,
102102
imageUriString = null,
103+
imageMimeType = null,
103104
roomAvatarPath = null,
104105
senderAvatarPath = null,
105106
soundName = null,

0 commit comments

Comments
 (0)