Improve extension to fix a copy paste issue.

This commit is contained in:
Benoit Marty 2024-10-02 21:05:43 +02:00
parent f88ec4837e
commit 403bb78112

View file

@ -103,7 +103,7 @@ class DefaultNotifiableEventResolver @Inject constructor(
timestamp = this.timestamp, timestamp = this.timestamp,
senderDisambiguatedDisplayName = senderDisambiguatedDisplayName, senderDisambiguatedDisplayName = senderDisambiguatedDisplayName,
body = messageBody, body = messageBody,
imageUriString = fetchImageIfPresent(client)?.toString(), imageUriString = content.fetchImageIfPresent(client)?.toString(),
roomName = roomDisplayName, roomName = roomDisplayName,
roomIsDm = isDm, roomIsDm = isDm,
roomAvatarPath = roomAvatarUrl, roomAvatarPath = roomAvatarUrl,
@ -148,7 +148,6 @@ class DefaultNotifiableEventResolver @Inject constructor(
timestamp = this.timestamp, timestamp = this.timestamp,
senderDisambiguatedDisplayName = getDisambiguatedDisplayName(content.senderId), senderDisambiguatedDisplayName = getDisambiguatedDisplayName(content.senderId),
body = stringProvider.getString(CommonStrings.common_call_invite), body = stringProvider.getString(CommonStrings.common_call_invite),
imageUriString = fetchImageIfPresent(client)?.toString(),
roomName = roomDisplayName, roomName = roomDisplayName,
roomIsDm = isDm, roomIsDm = isDm,
roomAvatarPath = roomAvatarUrl, roomAvatarPath = roomAvatarUrl,
@ -288,10 +287,8 @@ class DefaultNotifiableEventResolver @Inject constructor(
} }
} }
private suspend fun NotificationData.fetchImageIfPresent(client: MatrixClient): Uri? { private suspend fun NotificationContent.MessageLike.RoomMessage.fetchImageIfPresent(client: MatrixClient): Uri? {
val fileResult = when (val content = this.content) { val fileResult = when (val messageType = messageType) {
is NotificationContent.MessageLike.RoomMessage -> {
when (val messageType = content.messageType) {
is ImageMessageType -> notificationMediaRepoFactory.create(client) is ImageMessageType -> notificationMediaRepoFactory.create(client)
.getMediaFile( .getMediaFile(
mediaSource = messageType.source, mediaSource = messageType.source,
@ -301,9 +298,7 @@ class DefaultNotifiableEventResolver @Inject constructor(
is VideoMessageType -> null // Use the thumbnail here? is VideoMessageType -> null // Use the thumbnail here?
else -> null else -> null
} }
} ?: return null
else -> null
} ?: return null
return fileResult return fileResult
.onFailure { .onFailure {