Change a room's permissions power levels (#2525)

* Change a room's permissions power levels

* Make `currentPermissions` use a `MatrixRoomPowerLevels?` instance instead.

* Update strings

* Update screenshots

---------

Co-authored-by: ElementBot <benoitm+elementbot@element.io>
This commit is contained in:
Jorge Martin Espinosa 2024-03-12 15:45:06 +01:00 committed by GitHub
parent 3453738344
commit 59a682b407
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
71 changed files with 1556 additions and 58 deletions

View file

@ -39,6 +39,7 @@ import io.element.android.libraries.matrix.api.room.MessageEventType
import io.element.android.libraries.matrix.api.room.RoomMember
import io.element.android.libraries.matrix.api.room.StateEventType
import io.element.android.libraries.matrix.api.room.location.AssetType
import io.element.android.libraries.matrix.api.room.powerlevels.MatrixRoomPowerLevels
import io.element.android.libraries.matrix.api.room.powerlevels.UserRoleChange
import io.element.android.libraries.matrix.api.room.roomNotificationSettings
import io.element.android.libraries.matrix.api.timeline.MatrixTimeline
@ -54,6 +55,7 @@ import io.element.android.libraries.matrix.impl.poll.toInner
import io.element.android.libraries.matrix.impl.room.location.toInner
import io.element.android.libraries.matrix.impl.room.member.RoomMemberListFetcher
import io.element.android.libraries.matrix.impl.room.member.RoomMemberMapper
import io.element.android.libraries.matrix.impl.room.powerlevels.RoomPowerLevelsMapper
import io.element.android.libraries.matrix.impl.timeline.RustMatrixTimeline
import io.element.android.libraries.matrix.impl.timeline.toRustReceiptType
import io.element.android.libraries.matrix.impl.util.mxCallbackFlow
@ -86,6 +88,7 @@ import org.matrix.rustcomponents.sdk.messageEventContentFromHtml
import org.matrix.rustcomponents.sdk.messageEventContentFromMarkdown
import org.matrix.rustcomponents.sdk.use
import timber.log.Timber
import uniffi.matrix_sdk.RoomPowerLevelChanges
import java.io.File
import org.matrix.rustcomponents.sdk.Room as InnerRoom
import org.matrix.rustcomponents.sdk.Timeline as InnerTimeline
@ -253,6 +256,34 @@ class RustMatrixRoom(
}
}
override suspend fun powerLevels(): Result<MatrixRoomPowerLevels> = withContext(roomDispatcher) {
runCatching {
RoomPowerLevelsMapper.map(innerRoom.getPowerLevels())
}
}
override suspend fun updatePowerLevels(matrixRoomPowerLevels: MatrixRoomPowerLevels): Result<Unit> = withContext(roomDispatcher) {
runCatching {
val changes = RoomPowerLevelChanges(
ban = matrixRoomPowerLevels.ban,
invite = matrixRoomPowerLevels.invite,
kick = matrixRoomPowerLevels.kick,
redact = matrixRoomPowerLevels.redactEvents,
eventsDefault = matrixRoomPowerLevels.sendEvents,
roomName = matrixRoomPowerLevels.roomName,
roomAvatar = matrixRoomPowerLevels.roomAvatar,
roomTopic = matrixRoomPowerLevels.roomTopic,
)
innerRoom.applyPowerLevelChanges(changes)
}
}
override suspend fun resetPowerLevels(): Result<MatrixRoomPowerLevels> = withContext(roomDispatcher) {
runCatching {
RoomPowerLevelsMapper.map(innerRoom.resetPowerLevels())
}
}
override suspend fun userAvatarUrl(userId: UserId): Result<String?> = withContext(roomDispatcher) {
runCatching {
innerRoom.memberAvatarUrl(userId.value)

View file

@ -0,0 +1,35 @@
/*
* Copyright (c) 2024 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.libraries.matrix.impl.room.powerlevels
import io.element.android.libraries.matrix.api.room.powerlevels.MatrixRoomPowerLevels
import org.matrix.rustcomponents.sdk.RoomPowerLevels as RustRoomPowerLevels
object RoomPowerLevelsMapper {
fun map(roomPowerLevels: RustRoomPowerLevels): MatrixRoomPowerLevels {
return MatrixRoomPowerLevels(
ban = roomPowerLevels.ban,
invite = roomPowerLevels.invite,
kick = roomPowerLevels.kick,
sendEvents = roomPowerLevels.eventsDefault,
redactEvents = roomPowerLevels.redact,
roomName = roomPowerLevels.roomName,
roomAvatar = roomPowerLevels.roomAvatar,
roomTopic = roomPowerLevels.roomTopic
)
}
}

View file

@ -163,7 +163,7 @@ private fun RustOtherState.map(): OtherState {
RustOtherState.RoomJoinRules -> OtherState.RoomJoinRules
is RustOtherState.RoomName -> OtherState.RoomName(name)
RustOtherState.RoomPinnedEvents -> OtherState.RoomPinnedEvents
is RustOtherState.RoomPowerLevels -> OtherState.RoomPowerLevels(users)
is RustOtherState.RoomPowerLevels -> OtherState.RoomUserPowerLevels(users)
RustOtherState.RoomServerAcl -> OtherState.RoomServerAcl
is RustOtherState.RoomThirdPartyInvite -> OtherState.RoomThirdPartyInvite(displayName)
RustOtherState.RoomTombstone -> OtherState.RoomTombstone