Reduce API of JoinedRoom, caller must use the Timeline API from liveTimeline instead. (#4731)
This removes lots of boilerplate code.
This commit is contained in:
parent
3cf8237d29
commit
8d115213cc
20 changed files with 258 additions and 651 deletions
|
|
@ -13,6 +13,7 @@ import io.element.android.libraries.matrix.api.core.ProgressCallback
|
|||
import io.element.android.libraries.matrix.api.media.MediaUploadHandler
|
||||
import io.element.android.libraries.matrix.api.room.JoinedRoom
|
||||
import io.element.android.libraries.matrix.api.room.message.ReplyParameters
|
||||
import io.element.android.libraries.matrix.api.timeline.Timeline
|
||||
import io.element.android.libraries.preferences.api.store.SessionPreferencesStore
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.Job
|
||||
|
|
@ -49,7 +50,7 @@ class MediaSender @Inject constructor(
|
|||
progressCallback: ProgressCallback?,
|
||||
replyParameters: ReplyParameters?,
|
||||
): Result<Unit> {
|
||||
return room.sendMedia(
|
||||
return room.liveTimeline.sendMedia(
|
||||
uploadInfo = mediaUploadInfo,
|
||||
progressCallback = progressCallback,
|
||||
caption = caption,
|
||||
|
|
@ -76,7 +77,7 @@ class MediaSender @Inject constructor(
|
|||
compressIfPossible = compressIfPossible,
|
||||
)
|
||||
.flatMapCatching { info ->
|
||||
room.sendMedia(
|
||||
room.liveTimeline.sendMedia(
|
||||
uploadInfo = info,
|
||||
progressCallback = progressCallback,
|
||||
caption = caption,
|
||||
|
|
@ -108,7 +109,7 @@ class MediaSender @Inject constructor(
|
|||
audioInfo = audioInfo,
|
||||
waveform = waveForm,
|
||||
)
|
||||
room.sendMedia(
|
||||
room.liveTimeline.sendMedia(
|
||||
uploadInfo = newInfo,
|
||||
progressCallback = progressCallback,
|
||||
caption = null,
|
||||
|
|
@ -130,7 +131,7 @@ class MediaSender @Inject constructor(
|
|||
ongoingUploadJobs.remove(Job)
|
||||
}
|
||||
|
||||
private suspend fun JoinedRoom.sendMedia(
|
||||
private suspend fun Timeline.sendMedia(
|
||||
uploadInfo: MediaUploadInfo,
|
||||
progressCallback: ProgressCallback?,
|
||||
caption: String?,
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import io.element.android.libraries.matrix.api.room.JoinedRoom
|
|||
import io.element.android.libraries.matrix.api.room.message.ReplyParameters
|
||||
import io.element.android.libraries.matrix.test.media.FakeMediaUploadHandler
|
||||
import io.element.android.libraries.matrix.test.room.FakeJoinedRoom
|
||||
import io.element.android.libraries.matrix.test.timeline.FakeTimeline
|
||||
import io.element.android.libraries.mediaupload.test.FakeMediaPreProcessor
|
||||
import io.element.android.libraries.preferences.api.store.SessionPreferencesStore
|
||||
import io.element.android.libraries.preferences.test.InMemorySessionPreferencesStore
|
||||
|
|
@ -51,7 +52,9 @@ class MediaSenderTest {
|
|||
Result.success(FakeMediaUploadHandler())
|
||||
}
|
||||
val room = FakeJoinedRoom(
|
||||
sendImageResult = sendImageResult
|
||||
liveTimeline = FakeTimeline().apply {
|
||||
sendImageLambda = sendImageResult
|
||||
},
|
||||
)
|
||||
val sender = createMediaSender(room = room)
|
||||
|
||||
|
|
@ -74,14 +77,22 @@ class MediaSenderTest {
|
|||
|
||||
@Test
|
||||
fun `given a failure in the media upload when sending the whole process fails`() = runTest {
|
||||
val preProcessor = FakeMediaPreProcessor().apply {
|
||||
givenImageResult()
|
||||
}
|
||||
val sendImageResult =
|
||||
lambdaRecorder { _: File, _: File?, _: ImageInfo, _: String?, _: String?, _: ProgressCallback?, _: ReplyParameters? ->
|
||||
Result.failure<FakeMediaUploadHandler>(Exception())
|
||||
}
|
||||
val room = FakeJoinedRoom(
|
||||
sendImageResult = sendImageResult
|
||||
liveTimeline = FakeTimeline().apply {
|
||||
sendImageLambda = sendImageResult
|
||||
},
|
||||
)
|
||||
val sender = createMediaSender(
|
||||
preProcessor = preProcessor,
|
||||
room = room,
|
||||
)
|
||||
val sender = createMediaSender(room = room)
|
||||
|
||||
val uri = Uri.parse("content://image.jpg")
|
||||
val result = sender.sendMedia(uri = uri, mimeType = MimeTypes.Jpeg)
|
||||
|
|
@ -94,10 +105,12 @@ class MediaSenderTest {
|
|||
fun `given a cancellation in the media upload when sending the job is cancelled`() = runTest(StandardTestDispatcher()) {
|
||||
val sendFileResult =
|
||||
lambdaRecorder<File, FileInfo, String?, String?, ProgressCallback?, ReplyParameters?, Result<FakeMediaUploadHandler>> { _, _, _, _, _, _ ->
|
||||
Result.success(FakeMediaUploadHandler())
|
||||
}
|
||||
Result.success(FakeMediaUploadHandler())
|
||||
}
|
||||
val room = FakeJoinedRoom(
|
||||
sendFileResult = sendFileResult
|
||||
liveTimeline = FakeTimeline().apply {
|
||||
sendFileLambda = sendFileResult
|
||||
},
|
||||
)
|
||||
val sender = createMediaSender(room = room)
|
||||
val sendJob = launch {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue