Browse Source

Fix API break.

pull/3749/head
Benoit Marty 2 days ago
parent
commit
a899a0e129
  1. 33
      libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/preview/RoomPreviewMapper.kt
  2. 22
      libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/fixtures/factories/RoomPreviewInfo.kt
  3. 21
      libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/fixtures/fakes/FakeRustRoomPreview.kt
  4. 28
      libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/room/preview/RoomPreviewMapperTest.kt

33
libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/preview/RoomPreviewMapper.kt

@ -11,23 +11,28 @@ import io.element.android.libraries.matrix.api.core.RoomAlias
import io.element.android.libraries.matrix.api.core.RoomId import io.element.android.libraries.matrix.api.core.RoomId
import io.element.android.libraries.matrix.api.room.preview.RoomPreview import io.element.android.libraries.matrix.api.room.preview.RoomPreview
import io.element.android.libraries.matrix.impl.room.toRoomType import io.element.android.libraries.matrix.impl.room.toRoomType
import org.matrix.rustcomponents.sdk.JoinRule
import org.matrix.rustcomponents.sdk.Membership
import org.matrix.rustcomponents.sdk.RoomPreview as RustRoomPreview import org.matrix.rustcomponents.sdk.RoomPreview as RustRoomPreview
object RoomPreviewMapper { object RoomPreviewMapper {
fun map(roomPreview: RustRoomPreview): RoomPreview { fun map(roomPreview: RustRoomPreview): RoomPreview {
return RoomPreview( return roomPreview.use {
roomId = RoomId(roomPreview.roomId), val info = roomPreview.info()
canonicalAlias = roomPreview.canonicalAlias?.let(::RoomAlias), RoomPreview(
name = roomPreview.name, roomId = RoomId(info.roomId),
topic = roomPreview.topic, canonicalAlias = info.canonicalAlias?.let(::RoomAlias),
avatarUrl = roomPreview.avatarUrl, name = info.name,
numberOfJoinedMembers = roomPreview.numJoinedMembers.toLong(), topic = info.topic,
roomType = roomPreview.roomType.toRoomType(), avatarUrl = info.avatarUrl,
isHistoryWorldReadable = roomPreview.isHistoryWorldReadable, numberOfJoinedMembers = info.numJoinedMembers.toLong(),
isJoined = roomPreview.isJoined, roomType = info.roomType.toRoomType(),
isInvited = roomPreview.isInvited, isHistoryWorldReadable = info.isHistoryWorldReadable,
isPublic = roomPreview.isPublic, isJoined = info.membership == Membership.JOINED,
canKnock = roomPreview.canKnock isInvited = info.membership == Membership.INVITED,
) isPublic = info.joinRule == JoinRule.Public,
canKnock = info.joinRule == JoinRule.Knock
)
}
} }
} }

22
libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/fixtures/factories/RoomPreview.kt → libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/fixtures/factories/RoomPreviewInfo.kt

