Media: change the API

This commit is contained in:
ganfra 2023-04-27 12:06:01 +02:00
parent c920dfb97a
commit 4b5ca3acdd
18 changed files with 242 additions and 212 deletions

View file

@ -21,14 +21,14 @@ import io.element.android.libraries.matrix.api.core.RoomId
import io.element.android.libraries.matrix.api.core.SessionId
import io.element.android.libraries.matrix.api.core.UserId
import io.element.android.libraries.matrix.api.createroom.CreateRoomParameters
import io.element.android.libraries.matrix.api.media.MediaResolver
import io.element.android.libraries.matrix.api.media.MatrixMediaLoader
import io.element.android.libraries.matrix.api.notification.NotificationService
import io.element.android.libraries.matrix.api.pusher.PushersService
import io.element.android.libraries.matrix.api.room.MatrixRoom
import io.element.android.libraries.matrix.api.room.RoomMembershipObserver
import io.element.android.libraries.matrix.api.room.RoomSummaryDataSource
import io.element.android.libraries.matrix.api.verification.SessionVerificationService
import io.element.android.libraries.matrix.test.media.FakeMediaResolver
import io.element.android.libraries.matrix.test.media.FakeMediaLoader
import io.element.android.libraries.matrix.test.notification.FakeNotificationService
import io.element.android.libraries.matrix.test.pushers.FakePushersService
import io.element.android.libraries.matrix.test.room.FakeMatrixRoom
@ -42,6 +42,7 @@ class FakeMatrixClient(
private val userAvatarURLString: Result<String> = Result.success(AN_AVATAR_URL),
override val roomSummaryDataSource: RoomSummaryDataSource = FakeRoomSummaryDataSource(),
override val invitesDataSource: RoomSummaryDataSource = FakeRoomSummaryDataSource(),
override val mediaLoader: MatrixMediaLoader = FakeMediaLoader(),
private val sessionVerificationService: FakeSessionVerificationService = FakeSessionVerificationService(),
private val pushersService: FakePushersService = FakePushersService(),
private val notificationService: FakeNotificationService = FakeNotificationService(),
@ -77,10 +78,6 @@ class FakeMatrixClient(
override fun stopSync() = Unit
override fun mediaResolver(): MediaResolver {
return FakeMediaResolver()
}
override suspend fun logout() {
delay(100)
logoutFailure?.let { throw it }
@ -96,14 +93,6 @@ class FakeMatrixClient(
return userAvatarURLString
}
override suspend fun loadMediaContent(url: String): Result<ByteArray> {
return Result.success(ByteArray(0))
}
override suspend fun loadMediaThumbnail(url: String, width: Long, height: Long): Result<ByteArray> {
return Result.success(ByteArray(0))
}
override fun sessionVerificationService(): SessionVerificationService = sessionVerificationService
override fun pushersService(): PushersService = pushersService

View file

@ -0,0 +1,50 @@
/*
* Copyright (c) 2023 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.libraries.matrix.test.media
import io.element.android.libraries.matrix.api.media.MatrixMediaLoader
import java.nio.file.Path
import kotlin.io.path.Path
class FakeMediaLoader : MatrixMediaLoader {
var shouldFail = false
override suspend fun loadMediaContent(url: String): Result<ByteArray> {
return if (shouldFail) {
Result.failure(RuntimeException())
} else {
return Result.success(ByteArray(0))
}
}
override suspend fun loadMediaThumbnail(url: String, width: Long, height: Long): Result<ByteArray> {
return if (shouldFail) {
Result.failure(RuntimeException())
} else {
return Result.success(ByteArray(0))
}
}
override suspend fun loadMediaFile(url: String, mimeType: String?): Result<Path> {
return if (shouldFail) {
Result.failure(RuntimeException())
} else {
return Result.success(Path("path"))
}
}
}

View file

@ -1,32 +0,0 @@
/*
* Copyright (c) 2023 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.libraries.matrix.test.media
import io.element.android.libraries.matrix.api.media.MediaResolver
class FakeMediaResolver : MediaResolver {
private var result: Result<ByteArray> = Result.success(ByteArray(0))
fun givenResult(result: Result<ByteArray>) {
this.result = result
}
override suspend fun resolve(url: String?, kind: MediaResolver.Kind): Result<ByteArray> {
return result
}
}