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 cd481d3ca9
commit 64b189c48a
6 changed files with 22 additions and 2 deletions

View file

@ -107,6 +107,7 @@ class DefaultNotifiableEventResolver @Inject constructor(
senderDisambiguatedDisplayName = senderDisambiguatedDisplayName,
body = messageBody,
imageUriString = content.fetchImageIfPresent(client)?.toString(),
imageMimeType = content.getImageMimetype(),
roomName = roomDisplayName,
roomIsDm = isDm,
roomAvatarPath = roomAvatarUrl,
@ -316,6 +317,17 @@ class DefaultNotifiableEventResolver @Inject constructor(
}
.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")
@ -333,6 +345,7 @@ internal fun buildNotifiableMessageEvent(
// We cannot use Uri? type here, as that could trigger a
// NotSerializableException when persisting this to storage
imageUriString: String? = null,
imageMimeType: String? = null,
threadId: ThreadId? = null,
roomName: String? = null,
roomIsDm: Boolean = false,
@ -358,6 +371,7 @@ internal fun buildNotifiableMessageEvent(
senderDisambiguatedDisplayName = senderDisambiguatedDisplayName,
body = body,
imageUriString = imageUriString,
imageMimeType = imageMimeType,
threadId = threadId,
roomName = roomName,
roomIsDm = roomIsDm,

View file

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

View file

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

View file

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

View file

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

View file

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