Notification with image: provide the mimetype if available.
This commit is contained in:
committed by
Benoit Marty
parent
08b60a4d64
commit
839254cea1
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -100,6 +100,7 @@ fun aNotifiableMessageEvent(
|
||||
canBeReplaced = false,
|
||||
isRedacted = isRedacted,
|
||||
imageUriString = null,
|
||||
imageMimeType = null,
|
||||
roomAvatarPath = null,
|
||||
senderAvatarPath = null,
|
||||
soundName = null,
|
||||
|
||||
Reference in New Issue
Block a user