* update the sdk, and updated the power levels APIs Revert "update the sdk, and updated the power levels APIs" This reverts commit d3b291003d2b6fd6346ef7e445af4970fda62348. x * pr suggestions
57 lines
1.5 KiB
Swift
57 lines
1.5 KiB
Swift
//
|
|
// Copyright 2023, 2024 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 Foundation
|
|
import MatrixRustSDK
|
|
|
|
struct RoomMemberDetails: Identifiable, Hashable {
|
|
let id: String
|
|
let name: String?
|
|
let avatarURL: URL?
|
|
let permalink: URL?
|
|
|
|
var isInvited: Bool
|
|
var isIgnored: Bool
|
|
var isBanned: Bool
|
|
var isActive: Bool
|
|
|
|
enum Role { case administrator, moderator, user }
|
|
let role: Role
|
|
let powerLevel: RoomPowerLevel
|
|
|
|
func matches(searchQuery: String) -> Bool {
|
|
guard !searchQuery.isEmpty else { return true }
|
|
return id.localizedStandardContains(searchQuery) || name?.localizedStandardContains(searchQuery) == true
|
|
}
|
|
}
|
|
|
|
extension RoomMemberDetails {
|
|
init(withProxy proxy: RoomMemberProxyProtocol) {
|
|
id = proxy.userID
|
|
name = proxy.displayName
|
|
avatarURL = proxy.avatarURL
|
|
permalink = proxy.permalink
|
|
isActive = proxy.isActive
|
|
isInvited = proxy.membership == .invite
|
|
isIgnored = proxy.isIgnored
|
|
isBanned = proxy.membership == .ban
|
|
role = .init(proxy.role)
|
|
powerLevel = proxy.powerLevel
|
|
}
|
|
}
|
|
|
|
extension RoomMemberDetails.Role {
|
|
init(_ role: RoomMemberRole) {
|
|
self = switch role {
|
|
// TODO: Implement creator role
|
|
case .creator, .administrator: .administrator
|
|
case .moderator: .moderator
|
|
case .user: .user
|
|
}
|
|
}
|
|
}
|