mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-10 18:28:48 +00:00
0e7533145a
better implementation updated tests Update ElementX/Sources/Screens/Timeline/TimelineViewModel.swift Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com> fix
55 lines
1.4 KiB
Swift
55 lines
1.4 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
|
|
|
|
enum Role { case administrator, moderator, user }
|
|
let role: Role
|
|
let powerLevel: Int
|
|
|
|
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
|
|
|
|
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 {
|
|
case .administrator: .administrator
|
|
case .moderator: .moderator
|
|
case .user: .user
|
|
}
|
|
}
|
|
}
|