Merge pull request #566 from vector-im/feature/fga/update-rust-sdk-0.1.16

Feature/fga/update rust sdk 0.1.16
This commit is contained in:
ganfra 2023-06-09 17:26:11 +02:00 committed by GitHub
commit 511b26b2ab
16 changed files with 251 additions and 666 deletions

View file

@ -40,32 +40,32 @@ interface SessionVerificationService {
/**
* Request verification of the current session.
*/
fun requestVerification()
suspend fun requestVerification()
/**
* Cancels the current verification attempt.
*/
fun cancelVerification()
suspend fun cancelVerification()
/**
* Approves the current verification. This must happen on both devices to successfully verify a session.
*/
fun approveVerification()
suspend fun approveVerification()
/**
* Declines the verification attempt because the user could not verify or does not trust the other side of the verification.
*/
fun declineVerification()
suspend fun declineVerification()
/**
* Starts the verification of the unverified session from another device.
*/
fun startVerification()
suspend fun startVerification()
/**
* Returns the verification service state to the initial step.
*/
fun reset()
suspend fun reset()
}
/** Verification status of the current session. */

View file

@ -64,6 +64,7 @@ import org.matrix.rustcomponents.sdk.SlidingSyncList
import org.matrix.rustcomponents.sdk.SlidingSyncListBuilder
import org.matrix.rustcomponents.sdk.SlidingSyncListOnceBuilt
import org.matrix.rustcomponents.sdk.SlidingSyncRequestListFilters
import org.matrix.rustcomponents.sdk.SlidingSyncSelectiveModeBuilder
import org.matrix.rustcomponents.sdk.TaskHandle
import org.matrix.rustcomponents.sdk.use
import timber.log.Timber
@ -124,8 +125,7 @@ class RustMatrixClient constructor(
)
)
.filters(visibleRoomsSlidingSyncFilters)
.syncModeSelective()
.addRange(0u, 20u)
.syncModeSelective(SlidingSyncSelectiveModeBuilder().addRange(0u, 20u))
.onceBuilt(object : SlidingSyncListOnceBuilt {
override fun updateList(list: SlidingSyncList): SlidingSyncList {
visibleRoomsSlidingSyncList.tryEmit(list)
@ -146,8 +146,7 @@ class RustMatrixClient constructor(
)
)
.filters(invitesSlidingSyncFilters)
.syncModeSelective()
.addRange(0u, 20u)
.syncModeSelective(SlidingSyncSelectiveModeBuilder().addRange(0u, 20u))
.onceBuilt(object : SlidingSyncListOnceBuilt {
override fun updateList(list: SlidingSyncList): SlidingSyncList {
invitesSlidingSyncList.tryEmit(list)
@ -156,10 +155,9 @@ class RustMatrixClient constructor(
})
private val slidingSync = client
.slidingSync()
.slidingSync("ElementX")
// .homeserver("https://slidingsync.lab.matrix.org")
.withCommonExtensions()
.storageKey("ElementX")
.addList(visibleRoomsSlidingSyncListBuilder)
.addList(invitesSlidingSyncListBuilder)
.use {

View file

@ -75,8 +75,7 @@ class RustMediaLoader(
mediaSource = mediaSource,
body = body,
mimeType = mimeType ?: "application/octet-stream",
//TODO uncomment when rust api will be merged
//tempDir = cacheDirectory.path,
tempDir = cacheDirectory.path,
)
RustMediaFile(mediaFile)
}

View file

@ -38,6 +38,7 @@ import org.matrix.rustcomponents.sdk.RoomListEntry
import org.matrix.rustcomponents.sdk.SlidingSync
import org.matrix.rustcomponents.sdk.SlidingSyncList
import org.matrix.rustcomponents.sdk.SlidingSyncListRoomsListDiff
import org.matrix.rustcomponents.sdk.SlidingSyncSelectiveModeBuilder
import org.matrix.rustcomponents.sdk.SlidingSyncState
import org.matrix.rustcomponents.sdk.UpdateSummary
import timber.log.Timber
@ -98,7 +99,9 @@ internal class RustRoomSummaryDataSource(
override fun setSlidingSyncRange(range: IntRange) {
Timber.v("setVisibleRange=$range")
coroutineScope.launch {
slidingSyncListFlow.first().setRange(range.first.toUInt(), range.last.toUInt())
val slidingSyncMode = SlidingSyncSelectiveModeBuilder()
.addRange(range.first.toUInt(), range.last.toUInt())
slidingSyncListFlow.first().setSyncMode(slidingSyncMode)
}
}

View file

@ -159,7 +159,7 @@ class RustMatrixTimeline(
),
timelineLimit = null
)
listenerTokens += slidingSyncRoom.subscribeToRoom(settings)
slidingSyncRoom.subscribeToRoom(settings)
val result = slidingSyncRoom.addTimelineListener(timelineListener)
launch {
fetchMembers()

View file

@ -18,9 +18,9 @@ package io.element.android.libraries.matrix.impl.verification
import io.element.android.libraries.core.data.tryOrNull
import io.element.android.libraries.matrix.api.verification.SessionVerificationService
import io.element.android.libraries.matrix.api.verification.VerificationFlowState
import io.element.android.libraries.matrix.api.verification.SessionVerifiedStatus
import io.element.android.libraries.matrix.api.verification.VerificationEmoji
import io.element.android.libraries.matrix.api.verification.VerificationFlowState
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
@ -52,21 +52,21 @@ class RustSessionVerificationService @Inject constructor() : SessionVerification
private val _sessionVerifiedStatus = MutableStateFlow<SessionVerifiedStatus>(SessionVerifiedStatus.Unknown)
override val sessionVerifiedStatus: StateFlow<SessionVerifiedStatus> = _sessionVerifiedStatus.asStateFlow()
override fun requestVerification() = tryOrFail {
override suspend fun requestVerification() = tryOrFail {
verificationController?.requestVerification()
}
override fun cancelVerification() = tryOrFail { verificationController?.cancelVerification() }
override suspend fun cancelVerification() = tryOrFail { verificationController?.cancelVerification() }
override fun approveVerification() = tryOrFail { verificationController?.approveVerification() }
override suspend fun approveVerification() = tryOrFail { verificationController?.approveVerification() }
override fun declineVerification() = tryOrFail { verificationController?.declineVerification() }
override suspend fun declineVerification() = tryOrFail { verificationController?.declineVerification() }
override fun startVerification() = tryOrFail {
override suspend fun startVerification() = tryOrFail {
verificationController?.startSasVerification()
}
private fun tryOrFail(block: () -> Unit) {
private suspend fun tryOrFail(block: suspend () -> Unit) {
runCatching {
block()
}.onFailure { didFail() }
@ -107,7 +107,7 @@ class RustSessionVerificationService @Inject constructor() : SessionVerification
// end-region
override fun reset() {
override suspend fun reset() {
if (isReady.value) {
// Cancel any pending verification attempt
tryOrNull { verificationController?.cancelVerification() }

View file

@ -37,17 +37,15 @@ class FakeSessionVerificationService : SessionVerificationService {
override val isReady: StateFlow<Boolean> = _isReady
override fun requestVerification() {
override suspend fun requestVerification() {
_verificationFlowState.value = VerificationFlowState.AcceptedVerificationRequest
_verificationFlowState.value = VerificationFlowState.StartedSasVerification
_verificationFlowState.value = VerificationFlowState.ReceivedVerificationData(emojiList)
}
override fun cancelVerification() {
override suspend fun cancelVerification() {
_verificationFlowState.value = VerificationFlowState.Canceled
}
override fun approveVerification() {
override suspend fun approveVerification() {
if (!shouldFail) {
_verificationFlowState.value = VerificationFlowState.Finished
} else {
@ -55,7 +53,7 @@ class FakeSessionVerificationService : SessionVerificationService {
}
}
override fun declineVerification() {
override suspend fun declineVerification() {
if (!shouldFail) {
_verificationFlowState.value = VerificationFlowState.Canceled
} else {
@ -63,11 +61,14 @@ class FakeSessionVerificationService : SessionVerificationService {
}
}
override fun startVerification() {
_verificationFlowState.value = VerificationFlowState.StartedSasVerification
fun triggerReceiveVerificationData() {
_verificationFlowState.value = VerificationFlowState.ReceivedVerificationData(emojiList)
}
override suspend fun startVerification() {
_verificationFlowState.value = VerificationFlowState.StartedSasVerification
}
fun givenVerifiedStatus(status: SessionVerifiedStatus) {
_sessionVerifiedStatus.value = status
}
@ -84,7 +85,7 @@ class FakeSessionVerificationService : SessionVerificationService {
this.emojiList = emojis
}
override fun reset() {
override suspend fun reset() {
_verificationFlowState.value = VerificationFlowState.Initial
}
}