Merge branch 'develop' into feature/fga/safer_callback_flows

This commit is contained in:
ganfra 2023-07-31 11:36:59 +02:00
commit 13209b0aa0
122 changed files with 682 additions and 267 deletions

View file

@ -95,9 +95,9 @@ object PermalinkParser {
return if (signUrl.isNullOrEmpty().not() && email.isNullOrEmpty().not()) {
try {
val signValidUri = Uri.parse(signUrl)
val identityServerHost = signValidUri.authority ?: throw IllegalArgumentException()
val token = signValidUri.getQueryParameter("token") ?: throw IllegalArgumentException()
val privateKey = signValidUri.getQueryParameter("private_key") ?: throw IllegalArgumentException()
val identityServerHost = signValidUri.authority ?: throw IllegalArgumentException("missing `authority`")
val token = signValidUri.getQueryParameter("token") ?: throw IllegalArgumentException("missing `token`")
val privateKey = signValidUri.getQueryParameter("private_key") ?: throw IllegalArgumentException("missing `private_key`")
PermalinkData.RoomEmailInviteLink(
roomId = identifier,
email = email!!,
@ -137,7 +137,8 @@ object PermalinkParser {
.parameterList
.filter {
it.mParameter == "via"
}.map {
}
.map {
URLDecoder.decode(it.mValue, "UTF-8")
}
}

View file

@ -105,6 +105,8 @@ interface MatrixRoom : Closeable {
suspend fun canUserInvite(userId: UserId): Result<Boolean>
suspend fun canUserRedact(userId: UserId): Result<Boolean>
suspend fun canUserSendState(userId: UserId, type: StateEventType): Result<Boolean>
suspend fun canUserSendMessage(userId: UserId, type: MessageEventType): Result<Boolean>

View file

@ -34,3 +34,9 @@ suspend fun MatrixRoom.canSendState(type: StateEventType): Result<Boolean> = can
* Shortcut for calling [MatrixRoom.canUserSendMessage] with our own user.
*/
suspend fun MatrixRoom.canSendMessage(type: MessageEventType): Result<Boolean> = canUserSendMessage(sessionId, type)
/**
* Shortcut for calling [MatrixRoom.canUserRedact] with our own user.
*/
suspend fun MatrixRoom.canRedact(): Result<Boolean> = canUserRedact(sessionId)

View file

@ -147,7 +147,8 @@ class RustMatrixClient constructor(
if (syncState == SyncState.Running) {
onSlidingSyncUpdate()
}
}.launchIn(sessionCoroutineScope)
}
.launchIn(sessionCoroutineScope)
}
override suspend fun getRoom(roomId: RoomId): MatrixRoom? = withContext(sessionDispatcher) {
@ -227,7 +228,8 @@ class RustMatrixClient constructor(
roomSummaryDataSource.allRooms()
.filter { roomSummaries ->
roomSummaries.map { it.identifier() }.contains(roomId.value)
}.first()
}
.first()
}
roomId
}

View file

@ -93,7 +93,7 @@ class RustMatrixAuthenticationService @Inject constructor(
client.restoreSession(sessionData.toSession())
createMatrixClient(client)
} else {
throw IllegalStateException("No session to restore with id $sessionId")
error("No session to restore with id $sessionId")
}
}.mapFailure { failure ->
failure.mapClientException()

View file

@ -250,6 +250,12 @@ class RustMatrixRoom(
}
}
override suspend fun canUserRedact(userId: UserId): Result<Boolean> {
return runCatching {
innerRoom.canUserRedact(userId.value)
}
}
override suspend fun canUserSendState(userId: UserId, type: StateEventType): Result<Boolean> {
return runCatching {
innerRoom.canUserSendState(userId.value, type.map())

View file

@ -64,7 +64,8 @@ internal class RustRoomSummaryDataSource(
.map { it.toRoomSummaryDataSourceLoadingState() }
.onEach {
allRoomsLoadingState.value = it
}.launchIn(this)
}
.launchIn(this)
launch {
// Wait until running, as invites is only available after that

View file

@ -118,7 +118,8 @@ class RustMatrixTimeline(
innerRoom.backPaginationStatusFlow()
.onEach {
postPaginationStatus(it)
}.launchIn(this)
}
.launchIn(this)
taskHandleBag += fetchMembers().getOrNull()
}.invokeOnCompletion {

View file

@ -27,7 +27,7 @@ import java.util.Date
class TimelineEncryptedHistoryPostProcessorTest {
private val defaultLastLoginTimestamp = Date(1689061264L)
private val defaultLastLoginTimestamp = Date(1_689_061_264L)
@Test
fun `given an unencrypted room, nothing is done`() {

View file

@ -56,6 +56,7 @@ class FakeMatrixRoom(
override val joinedMemberCount: Long = 123L,
override val activeMemberCount: Long = 234L,
private val matrixTimeline: MatrixTimeline = FakeMatrixTimeline(),
canRedact: Boolean = false,
) : MatrixRoom {
private var ignoreResult: Result<Unit> = Result.success(Unit)
@ -66,6 +67,7 @@ class FakeMatrixRoom(
private var joinRoomResult = Result.success(Unit)
private var inviteUserResult = Result.success(Unit)
private var canInviteResult = Result.success(true)
private var canRedactResult = Result.success(canRedact)
private val canSendStateResults = mutableMapOf<StateEventType, Result<Boolean>>()
private val canSendEventResults = mutableMapOf<MessageEventType, Result<Boolean>>()
private var sendMediaResult = Result.success(Unit)
@ -207,6 +209,10 @@ class FakeMatrixRoom(
return canInviteResult
}
override suspend fun canUserRedact(userId: UserId): Result<Boolean> {
return canRedactResult
}
override suspend fun canUserSendState(userId: UserId, type: StateEventType): Result<Boolean> {
return canSendStateResults[type] ?: Result.failure(IllegalStateException("No fake answer"))
}