Browse Source

Media: handle PR review remarks

feature/jme/open-room-member-details-when-clicking-on-user-data
ganfra 1 year ago
parent
commit
b2a66ddafe
  1. 2
      features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt
  2. 6
      features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/media/viewer/MediaViewerPresenter.kt
  3. 2
      libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/media/MatrixMediaLoader.kt
  4. 2
      libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/media/RustMediaLoader.kt
  5. 2
      libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/media/FakeMediaLoader.kt
  6. 3
      libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/media/CoilMediaFetcher.kt

2
features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt

@ -105,7 +105,7 @@ fun MessagesView(
initialValue = ModalBottomSheetValue.Hidden, initialValue = ModalBottomSheetValue.Hidden,
) )
val composerState = state.composerState val composerState = state.composerState
val initialBottomSheetState = if (LocalInspectionMode.current && composerState.showAttachmentSourcePicker != null) { val initialBottomSheetState = if (LocalInspectionMode.current && composerState.showAttachmentSourcePicker) {
ModalBottomSheetValue.Expanded ModalBottomSheetValue.Expanded
} else { } else {
ModalBottomSheetValue.Hidden ModalBottomSheetValue.Hidden

6
features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/media/viewer/MediaViewerPresenter.kt

@ -58,7 +58,7 @@ class MediaViewerPresenter @AssistedInject constructor(
mutableStateOf(Async.Uninitialized) mutableStateOf(Async.Uninitialized)
} }
DisposableEffect(loadMediaTrigger) { DisposableEffect(loadMediaTrigger) {
coroutineScope.loadMedia(mediaFile, localMedia) coroutineScope.downloadMedia(mediaFile, localMedia)
onDispose { onDispose {
mediaFile.value?.close() mediaFile.value?.close()
} }
@ -80,9 +80,9 @@ class MediaViewerPresenter @AssistedInject constructor(
) )
} }
private fun CoroutineScope.loadMedia(mediaFile: MutableState<MediaFile?>, localMedia: MutableState<Async<LocalMedia>>) = launch { private fun CoroutineScope.downloadMedia(mediaFile: MutableState<MediaFile?>, localMedia: MutableState<Async<LocalMedia>>) = launch {
localMedia.value = Async.Loading() localMedia.value = Async.Loading()
mediaLoader.loadMediaFile(inputs.mediaSource, inputs.mimeType) mediaLoader.downloadMediaFile(inputs.mediaSource, inputs.mimeType)
.onSuccess { .onSuccess {
mediaFile.value = it mediaFile.value = it
}.mapCatching { }.mapCatching {

2
libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/media/MatrixMediaLoader.kt

@ -36,5 +36,5 @@ interface MatrixMediaLoader {
* @param mimeType: optional mime type * @param mimeType: optional mime type
* @return a [Result] of [MediaFile] * @return a [Result] of [MediaFile]
*/ */
suspend fun loadMediaFile(source: MediaSource, mimeType: String?): Result<MediaFile> suspend fun downloadMediaFile(source: MediaSource, mimeType: String?): Result<MediaFile>
} }

2
libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/media/RustMediaLoader.kt

@ -59,7 +59,7 @@ class RustMediaLoader(
} }
} }
override suspend fun loadMediaFile(source: MediaSource, mimeType: String?): Result<MediaFile> = override suspend fun downloadMediaFile(source: MediaSource, mimeType: String?): Result<MediaFile> =
withContext(dispatchers.io) { withContext(dispatchers.io) {
runCatching { runCatching {
source.toRustMediaSource().use { mediaSource -> source.toRustMediaSource().use { mediaSource ->

2
libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/media/FakeMediaLoader.kt

@ -44,7 +44,7 @@ class FakeMediaLoader : MatrixMediaLoader {
} }
} }
override suspend fun loadMediaFile(source: MediaSource, mimeType: String?): Result<MediaFile> { override suspend fun downloadMediaFile(source: MediaSource, mimeType: String?): Result<MediaFile> {
delay(FAKE_DELAY_IN_MS) delay(FAKE_DELAY_IN_MS)
return if (shouldFail) { return if (shouldFail) {
Result.failure(RuntimeException()) Result.failure(RuntimeException())

3
libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/media/CoilMediaFetcher.kt

@ -35,8 +35,7 @@ internal class CoilMediaFetcher(
override suspend fun fetch(): FetchResult? { override suspend fun fetch(): FetchResult? {
return loadMedia() return loadMedia()
.map { data -> .map { data ->
ByteBuffer.wrap(data) val byteBuffer = ByteBuffer.wrap(data)
}.map { byteBuffer ->
imageLoader.components.newFetcher(byteBuffer, options, imageLoader)?.first?.fetch() imageLoader.components.newFetcher(byteBuffer, options, imageLoader)?.first?.fetch()
}.getOrThrow() }.getOrThrow()
} }

Loading…
Cancel
Save