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,22 +287,18 @@ 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 -> { is ImageMessageType -> notificationMediaRepoFactory.create(client)
when (val messageType = content.messageType) { .getMediaFile(
is ImageMessageType -> notificationMediaRepoFactory.create(client) mediaSource = messageType.source,
.getMediaFile( mimeType = messageType.info?.mimetype,
mediaSource = messageType.source, body = messageType.body,
mimeType = messageType.info?.mimetype, )
body = messageType.body, is VideoMessageType -> null // Use the thumbnail here?
)
is VideoMessageType -> null // Use the thumbnail here?
else -> null
}
}
else -> null else -> null
} ?: return null }
?: return null
return fileResult return fileResult
.onFailure { .onFailure {