Changes after review
This commit is contained in:
parent
1b054aca5b
commit
97efff8aa4
14 changed files with 130 additions and 63 deletions
|
|
@ -1,69 +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.x.matrix
|
||||
|
||||
import io.element.android.x.matrix.core.RoomId
|
||||
import io.element.android.x.matrix.core.SessionId
|
||||
import io.element.android.x.matrix.core.UserId
|
||||
import io.element.android.x.matrix.media.FakeMediaResolver
|
||||
import io.element.android.x.matrix.media.MediaResolver
|
||||
import io.element.android.x.matrix.room.FakeMatrixRoom
|
||||
import io.element.android.x.matrix.room.InMemoryRoomSummaryDataSource
|
||||
import io.element.android.x.matrix.room.MatrixRoom
|
||||
import io.element.android.x.matrix.room.RoomSummaryDataSource
|
||||
import org.matrix.rustcomponents.sdk.MediaSource
|
||||
|
||||
class FakeMatrixClient(override val sessionId: SessionId) : MatrixClient {
|
||||
|
||||
override fun getRoom(roomId: RoomId): MatrixRoom? {
|
||||
return FakeMatrixRoom(roomId)
|
||||
}
|
||||
|
||||
override fun startSync() = Unit
|
||||
|
||||
override fun stopSync() = Unit
|
||||
|
||||
override fun roomSummaryDataSource(): RoomSummaryDataSource {
|
||||
return InMemoryRoomSummaryDataSource()
|
||||
}
|
||||
|
||||
override fun mediaResolver(): MediaResolver {
|
||||
return FakeMediaResolver()
|
||||
}
|
||||
|
||||
override suspend fun logout() = Unit
|
||||
|
||||
override fun userId(): UserId = UserId("")
|
||||
|
||||
override suspend fun loadUserDisplayName(): Result<String> {
|
||||
return Result.success("")
|
||||
}
|
||||
|
||||
override suspend fun loadUserAvatarURLString(): Result<String> {
|
||||
return Result.success("")
|
||||
}
|
||||
|
||||
override suspend fun loadMediaContentForSource(source: MediaSource): Result<ByteArray> {
|
||||
return Result.success(ByteArray(0))
|
||||
}
|
||||
|
||||
override suspend fun loadMediaThumbnailForSource(source: MediaSource, width: Long, height: Long): Result<ByteArray> {
|
||||
return Result.success(ByteArray(0))
|
||||
}
|
||||
|
||||
override fun close() = Unit
|
||||
}
|
||||
|
|
@ -16,9 +16,7 @@
|
|||
|
||||
package io.element.android.x.matrix.media
|
||||
|
||||
import io.element.android.x.matrix.MatrixClient
|
||||
import org.matrix.rustcomponents.sdk.MediaSource
|
||||
import org.matrix.rustcomponents.sdk.mediaSourceFromUrl
|
||||
|
||||
interface MediaResolver {
|
||||
|
||||
|
|
@ -39,23 +37,3 @@ interface MediaResolver {
|
|||
|
||||
suspend fun resolve(meta: Meta): ByteArray?
|
||||
}
|
||||
|
||||
internal class RustMediaResolver(private val client: MatrixClient) : MediaResolver {
|
||||
|
||||
override suspend fun resolve(url: String?, kind: MediaResolver.Kind): ByteArray? {
|
||||
if (url.isNullOrEmpty()) return null
|
||||
val mediaSource = mediaSourceFromUrl(url)
|
||||
return resolve(MediaResolver.Meta(mediaSource, kind))
|
||||
}
|
||||
|
||||
override suspend fun resolve(meta: MediaResolver.Meta): ByteArray? {
|
||||
return when (meta.kind) {
|
||||
is MediaResolver.Kind.Content -> client.loadMediaContentForSource(meta.source)
|
||||
is MediaResolver.Kind.Thumbnail -> client.loadMediaThumbnailForSource(
|
||||
meta.source,
|
||||
meta.kind.width.toLong(),
|
||||
meta.kind.height.toLong()
|
||||
)
|
||||
}.getOrNull()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,12 +16,25 @@
|
|||
|
||||
package io.element.android.x.matrix.media
|
||||
|
||||
class FakeMediaResolver : MediaResolver {
|
||||
import io.element.android.x.matrix.MatrixClient
|
||||
import org.matrix.rustcomponents.sdk.mediaSourceFromUrl
|
||||
|
||||
internal class RustMediaResolver(private val client: MatrixClient) : MediaResolver {
|
||||
|
||||
override suspend fun resolve(url: String?, kind: MediaResolver.Kind): ByteArray? {
|
||||
return null
|
||||
if (url.isNullOrEmpty()) return null
|
||||
val mediaSource = mediaSourceFromUrl(url)
|
||||
return resolve(MediaResolver.Meta(mediaSource, kind))
|
||||
}
|
||||
|
||||
override suspend fun resolve(meta: MediaResolver.Meta): ByteArray? {
|
||||
return null
|
||||
return when (meta.kind) {
|
||||
is MediaResolver.Kind.Content -> client.loadMediaContentForSource(meta.source)
|
||||
is MediaResolver.Kind.Thumbnail -> client.loadMediaThumbnailForSource(
|
||||
meta.source,
|
||||
meta.kind.width.toLong(),
|
||||
meta.kind.height.toLong()
|
||||
)
|
||||
}.getOrNull()
|
||||
}
|
||||
}
|
||||
|
|
@ -1,66 +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.x.matrix.room
|
||||
|
||||
import io.element.android.x.matrix.core.EventId
|
||||
import io.element.android.x.matrix.core.RoomId
|
||||
import io.element.android.x.matrix.timeline.FakeMatrixTimeline
|
||||
import io.element.android.x.matrix.timeline.MatrixTimeline
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.emptyFlow
|
||||
|
||||
class FakeMatrixRoom(
|
||||
override val roomId: RoomId,
|
||||
override val name: String? = null,
|
||||
override val bestName: String = "",
|
||||
override val displayName: String = "",
|
||||
override val topic: String? = null,
|
||||
override val avatarUrl: String? = null
|
||||
) : MatrixRoom {
|
||||
|
||||
override fun syncUpdateFlow(): Flow<Long> {
|
||||
return emptyFlow()
|
||||
}
|
||||
|
||||
override fun timeline(): MatrixTimeline {
|
||||
return FakeMatrixTimeline()
|
||||
}
|
||||
|
||||
override suspend fun userDisplayName(userId: String): Result<String?> {
|
||||
return Result.success("")
|
||||
}
|
||||
|
||||
override suspend fun userAvatarUrl(userId: String): Result<String?> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun sendMessage(message: String): Result<Unit> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun editMessage(originalEventId: EventId, message: String): Result<Unit> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun replyMessage(eventId: EventId, message: String): Result<Unit> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun redactEvent(eventId: EventId, reason: String?): Result<Unit> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
|
|
@ -1,29 +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.x.matrix.room
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.emptyFlow
|
||||
|
||||
class InMemoryRoomSummaryDataSource : RoomSummaryDataSource {
|
||||
|
||||
override fun roomSummaries(): Flow<List<RoomSummary>> {
|
||||
return emptyFlow()
|
||||
}
|
||||
|
||||
override fun setSlidingSyncRange(range: IntRange) = Unit
|
||||
}
|
||||
|
|
@ -1,60 +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.x.matrix.timeline
|
||||
|
||||
import io.element.android.x.matrix.core.EventId
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.emptyFlow
|
||||
import org.matrix.rustcomponents.sdk.TimelineListener
|
||||
|
||||
class FakeMatrixTimeline : MatrixTimeline {
|
||||
|
||||
override var callback: MatrixTimeline.Callback?
|
||||
get() = TODO("Not yet implemented")
|
||||
set(value) {}
|
||||
|
||||
override val hasMoreToLoad: Boolean
|
||||
get() = true
|
||||
|
||||
override fun timelineItems(): Flow<List<MatrixTimelineItem>> {
|
||||
return emptyFlow()
|
||||
}
|
||||
|
||||
override suspend fun paginateBackwards(count: Int): Result<Unit> {
|
||||
return Result.success(Unit)
|
||||
}
|
||||
|
||||
override fun addListener(timelineListener: TimelineListener) {
|
||||
//
|
||||
}
|
||||
|
||||
override fun initialize() = Unit
|
||||
|
||||
override fun dispose() = Unit
|
||||
|
||||
override suspend fun sendMessage(message: String): Result<Unit> {
|
||||
return Result.success(Unit)
|
||||
}
|
||||
|
||||
override suspend fun editMessage(originalEventId: EventId, message: String): Result<Unit> {
|
||||
return Result.success(Unit)
|
||||
}
|
||||
|
||||
override suspend fun replyMessage(inReplyToEventId: EventId, message: String): Result<Unit> {
|
||||
return Result.success(Unit)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue