mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Update files following swiftformat upgrade
This commit is contained in:
committed by
Stefan Ceriu
parent
fe189fcfed
commit
23062901c0
@@ -30,17 +30,19 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol {
|
||||
|
||||
private var subscribedForUpdates = false
|
||||
|
||||
// A room identifier is constant and lazy stops it from being fetched
|
||||
// multiple times over FFI
|
||||
/// A room identifier is constant and lazy stops it from being fetched
|
||||
/// multiple times over FFI
|
||||
lazy var id: String = room.id()
|
||||
|
||||
var ownUserID: String { room.ownUserId() }
|
||||
var ownUserID: String {
|
||||
room.ownUserId()
|
||||
}
|
||||
|
||||
// The predecessor is set on room creation and never changes, so we lazily store it.
|
||||
/// The predecessor is set on room creation and never changes, so we lazily store it.
|
||||
lazy var predecessorRoom = room.predecessorRoom()
|
||||
|
||||
// The successor may change over time, so we access it dynamically.
|
||||
// It's suggested to observe it through the `infoPublisher`
|
||||
/// The successor may change over time, so we access it dynamically.
|
||||
/// It's suggested to observe it through the `infoPublisher`
|
||||
var successorRoom: SuccessorRoom? {
|
||||
room.successorRoom()
|
||||
}
|
||||
|
||||
@@ -12,48 +12,139 @@ import MatrixRustSDK
|
||||
struct RoomInfoProxy: RoomInfoProxyProtocol {
|
||||
let roomInfo: RoomInfo
|
||||
|
||||
var id: String { roomInfo.id }
|
||||
var creators: [String] { roomInfo.creators ?? [] }
|
||||
var displayName: String? { roomInfo.displayName }
|
||||
var rawName: String? { roomInfo.rawName }
|
||||
var topic: String? { roomInfo.topic }
|
||||
/// The room's avatar URL. Use this for editing and favour ``avatar`` for display.
|
||||
var avatarURL: URL? { roomInfo.avatarUrl.flatMap(URL.init) }
|
||||
var id: String {
|
||||
roomInfo.id
|
||||
}
|
||||
|
||||
// Here we're assuming unknown rooms are unencrypted.
|
||||
// Fortunately https://github.com/matrix-org/matrix-rust-sdk/pull/4778 makes that very much of an edge case and we
|
||||
// also automatically start a `latestEncryptionState` fetch if needed.
|
||||
// In the worst case, even if we are to assume a room is unencrypted, the SDK will still determine the correct
|
||||
// state before any message is sent.
|
||||
var isEncrypted: Bool { roomInfo.encryptionState == .encrypted }
|
||||
var creators: [String] {
|
||||
roomInfo.creators ?? []
|
||||
}
|
||||
|
||||
var displayName: String? {
|
||||
roomInfo.displayName
|
||||
}
|
||||
|
||||
var rawName: String? {
|
||||
roomInfo.rawName
|
||||
}
|
||||
|
||||
var topic: String? {
|
||||
roomInfo.topic
|
||||
}
|
||||
|
||||
/// The room's avatar URL. Use this for editing and favour ``avatar`` for display.
|
||||
var avatarURL: URL? {
|
||||
roomInfo.avatarUrl.flatMap(URL.init)
|
||||
}
|
||||
|
||||
/// Here we're assuming unknown rooms are unencrypted.
|
||||
/// Fortunately https://github.com/matrix-org/matrix-rust-sdk/pull/4778 makes that very much of an edge case and we
|
||||
/// also automatically start a `latestEncryptionState` fetch if needed.
|
||||
/// In the worst case, even if we are to assume a room is unencrypted, the SDK will still determine the correct
|
||||
/// state before any message is sent.
|
||||
var isEncrypted: Bool {
|
||||
roomInfo.encryptionState == .encrypted
|
||||
}
|
||||
|
||||
var isDirect: Bool { roomInfo.isDirect }
|
||||
var isSpace: Bool { roomInfo.isSpace }
|
||||
var isDirect: Bool {
|
||||
roomInfo.isDirect
|
||||
}
|
||||
|
||||
var isSpace: Bool {
|
||||
roomInfo.isSpace
|
||||
}
|
||||
|
||||
var successor: SuccessorRoom? { roomInfo.successorRoom }
|
||||
var isFavourite: Bool { roomInfo.isFavourite }
|
||||
var canonicalAlias: String? { roomInfo.canonicalAlias }
|
||||
var alternativeAliases: [String] { roomInfo.alternativeAliases }
|
||||
var membership: Membership { roomInfo.membership }
|
||||
var inviter: RoomMemberProxyProtocol? { roomInfo.inviter.map(RoomMemberProxy.init) }
|
||||
var heroes: [RoomHero] { roomInfo.heroes }
|
||||
var activeMembersCount: Int { Int(roomInfo.activeMembersCount) }
|
||||
var invitedMembersCount: Int { Int(roomInfo.invitedMembersCount) }
|
||||
var joinedMembersCount: Int { Int(roomInfo.joinedMembersCount) }
|
||||
var highlightCount: Int { Int(roomInfo.highlightCount) }
|
||||
var notificationCount: Int { Int(roomInfo.notificationCount) }
|
||||
var cachedUserDefinedNotificationMode: RoomNotificationMode? { roomInfo.cachedUserDefinedNotificationMode }
|
||||
var hasRoomCall: Bool { roomInfo.hasRoomCall }
|
||||
var activeRoomCallParticipants: [String] { roomInfo.activeRoomCallParticipants }
|
||||
var isMarkedUnread: Bool { roomInfo.isMarkedUnread }
|
||||
var unreadMessagesCount: UInt { UInt(roomInfo.numUnreadMessages) }
|
||||
var unreadNotificationsCount: UInt { UInt(roomInfo.numUnreadNotifications) }
|
||||
var unreadMentionsCount: UInt { UInt(roomInfo.numUnreadMentions) }
|
||||
var pinnedEventIDs: Set<String> { Set(roomInfo.pinnedEventIds) }
|
||||
var joinRule: JoinRule? { roomInfo.joinRule }
|
||||
var historyVisibility: RoomHistoryVisibility { roomInfo.historyVisibility }
|
||||
var successor: SuccessorRoom? {
|
||||
roomInfo.successorRoom
|
||||
}
|
||||
|
||||
var isFavourite: Bool {
|
||||
roomInfo.isFavourite
|
||||
}
|
||||
|
||||
var canonicalAlias: String? {
|
||||
roomInfo.canonicalAlias
|
||||
}
|
||||
|
||||
var alternativeAliases: [String] {
|
||||
roomInfo.alternativeAliases
|
||||
}
|
||||
|
||||
var membership: Membership {
|
||||
roomInfo.membership
|
||||
}
|
||||
|
||||
var inviter: RoomMemberProxyProtocol? {
|
||||
roomInfo.inviter.map(RoomMemberProxy.init)
|
||||
}
|
||||
|
||||
var heroes: [RoomHero] {
|
||||
roomInfo.heroes
|
||||
}
|
||||
|
||||
var activeMembersCount: Int {
|
||||
Int(roomInfo.activeMembersCount)
|
||||
}
|
||||
|
||||
var invitedMembersCount: Int {
|
||||
Int(roomInfo.invitedMembersCount)
|
||||
}
|
||||
|
||||
var joinedMembersCount: Int {
|
||||
Int(roomInfo.joinedMembersCount)
|
||||
}
|
||||
|
||||
var highlightCount: Int {
|
||||
Int(roomInfo.highlightCount)
|
||||
}
|
||||
|
||||
var notificationCount: Int {
|
||||
Int(roomInfo.notificationCount)
|
||||
}
|
||||
|
||||
var cachedUserDefinedNotificationMode: RoomNotificationMode? {
|
||||
roomInfo.cachedUserDefinedNotificationMode
|
||||
}
|
||||
|
||||
var hasRoomCall: Bool {
|
||||
roomInfo.hasRoomCall
|
||||
}
|
||||
|
||||
var activeRoomCallParticipants: [String] {
|
||||
roomInfo.activeRoomCallParticipants
|
||||
}
|
||||
|
||||
var isMarkedUnread: Bool {
|
||||
roomInfo.isMarkedUnread
|
||||
}
|
||||
|
||||
var unreadMessagesCount: UInt {
|
||||
UInt(roomInfo.numUnreadMessages)
|
||||
}
|
||||
|
||||
var unreadNotificationsCount: UInt {
|
||||
UInt(roomInfo.numUnreadNotifications)
|
||||
}
|
||||
|
||||
var unreadMentionsCount: UInt {
|
||||
UInt(roomInfo.numUnreadMentions)
|
||||
}
|
||||
|
||||
var pinnedEventIDs: Set<String> {
|
||||
Set(roomInfo.pinnedEventIds)
|
||||
}
|
||||
|
||||
var joinRule: JoinRule? {
|
||||
roomInfo.joinRule
|
||||
}
|
||||
|
||||
var historyVisibility: RoomHistoryVisibility {
|
||||
roomInfo.historyVisibility
|
||||
}
|
||||
|
||||
var powerLevels: RoomPowerLevelsProxyProtocol? { RoomPowerLevelsProxy(roomInfo.powerLevels) }
|
||||
var powerLevels: RoomPowerLevelsProxyProtocol? {
|
||||
RoomPowerLevelsProxy(roomInfo.powerLevels)
|
||||
}
|
||||
}
|
||||
|
||||
struct RoomPreviewInfoProxy: BaseRoomInfoProxyProtocol {
|
||||
@@ -61,17 +152,51 @@ struct RoomPreviewInfoProxy: BaseRoomInfoProxyProtocol {
|
||||
|
||||
let successor: SuccessorRoom? = nil
|
||||
|
||||
var id: String { roomPreviewInfo.roomId }
|
||||
var displayName: String? { roomPreviewInfo.name }
|
||||
var heroes: [RoomHero] { roomPreviewInfo.heroes ?? [] }
|
||||
var topic: String? { roomPreviewInfo.topic }
|
||||
var canonicalAlias: String? { roomPreviewInfo.canonicalAlias }
|
||||
var avatarURL: URL? { roomPreviewInfo.avatarUrl.flatMap(URL.init) }
|
||||
var isDirect: Bool { roomPreviewInfo.isDirect ?? false }
|
||||
var isSpace: Bool { roomPreviewInfo.roomType == .space }
|
||||
var activeMembersCount: Int { Int(roomPreviewInfo.numActiveMembers ?? roomPreviewInfo.numJoinedMembers) }
|
||||
var joinedMembersCount: Int { Int(roomPreviewInfo.numJoinedMembers) }
|
||||
var id: String {
|
||||
roomPreviewInfo.roomId
|
||||
}
|
||||
|
||||
var displayName: String? {
|
||||
roomPreviewInfo.name
|
||||
}
|
||||
|
||||
var heroes: [RoomHero] {
|
||||
roomPreviewInfo.heroes ?? []
|
||||
}
|
||||
|
||||
var topic: String? {
|
||||
roomPreviewInfo.topic
|
||||
}
|
||||
|
||||
var canonicalAlias: String? {
|
||||
roomPreviewInfo.canonicalAlias
|
||||
}
|
||||
|
||||
var avatarURL: URL? {
|
||||
roomPreviewInfo.avatarUrl.flatMap(URL.init)
|
||||
}
|
||||
|
||||
var isDirect: Bool {
|
||||
roomPreviewInfo.isDirect ?? false
|
||||
}
|
||||
|
||||
var isSpace: Bool {
|
||||
roomPreviewInfo.roomType == .space
|
||||
}
|
||||
|
||||
var activeMembersCount: Int {
|
||||
Int(roomPreviewInfo.numActiveMembers ?? roomPreviewInfo.numJoinedMembers)
|
||||
}
|
||||
|
||||
var joinedMembersCount: Int {
|
||||
Int(roomPreviewInfo.numJoinedMembers)
|
||||
}
|
||||
|
||||
var joinRule: JoinRule? { roomPreviewInfo.joinRule }
|
||||
var membership: Membership? { roomPreviewInfo.membership }
|
||||
var joinRule: JoinRule? {
|
||||
roomPreviewInfo.joinRule
|
||||
}
|
||||
|
||||
var membership: Membership? {
|
||||
roomPreviewInfo.membership
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,13 @@ final class RoomMemberProxy: RoomMemberProxyProtocol {
|
||||
self.member = member
|
||||
}
|
||||
|
||||
var userID: String { member.userId }
|
||||
var userID: String {
|
||||
member.userId
|
||||
}
|
||||
|
||||
var displayName: String? { member.displayName }
|
||||
var displayName: String? {
|
||||
member.displayName
|
||||
}
|
||||
|
||||
var disambiguatedDisplayName: String? {
|
||||
guard let displayName else {
|
||||
@@ -28,13 +32,23 @@ final class RoomMemberProxy: RoomMemberProxyProtocol {
|
||||
return member.isNameAmbiguous ? "\(displayName) (\(userID))" : displayName
|
||||
}
|
||||
|
||||
var avatarURL: URL? { member.avatarUrl.flatMap(URL.init(string:)) }
|
||||
var avatarURL: URL? {
|
||||
member.avatarUrl.flatMap(URL.init(string:))
|
||||
}
|
||||
|
||||
var membership: MembershipState { member.membership }
|
||||
var membership: MembershipState {
|
||||
member.membership
|
||||
}
|
||||
|
||||
var membershipChangeReason: String? { member.membershipChangeReason }
|
||||
var membershipChangeReason: String? {
|
||||
member.membershipChangeReason
|
||||
}
|
||||
|
||||
var isIgnored: Bool { member.isIgnored }
|
||||
var isIgnored: Bool {
|
||||
member.isIgnored
|
||||
}
|
||||
|
||||
var powerLevel: RoomPowerLevel { .init(rustPowerLevel: member.powerLevel) }
|
||||
var powerLevel: RoomPowerLevel {
|
||||
.init(rustPowerLevel: member.powerLevel)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,5 +59,7 @@ extension [RoomMemberProxyProtocol] {
|
||||
}
|
||||
|
||||
extension RoomMemberProxyProtocol {
|
||||
var role: RoomRole { .init(powerLevel: powerLevel) }
|
||||
var role: RoomRole {
|
||||
.init(powerLevel: powerLevel)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,9 @@ struct RoomPermissionsSetting: Identifiable {
|
||||
static let allValues: [(title: String, tag: RoomRole)] = [(title: L10n.screenRoomChangePermissionsAdministrators, tag: .administrator),
|
||||
(title: L10n.screenRoomChangePermissionsModerators, tag: .moderator),
|
||||
(title: L10n.screenRoomChangePermissionsEveryone, tag: .user)]
|
||||
var id: KeyPath<RoomPermissions, Int64> { keyPath }
|
||||
var id: KeyPath<RoomPermissions, Int64> {
|
||||
keyPath
|
||||
}
|
||||
|
||||
/// The title of this setting.
|
||||
let title: String
|
||||
@@ -69,16 +71,6 @@ struct RoomPermissionsSetting: Identifiable {
|
||||
Self.allValues.filter { $0.tag <= ownPowerLevel.role }
|
||||
}
|
||||
}
|
||||
|
||||
init(title: String,
|
||||
value: Int64,
|
||||
ownPowerLevel: RoomPowerLevel,
|
||||
keyPath: KeyPath<RoomPermissions, Int64>) {
|
||||
self.ownPowerLevel = ownPowerLevel
|
||||
self.title = title
|
||||
self.value = value
|
||||
self.keyPath = keyPath
|
||||
}
|
||||
}
|
||||
|
||||
struct RoomPermissions {
|
||||
|
||||
@@ -214,7 +214,7 @@ extension JoinedRoomProxyProtocol {
|
||||
return membersPublisher.value
|
||||
}
|
||||
|
||||
// This is a horrible workaround for not having any server names available when using tombstone links with v12 room IDs.
|
||||
/// This is a horrible workaround for not having any server names available when using tombstone links with v12 room IDs.
|
||||
func knownServerNames(maxCount: Int) -> any Sequence<String> {
|
||||
membersPublisher.value
|
||||
.prefix(1000) // No need to go crazy here…
|
||||
|
||||
@@ -62,21 +62,33 @@ struct RoomSummary {
|
||||
let isFavourite: Bool
|
||||
let isTombstoned: Bool
|
||||
|
||||
var hasUnreadMessages: Bool { unreadMessagesCount > 0 }
|
||||
var hasUnreadMentions: Bool { unreadMentionsCount > 0 }
|
||||
var hasUnreadNotifications: Bool { unreadNotificationsCount > 0 }
|
||||
var isMuted: Bool { notificationMode == .mute }
|
||||
var hasUnreadMessages: Bool {
|
||||
unreadMessagesCount > 0
|
||||
}
|
||||
|
||||
var hasUnreadMentions: Bool {
|
||||
unreadMentionsCount > 0
|
||||
}
|
||||
|
||||
var hasUnreadNotifications: Bool {
|
||||
unreadNotificationsCount > 0
|
||||
}
|
||||
|
||||
var isMuted: Bool {
|
||||
notificationMode == .mute
|
||||
}
|
||||
}
|
||||
|
||||
extension RoomSummary: CustomStringConvertible {
|
||||
var description: String { """
|
||||
RoomSummary: - id: \(id) \
|
||||
- isDirect: \(isDirect) \
|
||||
- unreadMessagesCount: \(unreadMessagesCount) \
|
||||
- unreadMentionsCount: \(unreadMentionsCount) \
|
||||
- unreadNotificationsCount: \(unreadNotificationsCount) \
|
||||
- notificationMode: \(notificationMode?.rawValue ?? "nil")
|
||||
"""
|
||||
var description: String {
|
||||
"""
|
||||
RoomSummary: - id: \(id) \
|
||||
- isDirect: \(isDirect) \
|
||||
- unreadMessagesCount: \(unreadMessagesCount) \
|
||||
- unreadMentionsCount: \(unreadMentionsCount) \
|
||||
- unreadNotificationsCount: \(unreadNotificationsCount) \
|
||||
- notificationMode: \(notificationMode?.rawValue ?? "nil")
|
||||
"""
|
||||
}
|
||||
|
||||
/// Used where summaries are shown in a list e.g. message forwarding,
|
||||
@@ -135,7 +147,7 @@ extension RoomSummary {
|
||||
isTombstoned = false
|
||||
}
|
||||
|
||||
// This doesn't have to work properly for DM invites, the heroes are always empty
|
||||
/// This doesn't have to work properly for DM invites, the heroes are always empty
|
||||
var avatar: RoomAvatar {
|
||||
guard !isTombstoned else {
|
||||
return .tombstoned
|
||||
|
||||
Reference in New Issue
Block a user