mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Kick/ban room members (#2501)
* Add a temporary membershipChangePublisher on the timeline. * Kick/Ban users from a room. * Unit tests. * Disable autocorrection on the members list search field.
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
import Foundation
|
||||
import MatrixRustSDK
|
||||
|
||||
struct RoomMemberDetails: Identifiable, Equatable {
|
||||
struct RoomMemberDetails: Identifiable, Hashable {
|
||||
let id: String
|
||||
let name: String?
|
||||
let avatarURL: URL?
|
||||
|
||||
@@ -46,6 +46,7 @@ final class RoomMemberProxy: RoomMemberProxyProtocol {
|
||||
lazy var powerLevel = Int(member.powerLevel())
|
||||
lazy var role = member.suggestedRoleForPowerLevel()
|
||||
lazy var canInviteUsers = member.canInvite()
|
||||
lazy var canKickUsers = member.canKick()
|
||||
lazy var canBanUsers = member.canBan()
|
||||
|
||||
func canSendStateEvent(type: StateEventType) -> Bool {
|
||||
|
||||
@@ -34,6 +34,7 @@ protocol RoomMemberProxyProtocol: AnyObject {
|
||||
var powerLevel: Int { get }
|
||||
var role: RoomMemberRole { get }
|
||||
var canInviteUsers: Bool { get }
|
||||
var canKickUsers: Bool { get }
|
||||
var canBanUsers: Bool { get }
|
||||
|
||||
func ignoreUser() async -> Result<Void, RoomMemberProxyError>
|
||||
|
||||
@@ -416,6 +416,38 @@ class RoomProxy: RoomProxyProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Moderation
|
||||
|
||||
func kickUser(_ userID: String) async -> Result<Void, RoomProxyError> {
|
||||
do {
|
||||
try await room.kickUser(userId: userID, reason: nil)
|
||||
return .success(())
|
||||
} catch {
|
||||
MXLog.error("Failed kicking \(userID) with error: \(error)")
|
||||
return .failure(.failedModeration)
|
||||
}
|
||||
}
|
||||
|
||||
func banUser(_ userID: String) async -> Result<Void, RoomProxyError> {
|
||||
do {
|
||||
try await room.banUser(userId: userID, reason: nil)
|
||||
return .success(())
|
||||
} catch {
|
||||
MXLog.error("Failed banning \(userID) with error: \(error)")
|
||||
return .failure(.failedModeration)
|
||||
}
|
||||
}
|
||||
|
||||
func unbanUser(_ userID: String) async -> Result<Void, RoomProxyError> {
|
||||
do {
|
||||
try await room.unbanUser(userId: userID, reason: nil)
|
||||
return .success(())
|
||||
} catch {
|
||||
MXLog.error("Failed unbanning \(userID) with error: \(error)")
|
||||
return .failure(.failedModeration)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Element Call
|
||||
|
||||
func canUserJoinCall(userID: String) async -> Result<Bool, RoomProxyError> {
|
||||
|
||||
@@ -36,6 +36,7 @@ enum RoomProxyError: Error, Equatable {
|
||||
case failedMarkingAsRead
|
||||
case failedSendingTypingNotice
|
||||
case failedFlaggingAsFavourite
|
||||
case failedModeration
|
||||
}
|
||||
|
||||
enum RoomProxyAction {
|
||||
@@ -120,6 +121,12 @@ protocol RoomProxyProtocol {
|
||||
|
||||
func flagAsFavourite(_ isFavourite: Bool) async -> Result<Void, RoomProxyError>
|
||||
|
||||
// MARK: - Moderation
|
||||
|
||||
func kickUser(_ userID: String) async -> Result<Void, RoomProxyError>
|
||||
func banUser(_ userID: String) async -> Result<Void, RoomProxyError>
|
||||
func unbanUser(_ userID: String) async -> Result<Void, RoomProxyError>
|
||||
|
||||
// MARK: - Element Call
|
||||
|
||||
func canUserJoinCall(userID: String) async -> Result<Bool, RoomProxyError>
|
||||
|
||||
Reference in New Issue
Block a user