Skip to content

Commit a873e71

Browse files
authored
misc (matrix) : use innerClient.subscribeToRoomInfo sdk method (#4838)
1 parent de194e0 commit a873e71

File tree

11 files changed

+118
-135
lines changed

11 files changed

+118
-135
lines changed

appnav/src/main/kotlin/io/element/android/appnav/room/RoomFlowNode.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ import io.element.android.libraries.matrix.api.MatrixClient
4242
import io.element.android.libraries.matrix.api.core.RoomAlias
4343
import io.element.android.libraries.matrix.api.core.RoomId
4444
import io.element.android.libraries.matrix.api.core.RoomIdOrAlias
45-
import io.element.android.libraries.matrix.api.core.toRoomIdOrAlias
46-
import io.element.android.libraries.matrix.api.getRoomInfoFlow
4745
import io.element.android.libraries.matrix.api.room.CurrentUserMembership
4846
import io.element.android.libraries.matrix.api.room.RoomMembershipObserver
4947
import io.element.android.libraries.matrix.api.room.alias.ResolvedRoomAlias
@@ -124,7 +122,7 @@ class RoomFlowNode @AssistedInject constructor(
124122
}
125123

126124
private fun subscribeToRoomInfoFlow(roomId: RoomId, serverNames: List<String>) {
127-
val roomInfoFlow = client.getRoomInfoFlow(roomIdOrAlias = roomId.toRoomIdOrAlias())
125+
val roomInfoFlow = client.getRoomInfoFlow(roomId)
128126
val isSpaceFlow = roomInfoFlow.map { it.getOrNull()?.isSpace.orFalse() }.distinctUntilChanged()
129127
val currentMembershipFlow = roomInfoFlow.map { it.getOrNull()?.currentUserMembership }.distinctUntilChanged()
130128
combine(currentMembershipFlow, isSpaceFlow) { membership, isSpace ->

features/joinroom/impl/src/main/kotlin/io/element/android/features/joinroom/impl/JoinRoomPresenter.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ import io.element.android.libraries.core.meta.BuildMeta
3939
import io.element.android.libraries.matrix.api.MatrixClient
4040
import io.element.android.libraries.matrix.api.core.RoomId
4141
import io.element.android.libraries.matrix.api.core.RoomIdOrAlias
42-
import io.element.android.libraries.matrix.api.core.toRoomIdOrAlias
4342
import io.element.android.libraries.matrix.api.exception.ClientException
4443
import io.element.android.libraries.matrix.api.exception.ErrorKind
45-
import io.element.android.libraries.matrix.api.getRoomInfoFlow
4644
import io.element.android.libraries.matrix.api.room.CurrentUserMembership
4745
import io.element.android.libraries.matrix.api.room.RoomInfo
4846
import io.element.android.libraries.matrix.api.room.RoomMember
@@ -88,7 +86,7 @@ class JoinRoomPresenter @AssistedInject constructor(
8886
val coroutineScope = rememberCoroutineScope()
8987
var retryCount by remember { mutableIntStateOf(0) }
9088
val roomInfo by remember {
91-
matrixClient.getRoomInfoFlow(roomId.toRoomIdOrAlias())
89+
matrixClient.getRoomInfoFlow(roomId)
9290
}.collectAsState(initial = Optional.empty())
9391
val joinAction: MutableState<AsyncAction<Unit>> = remember { mutableStateOf(AsyncAction.Uninitialized) }
9492
val knockAction: MutableState<AsyncAction<Unit>> = remember { mutableStateOf(AsyncAction.Uninitialized) }

features/joinroom/impl/src/test/kotlin/io/element/android/features/joinroom/impl/JoinRoomPresenterTest.kt

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ import io.element.android.libraries.matrix.test.A_USER_ID
4545
import io.element.android.libraries.matrix.test.A_USER_ID_2
4646
import io.element.android.libraries.matrix.test.FakeMatrixClient
4747
import io.element.android.libraries.matrix.test.core.aBuildMeta
48+
import io.element.android.libraries.matrix.test.room.aRoomInfo
4849
import io.element.android.libraries.matrix.test.room.aRoomMember
4950
import io.element.android.libraries.matrix.test.room.aRoomPreview
5051
import io.element.android.libraries.matrix.test.room.aRoomPreviewInfo
51-
import io.element.android.libraries.matrix.test.room.aRoomSummary
5252
import io.element.android.libraries.matrix.test.room.join.FakeJoinRoom
5353
import io.element.android.libraries.matrix.ui.model.InviteSender
5454
import io.element.android.libraries.matrix.ui.model.toInviteSender
@@ -88,12 +88,12 @@ class JoinRoomPresenterTest {
8888

8989
@Test
9090
fun `present - when room is joined then content state is filled with his data`() = runTest {
91-
val roomSummary = aRoomSummary()
91+
val roomInfo = aRoomInfo()
9292
val matrixClient = FakeMatrixClient(
9393
getNotJoinedRoomResult = { _, _ -> Result.failure(AN_EXCEPTION) },
9494
).apply {
95-
getRoomSummaryFlowLambda = { _ ->
96-
flowOf(Optional.of(roomSummary))
95+
getRoomInfoFlowLambda = { _ ->
96+
flowOf(Optional.of(roomInfo))
9797
}
9898
}
9999
val presenter = createJoinRoomPresenter(
@@ -104,58 +104,58 @@ class JoinRoomPresenterTest {
104104
awaitItem().also { state ->
105105
val contentState = state.contentState as ContentState.Loaded
106106
assertThat(contentState.roomId).isEqualTo(A_ROOM_ID)
107-
assertThat(contentState.name).isEqualTo(roomSummary.info.name)
108-
assertThat(contentState.topic).isEqualTo(roomSummary.info.topic)
109-
assertThat(contentState.alias).isEqualTo(roomSummary.info.canonicalAlias)
110-
assertThat(contentState.numberOfMembers).isEqualTo(roomSummary.info.joinedMembersCount)
111-
assertThat(contentState.isDm).isEqualTo(roomSummary.info.isDirect)
112-
assertThat(contentState.roomAvatarUrl).isEqualTo(roomSummary.info.avatarUrl)
107+
assertThat(contentState.name).isEqualTo(roomInfo.name)
108+
assertThat(contentState.topic).isEqualTo(roomInfo.topic)
109+
assertThat(contentState.alias).isEqualTo(roomInfo.canonicalAlias)
110+
assertThat(contentState.numberOfMembers).isEqualTo(roomInfo.joinedMembersCount)
111+
assertThat(contentState.isDm).isEqualTo(roomInfo.isDirect)
112+
assertThat(contentState.roomAvatarUrl).isEqualTo(roomInfo.avatarUrl)
113113
}
114114
}
115115
}
116116

117117
@Test
118118
fun `present - when room is invited then join authorization is equal to invited`() = runTest {
119-
val roomSummary = aRoomSummary(currentUserMembership = CurrentUserMembership.INVITED)
119+
val roomInfo = aRoomInfo(currentUserMembership = CurrentUserMembership.INVITED)
120120
val matrixClient = FakeMatrixClient(
121121
getNotJoinedRoomResult = { _, _ -> Result.failure(AN_EXCEPTION) },
122122
).apply {
123-
getRoomSummaryFlowLambda = { _ ->
124-
flowOf(Optional.of(roomSummary))
123+
getRoomInfoFlowLambda = { _ ->
124+
flowOf(Optional.of(roomInfo))
125125
}
126126
}
127127
val seenInvitesStore = InMemorySeenInvitesStore()
128128
val presenter = createJoinRoomPresenter(
129129
matrixClient = matrixClient,
130130
seenInvitesStore = seenInvitesStore,
131131
)
132-
val inviteData = roomSummary.info.toInviteData()
132+
val inviteData = roomInfo.toInviteData()
133133
assertThat(seenInvitesStore.seenRoomIds().first()).isEmpty()
134134
presenter.test {
135135
skipItems(2)
136136
awaitItem().also { state ->
137137
assertThat(state.joinAuthorisationStatus).isEqualTo(JoinAuthorisationStatus.IsInvited(inviteData, null))
138138
}
139139
// Check that the roomId is stored in the seen invites store
140-
assertThat(seenInvitesStore.seenRoomIds().first()).containsExactly(roomSummary.roomId)
140+
assertThat(seenInvitesStore.seenRoomIds().first()).containsExactly(roomInfo.id)
141141
}
142142
}
143143

144144
@Test
145145
fun `present - when room is invited then join authorization is equal to invited, an inviter is provided`() = runTest {
146146
val inviter = aRoomMember(userId = UserId("@bob:example.com"), displayName = "Bob")
147147
val expectedInviteSender = inviter.toInviteSender()
148-
val roomSummary = aRoomSummary(
148+
val roomInfo = aRoomInfo(
149149
currentUserMembership = CurrentUserMembership.INVITED,
150150
joinedMembersCount = 5,
151151
inviter = inviter,
152152
)
153-
val inviteData = roomSummary.info.toInviteData()
153+
val inviteData = roomInfo.toInviteData()
154154
val matrixClient = FakeMatrixClient(
155155
getNotJoinedRoomResult = { _, _ -> Result.failure(AN_EXCEPTION) },
156156
).apply {
157-
getRoomSummaryFlowLambda = { _ ->
158-
flowOf(Optional.of(roomSummary))
157+
getRoomInfoFlowLambda = { _ ->
158+
flowOf(Optional.of(roomInfo))
159159
}
160160
}
161161
val presenter = createJoinRoomPresenter(
@@ -172,7 +172,7 @@ class JoinRoomPresenterTest {
172172

173173
@Test
174174
fun `present - when room is invited read the number of member from the room preview`() = runTest {
175-
val roomSummary = aRoomSummary(
175+
val roomInfo = aRoomInfo(
176176
currentUserMembership = CurrentUserMembership.INVITED,
177177
// It seems that the SDK does not provide this value.
178178
joinedMembersCount = 0,
@@ -188,8 +188,8 @@ class JoinRoomPresenterTest {
188188
)
189189
},
190190
).apply {
191-
getRoomSummaryFlowLambda = { _ ->
192-
flowOf(Optional.of(roomSummary))
191+
getRoomInfoFlowLambda = { _ ->
192+
flowOf(Optional.of(roomInfo))
193193
}
194194
}
195195
val presenter = createJoinRoomPresenter(
@@ -209,13 +209,13 @@ class JoinRoomPresenterTest {
209209
val acceptDeclinePresenter = Presenter {
210210
anAcceptDeclineInviteState(eventSink = eventSinkRecorder)
211211
}
212-
val roomSummary = aRoomSummary(currentUserMembership = CurrentUserMembership.INVITED)
212+
val roomInfo = aRoomInfo(currentUserMembership = CurrentUserMembership.INVITED)
213213
val matrixClient = FakeMatrixClient().apply {
214-
getRoomSummaryFlowLambda = { _ ->
215-
flowOf(Optional.of(roomSummary))
214+
getRoomInfoFlowLambda = { _ ->
215+
flowOf(Optional.of(roomInfo))
216216
}
217217
}
218-
val inviteData = roomSummary.info.toInviteData()
218+
val inviteData = roomInfo.toInviteData()
219219
val presenter = createJoinRoomPresenter(
220220
matrixClient = matrixClient,
221221
acceptDeclineInvitePresenter = acceptDeclinePresenter
@@ -324,7 +324,7 @@ class JoinRoomPresenterTest {
324324

325325
@Test
326326
fun `present - when room is banned, then join authorization is equal to IsBanned`() = runTest {
327-
val roomSummary = aRoomSummary(currentUserMembership = CurrentUserMembership.BANNED, joinRule = JoinRule.Public)
327+
val roomInfo = aRoomInfo(currentUserMembership = CurrentUserMembership.BANNED, joinRule = JoinRule.Public)
328328
val matrixClient = FakeMatrixClient(
329329
getNotJoinedRoomResult = { _, _ ->
330330
Result.success(
@@ -346,8 +346,8 @@ class JoinRoomPresenterTest {
346346
)
347347
}
348348
).apply {
349-
getRoomSummaryFlowLambda = { _ ->
350-
flowOf(Optional.of(roomSummary))
349+
getRoomInfoFlowLambda = { _ ->
350+
flowOf(Optional.of(roomInfo))
351351
}
352352
}
353353
val presenter = createJoinRoomPresenter(
@@ -369,12 +369,12 @@ class JoinRoomPresenterTest {
369369

370370
@Test
371371
fun `present - when room is left and public then join authorization is equal to canJoin`() = runTest {
372-
val roomSummary = aRoomSummary(currentUserMembership = CurrentUserMembership.LEFT, joinRule = JoinRule.Public)
372+
val roomInfo = aRoomInfo(currentUserMembership = CurrentUserMembership.LEFT, joinRule = JoinRule.Public)
373373
val matrixClient = FakeMatrixClient(
374374
getNotJoinedRoomResult = { _, _ -> Result.failure(AN_EXCEPTION) },
375375
).apply {
376-
getRoomSummaryFlowLambda = { _ ->
377-
flowOf(Optional.of(roomSummary))
376+
getRoomInfoFlowLambda = { _ ->
377+
flowOf(Optional.of(roomInfo))
378378
}
379379
}
380380
val presenter = createJoinRoomPresenter(
@@ -390,12 +390,12 @@ class JoinRoomPresenterTest {
390390

391391
@Test
392392
fun `present - when room is left and join rule null then join authorization is equal to Unknown`() = runTest {
393-
val roomSummary = aRoomSummary(currentUserMembership = CurrentUserMembership.LEFT, joinRule = null)
393+
val roomInfo = aRoomInfo(currentUserMembership = CurrentUserMembership.LEFT, joinRule = null)
394394
val matrixClient = FakeMatrixClient(
395395
getNotJoinedRoomResult = { _, _ -> Result.failure(AN_EXCEPTION) },
396396
).apply {
397-
getRoomSummaryFlowLambda = { _ ->
398-
flowOf(Optional.of(roomSummary))
397+
getRoomInfoFlowLambda = { _ ->
398+
flowOf(Optional.of(roomInfo))
399399
}
400400
}
401401
val presenter = createJoinRoomPresenter(

libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/MatrixClient.kt

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import io.element.android.libraries.matrix.api.room.RoomMembershipObserver
3131
import io.element.android.libraries.matrix.api.room.alias.ResolvedRoomAlias
3232
import io.element.android.libraries.matrix.api.roomdirectory.RoomDirectoryService
3333
import io.element.android.libraries.matrix.api.roomlist.RoomListService
34-
import io.element.android.libraries.matrix.api.roomlist.RoomSummary
3534
import io.element.android.libraries.matrix.api.sync.SlidingSyncVersion
3635
import io.element.android.libraries.matrix.api.sync.SyncService
3736
import io.element.android.libraries.matrix.api.user.MatrixSearchUserResults
@@ -41,8 +40,6 @@ import kotlinx.collections.immutable.ImmutableList
4140
import kotlinx.coroutines.CoroutineScope
4241
import kotlinx.coroutines.flow.Flow
4342
import kotlinx.coroutines.flow.StateFlow
44-
import kotlinx.coroutines.flow.distinctUntilChanged
45-
import kotlinx.coroutines.flow.map
4643
import java.util.Optional
4744

4845
interface MatrixClient {
@@ -65,9 +62,9 @@ interface MatrixClient {
6562
suspend fun setDisplayName(displayName: String): Result<Unit>
6663
suspend fun uploadAvatar(mimeType: String, data: ByteArray): Result<Unit>
6764
suspend fun removeAvatar(): Result<Unit>
68-
suspend fun joinRoom(roomId: RoomId): Result<RoomSummary?>
69-
suspend fun joinRoomByIdOrAlias(roomIdOrAlias: RoomIdOrAlias, serverNames: List<String>): Result<RoomSummary?>
70-
suspend fun knockRoom(roomIdOrAlias: RoomIdOrAlias, message: String, serverNames: List<String>): Result<RoomSummary?>
65+
suspend fun joinRoom(roomId: RoomId): Result<RoomInfo?>
66+
suspend fun joinRoomByIdOrAlias(roomIdOrAlias: RoomIdOrAlias, serverNames: List<String>): Result<RoomInfo?>
67+
suspend fun knockRoom(roomIdOrAlias: RoomIdOrAlias, message: String, serverNames: List<String>): Result<RoomInfo?>
7168
fun syncService(): SyncService
7269
fun sessionVerificationService(): SessionVerificationService
7370
fun pushersService(): PushersService
@@ -99,11 +96,11 @@ interface MatrixClient {
9996
fun roomMembershipObserver(): RoomMembershipObserver
10097

10198
/**
102-
* Get a room summary flow for a given room ID or alias.
103-
* The flow will emit a new value whenever the room summary is updated.
99+
* Get a room info flow for a given room ID.
100+
* The flow will emit a new value whenever the room info is updated.
104101
* The flow will emit Optional.empty item if the room is not found.
105102
*/
106-
fun getRoomSummaryFlow(roomIdOrAlias: RoomIdOrAlias): Flow<Optional<RoomSummary>>
103+
fun getRoomInfoFlow(roomId: RoomId): Flow<Optional<RoomInfo>>
107104

108105
fun isMe(userId: UserId?) = userId == sessionId
109106

@@ -169,17 +166,6 @@ interface MatrixClient {
169166
suspend fun canReportRoom(): Boolean
170167
}
171168

172-
/**
173-
* Get a room info flow for a given room ID or alias.
174-
* The flow will emit a new value whenever the room info is updated.
175-
* The flow will emit Optional.empty item if the room is not found.
176-
*/
177-
fun MatrixClient.getRoomInfoFlow(roomIdOrAlias: RoomIdOrAlias): Flow<Optional<RoomInfo>> {
178-
return getRoomSummaryFlow(roomIdOrAlias)
179-
.map { roomSummary -> roomSummary.map { it.info } }
180-
.distinctUntilChanged()
181-
}
182-
183169
/**
184170
* Returns a room alias from a room alias name, or null if the name is not valid.
185171
* @param name the room alias name ie. the local part of the room alias.

0 commit comments

Comments
 (0)