diff --git a/features/messenger/src/main/kotlin/app/dapk/st/messenger/DecryptingFetcher.kt b/features/messenger/src/main/kotlin/app/dapk/st/messenger/DecryptingFetcher.kt index 16e11d6..3e3226c 100644 --- a/features/messenger/src/main/kotlin/app/dapk/st/messenger/DecryptingFetcher.kt +++ b/features/messenger/src/main/kotlin/app/dapk/st/messenger/DecryptingFetcher.kt @@ -27,6 +27,9 @@ class DecryptingFetcher : Fetcher { private val http = OkHttpClient() override suspend fun fetch(pool: BitmapPool, data: RoomEvent.Image, size: Size, options: Options): FetchResult { + val response = http.newCall(Request.Builder().url(data.imageMeta.url).build()).execute() + val outputStream = Buffer() + val keys = data.imageMeta.keys!! val key = Base64.decode(keys.k.replace('-', '+').replace('_', '/'), Base64.DEFAULT) val initVectorBytes = Base64.decode(keys.iv, Base64.DEFAULT) @@ -42,9 +45,6 @@ class DecryptingFetcher : Fetcher { val d = ByteArray(CRYPTO_BUFFER_SIZE) var decodedBytes: ByteArray - val response = http.newCall(Request.Builder().url(data.imageMeta.url).build()).execute() - val outputStream = Buffer() - response.body()?.let { it.byteStream().use { read = it.read(d) diff --git a/features/messenger/src/main/kotlin/app/dapk/st/messenger/MessengerViewModel.kt b/features/messenger/src/main/kotlin/app/dapk/st/messenger/MessengerViewModel.kt index 87d457b..2a4621b 100644 --- a/features/messenger/src/main/kotlin/app/dapk/st/messenger/MessengerViewModel.kt +++ b/features/messenger/src/main/kotlin/app/dapk/st/messenger/MessengerViewModel.kt @@ -70,8 +70,10 @@ internal class MessengerViewModel( private fun CoroutineScope.updateRoomReadStateAsync(latestReadEvent: EventId, state: MessengerState): Deferred { return async { - roomService.markFullyRead(state.roomState.roomOverview.roomId, latestReadEvent) - roomStore.markRead(state.roomState.roomOverview.roomId) + runCatching { + roomService.markFullyRead(state.roomState.roomOverview.roomId, latestReadEvent) + roomStore.markRead(state.roomState.roomOverview.roomId) + } } }