mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Adopt the lastest SDK APIs and refactor how we deal with user permissions.
This patch introduces a new RoomPowerLevelsProxy and its associated mock and adopts newer Rust APIs to make working with user power levels and permissions easier.
This commit is contained in:
committed by
Stefan Ceriu
parent
96e5ed06f5
commit
f522e15dac
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -89,9 +89,8 @@ extension JoinedRoomProxyMock {
|
||||
markAsReadReceiptTypeReturnValue = .success(())
|
||||
flagAsFavouriteReturnValue = .success(())
|
||||
|
||||
powerLevelsReturnValue = .success(.mock)
|
||||
applyPowerLevelChangesReturnValue = .success(())
|
||||
resetPowerLevelsReturnValue = .success(.mock)
|
||||
resetPowerLevelsReturnValue = .success(())
|
||||
suggestedRoleForClosure = { [weak self] userID in
|
||||
guard case .success(let member) = await self?.getMember(userID: userID) else {
|
||||
return .failure(.sdkError(RoomProxyMockError.generic))
|
||||
@@ -99,22 +98,27 @@ extension JoinedRoomProxyMock {
|
||||
return .success(member.role)
|
||||
}
|
||||
updatePowerLevelsForUsersReturnValue = .success(())
|
||||
canUserUserIDSendMessageReturnValue = .success(configuration.canUserSendMessage)
|
||||
canUserUserIDSendStateEventClosure = { [weak self] userID, _ in
|
||||
|
||||
let powerLevelsProxyMock = RoomPowerLevelsProxyMock(configuration: .init())
|
||||
|
||||
powerLevelsProxyMock.canUserUserIDSendMessageReturnValue = .success(configuration.canUserSendMessage)
|
||||
powerLevelsProxyMock.canUserUserIDSendStateEventClosure = { [weak self] userID, _ in
|
||||
.success(self?.membersPublisher.value.first { $0.userID == userID }?.role ?? .user != .user)
|
||||
}
|
||||
canUserInviteUserIDReturnValue = .success(configuration.canUserInvite)
|
||||
canUserRedactOtherUserIDReturnValue = .success(false)
|
||||
canUserRedactOwnUserIDReturnValue = .success(true)
|
||||
canUserKickUserIDClosure = { [weak self] userID in
|
||||
powerLevelsProxyMock.canUserInviteUserIDReturnValue = .success(configuration.canUserInvite)
|
||||
powerLevelsProxyMock.canUserRedactOtherUserIDReturnValue = .success(false)
|
||||
powerLevelsProxyMock.canUserRedactOwnUserIDReturnValue = .success(true)
|
||||
powerLevelsProxyMock.canUserKickUserIDClosure = { [weak self] userID in
|
||||
.success(self?.membersPublisher.value.first { $0.userID == userID }?.role ?? .user != .user)
|
||||
}
|
||||
canUserBanUserIDClosure = { [weak self] userID in
|
||||
powerLevelsProxyMock.canUserBanUserIDClosure = { [weak self] userID in
|
||||
.success(self?.membersPublisher.value.first { $0.userID == userID }?.role ?? .user != .user)
|
||||
}
|
||||
canUserTriggerRoomNotificationUserIDReturnValue = .success(configuration.canUserTriggerRoomNotification)
|
||||
canUserJoinCallUserIDReturnValue = .success(configuration.canUserJoinCall)
|
||||
canUserPinOrUnpinUserIDReturnValue = .success(configuration.canUserPin)
|
||||
powerLevelsProxyMock.canUserTriggerRoomNotificationUserIDReturnValue = .success(configuration.canUserTriggerRoomNotification)
|
||||
powerLevelsProxyMock.canUserJoinCallUserIDReturnValue = .success(configuration.canUserJoinCall)
|
||||
powerLevelsProxyMock.canUserPinOrUnpinUserIDReturnValue = .success(configuration.canUserPin)
|
||||
|
||||
powerLevelsReturnValue = .success(powerLevelsProxyMock)
|
||||
|
||||
kickUserReasonReturnValue = .success(())
|
||||
banUserReasonReturnValue = .success(())
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// Copyright 2025 New Vector Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import MatrixRustSDK
|
||||
|
||||
extension RoomPowerLevelsProxyMock {
|
||||
struct Configuration { }
|
||||
|
||||
convenience init(configuration: Configuration) {
|
||||
self.init()
|
||||
|
||||
underlyingValues = RoomPowerLevelsValues.mock
|
||||
|
||||
canUserUserIDSendMessageReturnValue = .success(true)
|
||||
canUserUserIDSendStateEventReturnValue = .success(true)
|
||||
canUserInviteUserIDReturnValue = .success(true)
|
||||
canUserRedactOtherUserIDReturnValue = .success(true)
|
||||
canUserRedactOwnUserIDReturnValue = .success(true)
|
||||
canUserKickUserIDReturnValue = .success(true)
|
||||
canUserBanUserIDReturnValue = .success(true)
|
||||
canUserTriggerRoomNotificationUserIDReturnValue = .success(true)
|
||||
canUserPinOrUnpinUserIDReturnValue = .success(true)
|
||||
canUserJoinCallUserIDReturnValue = .success(true)
|
||||
}
|
||||
}
|
||||
|
||||
extension RoomPowerLevelsValues {
|
||||
static var mock: RoomPowerLevelsValues {
|
||||
RoomPowerLevelsValues(ban: 50,
|
||||
invite: 0,
|
||||
kick: 50,
|
||||
redact: 50,
|
||||
eventsDefault: 0,
|
||||
stateDefault: 50,
|
||||
usersDefault: 0,
|
||||
roomName: 50,
|
||||
roomAvatar: 50,
|
||||
roomTopic: 50)
|
||||
}
|
||||
}
|
||||
+4
-3
@@ -224,9 +224,10 @@ class KnockRequestsListScreenViewModel: KnockRequestsListScreenViewModelType, Kn
|
||||
}
|
||||
|
||||
private func updatePermissions() async {
|
||||
state.canAccept = await (try? roomProxy.canUserInvite(userID: roomProxy.ownUserID).get()) == true
|
||||
state.canDecline = await (try? roomProxy.canUserKick(userID: roomProxy.ownUserID).get()) == true
|
||||
state.canBan = await (try? roomProxy.canUserBan(userID: roomProxy.ownUserID).get()) == true
|
||||
let powerLevels = try? await roomProxy.powerLevels().get()
|
||||
state.canAccept = (try? powerLevels?.canUserInvite(userID: roomProxy.ownUserID).get()) == true
|
||||
state.canDecline = (try? powerLevels?.canUserKick(userID: roomProxy.ownUserID).get()) == true
|
||||
state.canBan = (try? powerLevels?.canUserBan(userID: roomProxy.ownUserID).get()) == true
|
||||
}
|
||||
|
||||
private static let loadingIndicatorIdentifier = "\(KnockRequestsListScreenViewModel.self)-Loading"
|
||||
|
||||
@@ -40,10 +40,10 @@ class RoomDetailsEditScreenViewModel: RoomDetailsEditScreenViewModelType, RoomDe
|
||||
bindings: .init(name: roomName ?? "", topic: roomTopic ?? "")), mediaProvider: mediaProvider)
|
||||
|
||||
Task {
|
||||
// Can't use async let because the mocks aren't thread safe when calling the same method 🤦♂️
|
||||
state.canEditAvatar = await (try? roomProxy.canUser(userID: roomProxy.ownUserID, sendStateEvent: .roomAvatar).get()) == .some(true)
|
||||
state.canEditName = await (try? roomProxy.canUser(userID: roomProxy.ownUserID, sendStateEvent: .roomName).get()) == .some(true)
|
||||
state.canEditTopic = await (try? roomProxy.canUser(userID: roomProxy.ownUserID, sendStateEvent: .roomTopic).get()) == .some(true)
|
||||
let powerLevels = try? await roomProxy.powerLevels().get()
|
||||
state.canEditAvatar = (try? powerLevels?.canUser(userID: roomProxy.ownUserID, sendStateEvent: .roomAvatar).get()) == .some(true)
|
||||
state.canEditName = (try? powerLevels?.canUser(userID: roomProxy.ownUserID, sendStateEvent: .roomName).get()) == .some(true)
|
||||
state.canEditTopic = (try? powerLevels?.canUser(userID: roomProxy.ownUserID, sendStateEvent: .roomTopic).get()) == .some(true)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -90,13 +90,6 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
Task {
|
||||
let userID = roomProxy.ownUserID
|
||||
if case let .success(permission) = await roomProxy.canUserJoinCall(userID: userID) {
|
||||
state.canJoinCall = permission
|
||||
}
|
||||
}
|
||||
|
||||
Task {
|
||||
if case let .success(permalinkURL) = await roomProxy.matrixToPermalink() {
|
||||
state.permalink = permalinkURL
|
||||
@@ -288,13 +281,16 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
|
||||
}
|
||||
|
||||
private func updatePowerLevelPermissions() async {
|
||||
state.canEditRoomName = await (try? roomProxy.canUser(userID: roomProxy.ownUserID, sendStateEvent: .roomName).get()) == true
|
||||
state.canEditRoomTopic = await (try? roomProxy.canUser(userID: roomProxy.ownUserID, sendStateEvent: .roomTopic).get()) == true
|
||||
state.canEditRoomAvatar = await (try? roomProxy.canUser(userID: roomProxy.ownUserID, sendStateEvent: .roomAvatar).get()) == true
|
||||
state.canEditRolesOrPermissions = await (try? roomProxy.suggestedRole(for: roomProxy.ownUserID).get()) == .administrator
|
||||
state.canInviteUsers = await (try? roomProxy.canUserInvite(userID: roomProxy.ownUserID).get()) == true
|
||||
state.canKickUsers = await (try? roomProxy.canUserKick(userID: roomProxy.ownUserID).get()) == true
|
||||
state.canBanUsers = await (try? roomProxy.canUserBan(userID: roomProxy.ownUserID).get()) == true
|
||||
|
||||
let powerLevels = try? await roomProxy.powerLevels().get()
|
||||
state.canEditRoomName = (try? powerLevels?.canUser(userID: roomProxy.ownUserID, sendStateEvent: .roomName).get()) == true
|
||||
state.canEditRoomTopic = (try? powerLevels?.canUser(userID: roomProxy.ownUserID, sendStateEvent: .roomTopic).get()) == true
|
||||
state.canEditRoomAvatar = (try? powerLevels?.canUser(userID: roomProxy.ownUserID, sendStateEvent: .roomAvatar).get()) == true
|
||||
state.canInviteUsers = (try? powerLevels?.canUserInvite(userID: roomProxy.ownUserID).get()) == true
|
||||
state.canKickUsers = (try? powerLevels?.canUserKick(userID: roomProxy.ownUserID).get()) == true
|
||||
state.canBanUsers = (try? powerLevels?.canUserBan(userID: roomProxy.ownUserID).get()) == true
|
||||
state.canJoinCall = (try? powerLevels?.canUserJoinCall(userID: roomProxy.ownUserID).get()) == true
|
||||
}
|
||||
|
||||
private func setupNotificationSettingsSubscription() {
|
||||
|
||||
@@ -99,10 +99,11 @@ class RoomMembersListScreenViewModel: RoomMembersListScreenViewModelType, RoomMe
|
||||
bannedMembers: roomMembersDetails.bannedMembers,
|
||||
bindings: state.bindings)
|
||||
|
||||
self.state.canInviteUsers = await (try? roomProxy.canUserInvite(userID: roomProxy.ownUserID).get()) == true
|
||||
self.state.canKickUsers = await (try? roomProxy.canUserKick(userID: roomProxy.ownUserID).get()) == true
|
||||
self.state.canBanUsers = await (try? roomProxy.canUserBan(userID: roomProxy.ownUserID).get()) == true
|
||||
|
||||
let powerLevels = try? await roomProxy.powerLevels().get()
|
||||
self.state.canInviteUsers = (try? powerLevels?.canUserInvite(userID: roomProxy.ownUserID).get()) == true
|
||||
self.state.canKickUsers = (try? powerLevels?.canUserKick(userID: roomProxy.ownUserID).get()) == true
|
||||
self.state.canBanUsers = (try? powerLevels?.canUserBan(userID: roomProxy.ownUserID).get()) == true
|
||||
|
||||
hideLoadingIndicator(Self.updateStateLoadingIndicatorIdentifier)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -116,7 +116,7 @@ class RoomRolesAndPermissionsScreenViewModel: RoomRolesAndPermissionsScreenViewM
|
||||
private func updatePermissions() async {
|
||||
switch await roomProxy.powerLevels() {
|
||||
case .success(let powerLevels):
|
||||
state.permissions = .init(powerLevels: powerLevels)
|
||||
state.permissions = .init(powerLevels: powerLevels.values)
|
||||
case .failure:
|
||||
break
|
||||
}
|
||||
|
||||
+1
-6
@@ -48,12 +48,7 @@ final class CompletionSuggestionService: CompletionSuggestionServiceProtocol {
|
||||
}
|
||||
|
||||
Task {
|
||||
switch await roomProxy.canUserTriggerRoomNotification(userID: roomProxy.ownUserID) {
|
||||
case .success(let value):
|
||||
canMentionAllUsers = value
|
||||
case .failure:
|
||||
canMentionAllUsers = false
|
||||
}
|
||||
canMentionAllUsers = await (try? roomProxy.powerLevels().get().canUserTriggerRoomNotification(userID: roomProxy.ownUserID).get()) == true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -347,13 +347,13 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
|
||||
default:
|
||||
state.isKnockableRoom = false
|
||||
}
|
||||
|
||||
let ownUserID = roomProxy.ownUserID
|
||||
state.canSendMessage = await (try? roomProxy.canUser(userID: ownUserID, sendMessage: .roomMessage).get()) == true
|
||||
state.canJoinCall = await (try? roomProxy.canUserJoinCall(userID: ownUserID).get()) == true
|
||||
state.canAcceptKnocks = await (try? roomProxy.canUserInvite(userID: ownUserID).get()) == true
|
||||
state.canDeclineKnocks = await (try? roomProxy.canUserKick(userID: ownUserID).get()) == true
|
||||
state.canBan = await (try? roomProxy.canUserBan(userID: ownUserID).get()) == true
|
||||
|
||||
let powerLevels = try? await roomProxy.powerLevels().get()
|
||||
state.canSendMessage = (try? powerLevels?.canUser(userID: roomProxy.ownUserID, sendMessage: .roomMessage).get()) == true
|
||||
state.canJoinCall = (try? powerLevels?.canUserJoinCall(userID: roomProxy.ownUserID).get()) == true
|
||||
state.canAcceptKnocks = (try? powerLevels?.canUserInvite(userID: roomProxy.ownUserID).get()) == true
|
||||
state.canDeclineKnocks = (try? powerLevels?.canUserKick(userID: roomProxy.ownUserID).get()) == true
|
||||
state.canBan = (try? powerLevels?.canUserBan(userID: roomProxy.ownUserID).get()) == true
|
||||
}
|
||||
|
||||
private func setupPinnedEventsTimelineItemProviderIfNeeded() {
|
||||
|
||||
@@ -65,6 +65,6 @@ class ThreadTimelineScreenViewModel: ThreadTimelineScreenViewModelType, ThreadTi
|
||||
// MARK: - Private
|
||||
|
||||
private func handleRoomInfoUpdate(_ roomInfo: RoomInfoProxy) async {
|
||||
state.canSendMessage = await (try? roomProxy.canUser(userID: roomProxy.ownUserID, sendMessage: .roomMessage).get()) == true
|
||||
state.canSendMessage = await (try? roomProxy.powerLevels().get().canUser(userID: roomProxy.ownUserID, sendMessage: .roomMessage).get()) == true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -404,41 +404,13 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol {
|
||||
}
|
||||
|
||||
private func updatePermissions() async {
|
||||
if case let .success(value) = await roomProxy.canUser(userID: roomProxy.ownUserID, sendMessage: .roomMessage) {
|
||||
state.canCurrentUserSendMessage = value
|
||||
} else {
|
||||
state.canCurrentUserSendMessage = false
|
||||
}
|
||||
|
||||
if case let .success(value) = await roomProxy.canUserRedactOther(userID: roomProxy.ownUserID) {
|
||||
state.canCurrentUserRedactOthers = value
|
||||
} else {
|
||||
state.canCurrentUserRedactOthers = false
|
||||
}
|
||||
|
||||
if case let .success(value) = await roomProxy.canUserRedactOwn(userID: roomProxy.ownUserID) {
|
||||
state.canCurrentUserRedactSelf = value
|
||||
} else {
|
||||
state.canCurrentUserRedactSelf = false
|
||||
}
|
||||
|
||||
if case let .success(value) = await roomProxy.canUserPinOrUnpin(userID: roomProxy.ownUserID) {
|
||||
state.canCurrentUserPin = value
|
||||
} else {
|
||||
state.canCurrentUserPin = false
|
||||
}
|
||||
|
||||
if case let .success(value) = await roomProxy.canUserKick(userID: roomProxy.ownUserID) {
|
||||
state.canCurrentUserKick = value
|
||||
} else {
|
||||
state.canCurrentUserKick = false
|
||||
}
|
||||
|
||||
if case let .success(value) = await roomProxy.canUserBan(userID: roomProxy.ownUserID) {
|
||||
state.canCurrentUserBan = value
|
||||
} else {
|
||||
state.canCurrentUserBan = false
|
||||
}
|
||||
let powerLevels = try? await roomProxy.powerLevels().get()
|
||||
state.canCurrentUserSendMessage = (try? powerLevels?.canUser(userID: roomProxy.ownUserID, sendMessage: .roomMessage).get()) == true
|
||||
state.canCurrentUserRedactOthers = (try? powerLevels?.canUserRedactOther(userID: roomProxy.ownUserID).get()) == true
|
||||
state.canCurrentUserRedactSelf = (try? powerLevels?.canUserRedactOwn(userID: roomProxy.ownUserID).get()) == true
|
||||
state.canCurrentUserPin = (try? powerLevels?.canUserPinOrUnpin(userID: roomProxy.ownUserID).get()) == true
|
||||
state.canCurrentUserKick = (try? powerLevels?.canUserKick(userID: roomProxy.ownUserID).get()) == true
|
||||
state.canCurrentUserBan = (try? powerLevels?.canUserBan(userID: roomProxy.ownUserID).get()) == true
|
||||
}
|
||||
|
||||
private func setupSubscriptions() {
|
||||
|
||||
@@ -552,9 +552,9 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol {
|
||||
|
||||
// MARK: - Power Levels
|
||||
|
||||
func powerLevels() async -> Result<RoomPowerLevels, RoomProxyError> {
|
||||
func powerLevels() async -> Result<RoomPowerLevelsProxyProtocol, RoomProxyError> {
|
||||
do {
|
||||
return try await .success(room.getPowerLevels())
|
||||
return try await .success(RoomPowerLevelsProxy(room.getPowerLevels()))
|
||||
} catch {
|
||||
MXLog.error("Failed building the current power level settings: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
@@ -570,9 +570,10 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func resetPowerLevels() async -> Result<RoomPowerLevels, RoomProxyError> {
|
||||
func resetPowerLevels() async -> Result<Void, RoomProxyError> {
|
||||
do {
|
||||
return try await .success(room.resetPowerLevels())
|
||||
_ = try await room.resetPowerLevels()
|
||||
return .success(())
|
||||
} catch {
|
||||
MXLog.error("Failed resetting the power levels: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
@@ -598,87 +599,6 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func canUser(userID: String, sendMessage messageType: MessageLikeEventType) async -> Result<Bool, RoomProxyError> {
|
||||
do {
|
||||
return try await .success(room.canUserSendMessage(userId: userID, message: messageType))
|
||||
} catch {
|
||||
MXLog.error("Failed checking if the user can send message with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
func canUser(userID: String, sendStateEvent event: StateEventType) async -> Result<Bool, RoomProxyError> {
|
||||
do {
|
||||
return try await .success(room.canUserSendState(userId: userID, stateEvent: event))
|
||||
} catch {
|
||||
MXLog.error("Failed checking if the user can send \(event) with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
func canUserInvite(userID: String) async -> Result<Bool, RoomProxyError> {
|
||||
do {
|
||||
return try await .success(room.canUserInvite(userId: userID))
|
||||
} catch {
|
||||
MXLog.error("Failed checking if the user can invite with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
func canUserRedactOther(userID: String) async -> Result<Bool, RoomProxyError> {
|
||||
do {
|
||||
return try await .success(room.canUserRedactOther(userId: userID))
|
||||
} catch {
|
||||
MXLog.error("Failed checking if the user can redact others with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
func canUserRedactOwn(userID: String) async -> Result<Bool, RoomProxyError> {
|
||||
do {
|
||||
return try await .success(room.canUserRedactOwn(userId: userID))
|
||||
} catch {
|
||||
MXLog.error("Failed checking if the user can redact self with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
func canUserKick(userID: String) async -> Result<Bool, RoomProxyError> {
|
||||
do {
|
||||
return try await .success(room.canUserKick(userId: userID))
|
||||
} catch {
|
||||
MXLog.error("Failed checking if the user can kick with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
func canUserBan(userID: String) async -> Result<Bool, RoomProxyError> {
|
||||
do {
|
||||
return try await .success(room.canUserBan(userId: userID))
|
||||
} catch {
|
||||
MXLog.error("Failed checking if the user can ban with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
func canUserTriggerRoomNotification(userID: String) async -> Result<Bool, RoomProxyError> {
|
||||
do {
|
||||
return try await .success(room.canUserTriggerRoomNotification(userId: userID))
|
||||
} catch {
|
||||
MXLog.error("Failed checking if the user can trigger room notification with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
func canUserPinOrUnpin(userID: String) async -> Result<Bool, RoomProxyError> {
|
||||
do {
|
||||
return try await .success(room.canUserPinUnpin(userId: userID))
|
||||
} catch {
|
||||
MXLog.error("Failed checking if the user can pin or unnpin: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Moderation
|
||||
|
||||
func kickUser(_ userID: String, reason: String?) async -> Result<Void, RoomProxyError> {
|
||||
@@ -713,15 +633,6 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol {
|
||||
|
||||
// MARK: - Element Call
|
||||
|
||||
func canUserJoinCall(userID: String) async -> Result<Bool, RoomProxyError> {
|
||||
do {
|
||||
return try await .success(room.canUserSendState(userId: userID, stateEvent: .callMember))
|
||||
} catch {
|
||||
MXLog.error("Failed checking if the user can trigger room notification with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
func elementCallWidgetDriver(deviceID: String) -> ElementCallWidgetDriverProtocol {
|
||||
ElementCallWidgetDriver(room: room, deviceID: deviceID)
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ struct RoomPermissions {
|
||||
|
||||
extension RoomPermissions {
|
||||
/// Create permissions from the room's power levels.
|
||||
init(powerLevels: RoomPowerLevels) {
|
||||
init(powerLevels: RoomPowerLevelsValues) {
|
||||
ban = RoomMemberDetails.Role(rustPowerLevel: powerLevels.ban)
|
||||
invite = RoomMemberDetails.Role(rustPowerLevel: powerLevels.invite)
|
||||
kick = RoomMemberDetails.Role(rustPowerLevel: powerLevels.kick)
|
||||
@@ -104,18 +104,3 @@ extension RoomMemberDetails.Role {
|
||||
suggestedPowerLevelForRole(role: rustRole)
|
||||
}
|
||||
}
|
||||
|
||||
extension RoomPowerLevels {
|
||||
static var mock: RoomPowerLevels {
|
||||
RoomPowerLevels(ban: 50,
|
||||
invite: 0,
|
||||
kick: 50,
|
||||
redact: 50,
|
||||
eventsDefault: 0,
|
||||
stateDefault: 50,
|
||||
usersDefault: 0,
|
||||
roomName: 50,
|
||||
roomAvatar: 50,
|
||||
roomTopic: 50)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// Copyright 2025 New Vector Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import MatrixRustSDK
|
||||
|
||||
// sourcery: AutoMockable
|
||||
protocol RoomPowerLevelsProxyProtocol {
|
||||
var values: RoomPowerLevelsValues { get }
|
||||
|
||||
func canUser(userID: String, sendMessage messageType: MessageLikeEventType) -> Result<Bool, RoomProxyError>
|
||||
func canUser(userID: String, sendStateEvent event: StateEventType) -> Result<Bool, RoomProxyError>
|
||||
func canUserInvite(userID: String) -> Result<Bool, RoomProxyError>
|
||||
func canUserRedactOther(userID: String) -> Result<Bool, RoomProxyError>
|
||||
func canUserRedactOwn(userID: String) -> Result<Bool, RoomProxyError>
|
||||
func canUserKick(userID: String) -> Result<Bool, RoomProxyError>
|
||||
func canUserBan(userID: String) -> Result<Bool, RoomProxyError>
|
||||
func canUserTriggerRoomNotification(userID: String) -> Result<Bool, RoomProxyError>
|
||||
func canUserPinOrUnpin(userID: String) -> Result<Bool, RoomProxyError>
|
||||
func canUserJoinCall(userID: String) -> Result<Bool, RoomProxyError>
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
//
|
||||
// Copyright 2025 New Vector Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import MatrixRustSDK
|
||||
|
||||
struct RoomPowerLevelsProxy: RoomPowerLevelsProxyProtocol {
|
||||
private let powerLevels: RoomPowerLevels
|
||||
|
||||
init(_ powerLevels: RoomPowerLevels) {
|
||||
self.powerLevels = powerLevels
|
||||
}
|
||||
|
||||
var values: RoomPowerLevelsValues {
|
||||
powerLevels.values()
|
||||
}
|
||||
|
||||
func canUser(userID: String, sendMessage messageType: MessageLikeEventType) -> Result<Bool, RoomProxyError> {
|
||||
do {
|
||||
return try .success(powerLevels.canUserSendMessage(userId: userID, message: messageType))
|
||||
} catch {
|
||||
MXLog.error("Failed checking if the user can send message with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
func canUser(userID: String, sendStateEvent event: StateEventType) -> Result<Bool, RoomProxyError> {
|
||||
do {
|
||||
return try .success(powerLevels.canUserSendState(userId: userID, stateEvent: event))
|
||||
} catch {
|
||||
MXLog.error("Failed checking if the user can send \(event) with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
func canUserInvite(userID: String) -> Result<Bool, RoomProxyError> {
|
||||
do {
|
||||
return try .success(powerLevels.canUserInvite(userId: userID))
|
||||
} catch {
|
||||
MXLog.error("Failed checking if the user can invite with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
func canUserRedactOther(userID: String) -> Result<Bool, RoomProxyError> {
|
||||
do {
|
||||
return try .success(powerLevels.canUserRedactOther(userId: userID))
|
||||
} catch {
|
||||
MXLog.error("Failed checking if the user can redact others with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
func canUserRedactOwn(userID: String) -> Result<Bool, RoomProxyError> {
|
||||
do {
|
||||
return try .success(powerLevels.canUserRedactOwn(userId: userID))
|
||||
} catch {
|
||||
MXLog.error("Failed checking if the user can redact self with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
func canUserKick(userID: String) -> Result<Bool, RoomProxyError> {
|
||||
do {
|
||||
return try .success(powerLevels.canUserKick(userId: userID))
|
||||
} catch {
|
||||
MXLog.error("Failed checking if the user can kick with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
func canUserBan(userID: String) -> Result<Bool, RoomProxyError> {
|
||||
do {
|
||||
return try .success(powerLevels.canUserBan(userId: userID))
|
||||
} catch {
|
||||
MXLog.error("Failed checking if the user can ban with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
func canUserTriggerRoomNotification(userID: String) -> Result<Bool, RoomProxyError> {
|
||||
do {
|
||||
return try .success(powerLevels.canUserTriggerRoomNotification(userId: userID))
|
||||
} catch {
|
||||
MXLog.error("Failed checking if the user can trigger room notification with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
func canUserPinOrUnpin(userID: String) -> Result<Bool, RoomProxyError> {
|
||||
do {
|
||||
return try .success(powerLevels.canUserPinUnpin(userId: userID))
|
||||
} catch {
|
||||
MXLog.error("Failed checking if the user can pin or unnpin: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
func canUserJoinCall(userID: String) -> Result<Bool, RoomProxyError> {
|
||||
do {
|
||||
return try .success(powerLevels.canUserSendState(userId: userID, stateEvent: .callMember))
|
||||
} catch {
|
||||
MXLog.error("Failed checking if the user can trigger room notification with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,20 +152,11 @@ protocol JoinedRoomProxyProtocol: RoomProxyProtocol {
|
||||
|
||||
// MARK: - Power Levels
|
||||
|
||||
func powerLevels() async -> Result<RoomPowerLevels, RoomProxyError>
|
||||
func powerLevels() async -> Result<RoomPowerLevelsProxyProtocol, RoomProxyError>
|
||||
func applyPowerLevelChanges(_ changes: RoomPowerLevelChanges) async -> Result<Void, RoomProxyError>
|
||||
func resetPowerLevels() async -> Result<RoomPowerLevels, RoomProxyError>
|
||||
func resetPowerLevels() async -> Result<Void, RoomProxyError>
|
||||
func suggestedRole(for userID: String) async -> Result<RoomMemberRole, RoomProxyError>
|
||||
func updatePowerLevelsForUsers(_ updates: [(userID: String, powerLevel: Int64)]) async -> Result<Void, RoomProxyError>
|
||||
func canUser(userID: String, sendMessage messageType: MessageLikeEventType) async -> Result<Bool, RoomProxyError>
|
||||
func canUser(userID: String, sendStateEvent event: StateEventType) async -> Result<Bool, RoomProxyError>
|
||||
func canUserInvite(userID: String) async -> Result<Bool, RoomProxyError>
|
||||
func canUserRedactOther(userID: String) async -> Result<Bool, RoomProxyError>
|
||||
func canUserRedactOwn(userID: String) async -> Result<Bool, RoomProxyError>
|
||||
func canUserKick(userID: String) async -> Result<Bool, RoomProxyError>
|
||||
func canUserBan(userID: String) async -> Result<Bool, RoomProxyError>
|
||||
func canUserTriggerRoomNotification(userID: String) async -> Result<Bool, RoomProxyError>
|
||||
func canUserPinOrUnpin(userID: String) async -> Result<Bool, RoomProxyError>
|
||||
|
||||
// MARK: - Moderation
|
||||
|
||||
@@ -175,9 +166,7 @@ protocol JoinedRoomProxyProtocol: RoomProxyProtocol {
|
||||
|
||||
// MARK: - Element Call
|
||||
|
||||
func canUserJoinCall(userID: String) async -> Result<Bool, RoomProxyError>
|
||||
func elementCallWidgetDriver(deviceID: String) -> ElementCallWidgetDriverProtocol
|
||||
|
||||
func sendCallNotificationIfNeeded() async -> Result<Void, RoomProxyError>
|
||||
|
||||
// MARK: - Permalinks
|
||||
|
||||
Reference in New Issue
Block a user