Notification with image: provide the mimetype if available.

This commit is contained in:
Benoit Marty 2024-11-04 15:41:42 +01:00 committed by Benoit Marty
parent 08b60a4d64
commit 839254cea1
6 changed files with 22 additions and 2 deletions

View file

@ -107,6 +107,7 @@ class DefaultNotifiableEventResolver @Inject constructor(
senderDisambiguatedDisplayName = senderDisambiguatedDisplayName, senderDisambiguatedDisplayName = senderDisambiguatedDisplayName,
body = messageBody, body = messageBody,
imageUriString = content.fetchImageIfPresent(client)?.toString(), imageUriString = content.fetchImageIfPresent(client)?.toString(),
imageMimeType = content.getImageMimetype(),
roomName = roomDisplayName, roomName = roomDisplayName,
roomIsDm = isDm, roomIsDm = isDm,
roomAvatarPath = roomAvatarUrl, roomAvatarPath = roomAvatarUrl,
@ -316,6 +317,17 @@ class DefaultNotifiableEventResolver @Inject constructor(
} }
.getOrNull() .getOrNull()
} }
private suspend fun NotificationContent.MessageLike.RoomMessage.getImageMimetype(): String? {
if (appPreferencesStore.doesHideImagesAndVideosFlow().first()) {
return null
}
return when (val messageType = messageType) {
is ImageMessageType -> messageType.info?.mimetype
is VideoMessageType -> null // Use the thumbnail here?
else -> null
}
}
} }
@Suppress("LongParameterList") @Suppress("LongParameterList")
@ -333,6 +345,7 @@ internal fun buildNotifiableMessageEvent(
// We cannot use Uri? type here, as that could trigger a // We cannot use Uri? type here, as that could trigger a
// NotSerializableException when persisting this to storage // NotSerializableException when persisting this to storage
imageUriString: String? = null, imageUriString: String? = null,
imageMimeType: String? = null,
threadId: ThreadId? = null, threadId: ThreadId? = null,
roomName: String? = null, roomName: String? = null,
roomIsDm: Boolean = false, roomIsDm: Boolean = false,
@ -358,6 +371,7 @@ internal fun buildNotifiableMessageEvent(
senderDisambiguatedDisplayName = senderDisambiguatedDisplayName, senderDisambiguatedDisplayName = senderDisambiguatedDisplayName,
body = body, body = body,
imageUriString = imageUriString, imageUriString = imageUriString,
imageMimeType = imageMimeType,
threadId = threadId, threadId = threadId,
roomName = roomName, roomName = roomName,
roomIsDm = roomIsDm, roomIsDm = roomIsDm,

View file

@ -150,6 +150,7 @@ class NotificationBroadcastReceiverHandler @Inject constructor(
?: stringProvider.getString(R.string.notification_sender_me), ?: stringProvider.getString(R.string.notification_sender_me),
body = message, body = message,
imageUriString = null, imageUriString = null,
imageMimeType = null,
threadId = threadId, threadId = threadId,
roomName = room.displayName, roomName = room.displayName,
roomIsDm = room.isDm, roomIsDm = room.isDm,

View file

@ -419,7 +419,7 @@ class DefaultNotificationCreator @Inject constructor(
senderPerson senderPerson
).also { message -> ).also { message ->
event.imageUri?.let { event.imageUri?.let {
message.setData("image/", it) message.setData(event.imageMimeType ?: "image/", it)
} }
message.extras.putString(MESSAGE_EVENT_ID, event.eventId.value) message.extras.putString(MESSAGE_EVENT_ID, event.eventId.value)
} }

View file

@ -31,7 +31,8 @@ data class NotifiableMessageEvent(
val body: String?, val body: String?,
// We cannot use Uri? type here, as that could trigger a // We cannot use Uri? type here, as that could trigger a
// NotSerializableException when persisting this to storage // NotSerializableException when persisting this to storage
val imageUriString: String?, private val imageUriString: String?,
val imageMimeType: String?,
val threadId: ThreadId?, val threadId: ThreadId?,
val roomName: String?, val roomName: String?,
val roomIsDm: Boolean = false, val roomIsDm: Boolean = false,

View file

@ -590,6 +590,7 @@ class DefaultNotifiableEventResolverTest {
senderDisambiguatedDisplayName = A_USER_NAME_2, senderDisambiguatedDisplayName = A_USER_NAME_2,
body = "Call in progress (unsupported)", body = "Call in progress (unsupported)",
imageUriString = null, imageUriString = null,
imageMimeType = null,
threadId = null, threadId = null,
roomName = A_ROOM_NAME, roomName = A_ROOM_NAME,
roomAvatarPath = null, roomAvatarPath = null,
@ -669,6 +670,7 @@ class DefaultNotifiableEventResolverTest {
canBeReplaced = false, canBeReplaced = false,
isRedacted = false, isRedacted = false,
imageUriString = null, imageUriString = null,
imageMimeType = null,
type = EventType.CALL_NOTIFY, type = EventType.CALL_NOTIFY,
) )
) )
@ -704,6 +706,7 @@ class DefaultNotifiableEventResolverTest {
canBeReplaced = false, canBeReplaced = false,
isRedacted = false, isRedacted = false,
imageUriString = null, imageUriString = null,
imageMimeType = null,
type = EventType.CALL_NOTIFY, type = EventType.CALL_NOTIFY,
) )
) )

View file

@ -100,6 +100,7 @@ fun aNotifiableMessageEvent(
canBeReplaced = false, canBeReplaced = false,
isRedacted = isRedacted, isRedacted = isRedacted,
imageUriString = null, imageUriString = null,
imageMimeType = null,
roomAvatarPath = null, roomAvatarPath = null,
senderAvatarPath = null, senderAvatarPath = null,
soundName = null, soundName = null,