@ -9,16 +9,16 @@ package io.element.android.libraries.matrix.impl.fixtures.factories
import io.element.android.libraries.matrix.test.A_ROOM_ALIAS import io.element.android.libraries.matrix.test.A_ROOM_ALIAS
import io.element.android.libraries.matrix.test.A_ROOM_ID import io.element.android.libraries.matrix.test.A_ROOM_ID
import org.matrix.rustcomponents.sdk.RoomPreview import org.matrix.rustcomponents.sdk.JoinRule
import org.matrix.rustcomponents.sdk.Membership
import org.matrix.rustcomponents.sdk.RoomPreviewInfo
internal fun aRustRoomPreview( internal fun aRustRoomPreviewInfo(
canonicalAlias: String? = A_ROOM_ALIAS.value, canonicalAlias: String? = A_ROOM_ALIAS.value,
isJoined: Boolean = true, membership: Membership? = Membership.JOINED,
isInvited: Boolean = true, joinRule: JoinRule = JoinRule.Public,
isPublic: Boolean = true, ): RoomPreviewInfo {
canKnock: Boolean = true, return RoomPreviewInfo(
): RoomPreview {
return RoomPreview(
roomId = A_ROOM_ID.value, roomId = A_ROOM_ID.value,
canonicalAlias = canonicalAlias, canonicalAlias = canonicalAlias,
name = "name", name = "name",
@ -27,9 +27,7 @@ internal fun aRustRoomPreview(
numJoinedMembers = 1u, numJoinedMembers = 1u,
roomType = null, roomType = null,
isHistoryWorldReadable = true, isHistoryWorldReadable = true,
isJoined = isJoined, membership = membership,
isInvited = isInvited, joinRule = joinRule,
isPublic = isPublic,
canKnock = canKnock,
) )
} }

21
libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/fixtures/fakes/FakeRustRoomPreview.kt

@ -0,0 +1,21 @@
/*
* Copyright 2024 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only
* Please see LICENSE in the repository root for full details.
*/
package io.element.android.libraries.matrix.impl.fixtures.fakes
import io.element.android.libraries.matrix.impl.fixtures.factories.aRustRoomPreviewInfo
import org.matrix.rustcomponents.sdk.NoPointer
import org.matrix.rustcomponents.sdk.RoomPreview
import org.matrix.rustcomponents.sdk.RoomPreviewInfo
class FakeRustRoomPreview(
private val info: RoomPreviewInfo = aRustRoomPreviewInfo(),
) : RoomPreview(NoPointer) {
override fun info(): RoomPreviewInfo {
return info
}
}

28
libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/room/preview/RoomPreviewMapperTest.kt

@ -10,19 +10,23 @@ package io.element.android.libraries.matrix.impl.room.preview
import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertThat
import io.element.android.libraries.matrix.api.room.RoomType import io.element.android.libraries.matrix.api.room.RoomType
import io.element.android.libraries.matrix.api.room.preview.RoomPreview import io.element.android.libraries.matrix.api.room.preview.RoomPreview
import io.element.android.libraries.matrix.impl.fixtures.factories.aRustRoomPreview import io.element.android.libraries.matrix.impl.fixtures.factories.aRustRoomPreviewInfo
import io.element.android.libraries.matrix.impl.fixtures.fakes.FakeRustRoomPreview
import io.element.android.libraries.matrix.test.A_ROOM_ALIAS import io.element.android.libraries.matrix.test.A_ROOM_ALIAS
import io.element.android.libraries.matrix.test.A_ROOM_ID import io.element.android.libraries.matrix.test.A_ROOM_ID
import org.junit.Test import org.junit.Test
import org.matrix.rustcomponents.sdk.JoinRule
import org.matrix.rustcomponents.sdk.Membership
class RoomPreviewMapperTest { class RoomPreviewMapperTest {
@Test @Test
fun `map should map values 1`() { fun `map should map values 1`() {
assertThat( assertThat(
RoomPreviewMapper.map( RoomPreviewMapper.map(
aRustRoomPreview( FakeRustRoomPreview(
isJoined = false, info = aRustRoomPreviewInfo(
isInvited = false, membership = null,
)
) )
) )
).isEqualTo( ).isEqualTo(
@ -38,7 +42,7 @@ class RoomPreviewMapperTest {
isJoined = false, isJoined = false,
isInvited = false, isInvited = false,
isPublic = true, isPublic = true,
canKnock = true, canKnock = false,
) )
) )
} }
@ -47,10 +51,12 @@ class RoomPreviewMapperTest {
fun `map should map values 2`() { fun `map should map values 2`() {
assertThat( assertThat(
RoomPreviewMapper.map( RoomPreviewMapper.map(
aRustRoomPreview( FakeRustRoomPreview(
canonicalAlias = null, info = aRustRoomPreviewInfo(
isPublic = false, canonicalAlias = null,
canKnock = false, membership = Membership.JOINED,
joinRule = JoinRule.Knock,
)
) )
) )
).isEqualTo( ).isEqualTo(
@ -64,9 +70,9 @@ class RoomPreviewMapperTest {
roomType = RoomType.Room, roomType = RoomType.Room,
isHistoryWorldReadable = true, isHistoryWorldReadable = true,
isJoined = true, isJoined = true,
isInvited = true, isInvited = false,
isPublic = false, isPublic = false,
canKnock = false, canKnock = true,
) )
) )
} }

Loading…
Cancel
Save