Skip to content

Commit 9741b3d

Browse files
authored
Merge pull request #906 from vector-im/feature/fga/update-rust-sdk-0.1.34
Feature/fga/update rust sdk 0.1.34
2 parents f32a177 + dfd7f9c commit 9741b3d

File tree

15 files changed

+55
-77
lines changed

15 files changed

+55
-77
lines changed

appnav/src/main/kotlin/io/element/android/appnav/LoggedInFlowNode.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ class LoggedInFlowNode @AssistedInject constructor(
139139
}
140140
},
141141
onResume = {
142-
syncService.startSync()
142+
lifecycleScope.launch {
143+
syncService.startSync()
144+
}
143145
},
144146
onPause = {
145147
syncService.stopSync()

features/invitelist/impl/src/main/kotlin/io/element/android/features/invitelist/impl/InviteListPresenter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class InviteListPresenter @Inject constructor(
139139
private fun CoroutineScope.acceptInvite(roomId: RoomId, acceptedAction: MutableState<Async<RoomId>>) = launch {
140140
suspend {
141141
client.getRoom(roomId)?.use {
142-
it.acceptInvitation().getOrThrow()
142+
it.join().getOrThrow()
143143
notificationDrawerManager.clearMembershipNotificationForRoom(client.sessionId, roomId)
144144
analyticsService.capture(it.toAnalyticsJoinedRoom(JoinedRoom.Trigger.Invite))
145145
}
@@ -150,7 +150,7 @@ class InviteListPresenter @Inject constructor(
150150
private fun CoroutineScope.declineInvite(roomId: RoomId, declinedAction: MutableState<Async<Unit>>) = launch {
151151
suspend {
152152
client.getRoom(roomId)?.use {
153-
it.rejectInvitation().getOrThrow()
153+
it.leave().getOrThrow()
154154
notificationDrawerManager.clearMembershipNotificationForRoom(client.sessionId, roomId)
155155
}
156156
Unit

features/invitelist/impl/src/test/kotlin/io/element/android/features/invitelist/impl/InviteListPresenterTests.kt

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ class InviteListPresenterTests {
211211

212212
skipItems(2)
213213

214-
Truth.assertThat(room.isInviteRejected).isTrue()
215214
Truth.assertThat(fakeNotificationDrawerManager.getClearMembershipNotificationForRoomCount(client.sessionId, A_ROOM_ID)).isEqualTo(1)
216215
}
217216
}
@@ -225,7 +224,7 @@ class InviteListPresenterTests {
225224
val room = FakeMatrixRoom()
226225
val presenter = createPresenter(client)
227226
val ex = Throwable("Ruh roh!")
228-
room.givenRejectInviteResult(Result.failure(ex))
227+
room.givenLeaveRoomError(ex)
229228
client.givenGetRoomResult(A_ROOM_ID, room)
230229

231230
moleculeFlow(RecompositionClock.Immediate) {
@@ -242,7 +241,6 @@ class InviteListPresenterTests {
242241

243242
val newState = awaitItem()
244243

245-
Truth.assertThat(room.isInviteRejected).isTrue()
246244
Truth.assertThat(newState.declinedAction).isEqualTo(Async.Failure<Unit>(ex))
247245
}
248246
}
@@ -256,7 +254,7 @@ class InviteListPresenterTests {
256254
val room = FakeMatrixRoom()
257255
val presenter = createPresenter(client)
258256
val ex = Throwable("Ruh roh!")
259-
room.givenRejectInviteResult(Result.failure(ex))
257+
room.givenLeaveRoomError(ex)
260258
client.givenGetRoomResult(A_ROOM_ID, room)
261259

262260
moleculeFlow(RecompositionClock.Immediate) {
@@ -298,7 +296,6 @@ class InviteListPresenterTests {
298296

299297
val newState = awaitItem()
300298

301-
Truth.assertThat(room.isInviteAccepted).isTrue()
302299
Truth.assertThat(newState.acceptedAction).isEqualTo(Async.Success(A_ROOM_ID))
303300
Truth.assertThat(fakeNotificationDrawerManager.getClearMembershipNotificationForRoomCount(client.sessionId, A_ROOM_ID)).isEqualTo(1)
304301
}
@@ -313,7 +310,7 @@ class InviteListPresenterTests {
313310
val room = FakeMatrixRoom()
314311
val presenter = createPresenter(client)
315312
val ex = Throwable("Ruh roh!")
316-
room.givenAcceptInviteResult(Result.failure(ex))
313+
room.givenJoinRoomResult(Result.failure(ex))
317314
client.givenGetRoomResult(A_ROOM_ID, room)
318315

319316
moleculeFlow(RecompositionClock.Immediate) {
@@ -322,10 +319,7 @@ class InviteListPresenterTests {
322319
val originalState = awaitItem()
323320
originalState.eventSink(InviteListEvents.AcceptInvite(originalState.inviteList[0]))
324321

325-
val newState = awaitItem()
326-
327-
Truth.assertThat(room.isInviteAccepted).isTrue()
328-
Truth.assertThat(newState.acceptedAction).isEqualTo(Async.Failure<RoomId>(ex))
322+
Truth.assertThat(awaitItem().acceptedAction).isEqualTo(Async.Failure<RoomId>(ex))
329323
}
330324
}
331325

@@ -338,7 +332,7 @@ class InviteListPresenterTests {
338332
val room = FakeMatrixRoom()
339333
val presenter = createPresenter(client)
340334
val ex = Throwable("Ruh roh!")
341-
room.givenAcceptInviteResult(Result.failure(ex))
335+
room.givenJoinRoomResult(Result.failure(ex))
342336
client.givenGetRoomResult(A_ROOM_ID, room)
343337

344338
moleculeFlow(RecompositionClock.Immediate) {

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ jsoup = { module = "org.jsoup:jsoup", version.ref = "jsoup" }
145145
appyx_core = { module = "com.bumble.appyx:core", version.ref = "appyx" }
146146
molecule-runtime = { module = "app.cash.molecule:molecule-runtime", version.ref = "molecule" }
147147
timber = "com.jakewharton.timber:timber:5.0.1"
148-
matrix_sdk = "org.matrix.rustcomponents:sdk-android:0.1.31"
148+
matrix_sdk = "org.matrix.rustcomponents:sdk-android:0.1.34"
149149
sqldelight-driver-android = { module = "com.squareup.sqldelight:android-driver", version.ref = "sqldelight" }
150150
sqldelight-driver-jvm = { module = "com.squareup.sqldelight:sqlite-driver", version.ref = "sqldelight" }
151151
sqldelight-coroutines = { module = "com.squareup.sqldelight:coroutines-extensions", version.ref = "sqldelight" }

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ interface MatrixRoom : Closeable {
9595

9696
suspend fun leave(): Result<Unit>
9797

98-
suspend fun acceptInvitation(): Result<Unit>
99-
100-
suspend fun rejectInvitation(): Result<Unit>
98+
suspend fun join(): Result<Unit>
10199

102100
suspend fun inviteUserById(id: UserId): Result<Unit>
103101

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ interface SyncService {
2222
/**
2323
* Tries to start the sync. If already syncing it has no effect.
2424
*/
25-
fun startSync(): Result<Unit>
25+
suspend fun startSync(): Result<Unit>
2626

2727
/**
2828
* Tries to stop the sync. If service is not syncing it has no effect.

libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/RustMatrixClient.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ import java.io.File
7373
import org.matrix.rustcomponents.sdk.CreateRoomParameters as RustCreateRoomParameters
7474
import org.matrix.rustcomponents.sdk.RoomPreset as RustRoomPreset
7575
import org.matrix.rustcomponents.sdk.RoomVisibility as RustRoomVisibility
76+
import org.matrix.rustcomponents.sdk.SyncService as ClientSyncService
7677

7778
@OptIn(ExperimentalCoroutinesApi::class)
7879
class RustMatrixClient constructor(
7980
private val client: Client,
81+
private val syncService: ClientSyncService,
8082
private val sessionStore: SessionStore,
8183
appCoroutineScope: CoroutineScope,
8284
private val dispatchers: CoroutineDispatchers,
@@ -86,14 +88,11 @@ class RustMatrixClient constructor(
8688
) : MatrixClient {
8789

8890
override val sessionId: UserId = UserId(client.userId())
89-
private val app = client.app().use { builder ->
90-
builder.finish()
91-
}
92-
private val roomListService = app.roomListService()
91+
private val roomListService = syncService.roomListService()
9392
private val sessionDispatcher = dispatchers.io.limitedParallelism(64)
9493
private val sessionCoroutineScope = appCoroutineScope.childScope(dispatchers.main, "Session-${sessionId}")
9594
private val verificationService = RustSessionVerificationService()
96-
private val syncService = RustSyncService(app, roomListService.stateFlow(), sessionCoroutineScope)
95+
private val rustSyncService = RustSyncService(syncService, roomListService.stateFlow(), sessionCoroutineScope)
9796
private val pushersService = RustPushersService(
9897
client = client,
9998
dispatchers = dispatchers,
@@ -131,7 +130,7 @@ class RustMatrixClient constructor(
131130

132131
init {
133132
client.setDelegate(clientDelegate)
134-
syncService.syncState
133+
rustSyncService.syncState
135134
.onEach { syncState ->
136135
if (syncState == SyncState.Syncing) {
137136
onSlidingSyncUpdate()
@@ -247,7 +246,7 @@ class RustMatrixClient constructor(
247246
}
248247
}
249248

250-
override fun syncService(): SyncService = syncService
249+
override fun syncService(): SyncService = rustSyncService
251250

252251
override fun sessionVerificationService(): SessionVerificationService = verificationService
253252

@@ -259,7 +258,7 @@ class RustMatrixClient constructor(
259258
sessionCoroutineScope.cancel()
260259
client.setDelegate(null)
261260
verificationService.destroy()
262-
app.destroy()
261+
syncService.destroy()
263262
roomListService.destroy()
264263
notificationClient.destroy()
265264
client.destroy()

libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/RustMatrixAuthenticationService.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,11 @@ class RustMatrixAuthenticationService @Inject constructor(
181181
*/
182182
}
183183

184-
private fun createMatrixClient(client: Client): MatrixClient {
184+
private suspend fun createMatrixClient(client: Client): MatrixClient {
185+
val syncService = client.syncService().finish()
185186
return RustMatrixClient(
186187
client = client,
188+
syncService = syncService,
187189
sessionStore = sessionStore,
188190
appCoroutineScope = appCoroutineScope,
189191
dispatchers = coroutineDispatchers,

libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RustMatrixRoom.kt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import io.element.android.libraries.matrix.impl.timeline.RustMatrixTimeline
4343
import io.element.android.libraries.matrix.impl.timeline.backPaginationStatusFlow
4444
import io.element.android.libraries.matrix.impl.timeline.timelineDiffFlow
4545
import io.element.android.libraries.sessionstorage.api.SessionData
46-
import io.element.android.libraries.sessionstorage.api.SessionStore
4746
import io.element.android.services.toolbox.api.systemclock.SystemClock
4847
import kotlinx.coroutines.CoroutineScope
4948
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -82,6 +81,7 @@ class RustMatrixRoom(
8281

8382
// Create a dispatcher for all room methods...
8483
private val roomDispatcher = coroutineDispatchers.io.limitedParallelism(32)
84+
8585
//...except getMember methods as it could quickly fill the roomDispatcher...
8686
private val roomMembersDispatcher = coroutineDispatchers.io.limitedParallelism(8)
8787

@@ -257,15 +257,9 @@ class RustMatrixRoom(
257257
}
258258
}
259259

260-
override suspend fun acceptInvitation(): Result<Unit> = withContext(roomDispatcher) {
261-
runCatching {
262-
innerRoom.acceptInvitation()
263-
}
264-
}
265-
266-
override suspend fun rejectInvitation(): Result<Unit> = withContext(roomDispatcher) {
260+
override suspend fun join(): Result<Unit> = withContext(roomDispatcher) {
267261
runCatching {
268-
innerRoom.rejectInvitation()
262+
innerRoom.join()
269263
}
270264
}
271265

libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/sync/AppStateMapper.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
package io.element.android.libraries.matrix.impl.sync
1818

1919
import io.element.android.libraries.matrix.api.sync.SyncState
20-
import org.matrix.rustcomponents.sdk.AppState
2120
import org.matrix.rustcomponents.sdk.RoomListServiceState
21+
import org.matrix.rustcomponents.sdk.SyncServiceState
2222

2323
internal fun RoomListServiceState.toSyncState(): SyncState {
2424
return when (this) {
@@ -30,10 +30,11 @@ internal fun RoomListServiceState.toSyncState(): SyncState {
3030
}
3131
}
3232

33-
internal fun AppState.toSyncState(): SyncState {
33+
internal fun SyncServiceState.toSyncState(): SyncState {
3434
return when (this) {
35-
AppState.RUNNING -> SyncState.Syncing
36-
AppState.TERMINATED -> SyncState.Terminated
37-
AppState.ERROR -> SyncState.InError
35+
SyncServiceState.IDLE -> SyncState.Idle
36+
SyncServiceState.RUNNING -> SyncState.Syncing
37+
SyncServiceState.TERMINATED -> SyncState.Terminated
38+
SyncServiceState.ERROR -> SyncState.InError
3839
}
3940
}

0 commit comments

Comments
 (0)