mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Replace individual RoomProxy properties with a stored RoomInfo. (#3445)
* Store RoomInfo updates in JoinedRoomProxy and read from them directly. * Remove all RoomProxy properties that were reading from the RoomInfo.
This commit is contained in:
@@ -5824,67 +5824,21 @@ class ElementCallWidgetDriverMock: ElementCallWidgetDriverProtocol {
|
||||
}
|
||||
}
|
||||
class InvitedRoomProxyMock: InvitedRoomProxyProtocol {
|
||||
var inviterCallsCount = 0
|
||||
var inviterCalled: Bool {
|
||||
return inviterCallsCount > 0
|
||||
var info: RoomInfoProxy {
|
||||
get { return underlyingInfo }
|
||||
set(value) { underlyingInfo = value }
|
||||
}
|
||||
|
||||
var inviter: RoomMemberProxyProtocol? {
|
||||
get async {
|
||||
inviterCallsCount += 1
|
||||
if let inviterClosure = inviterClosure {
|
||||
return await inviterClosure()
|
||||
} else {
|
||||
return underlyingInviter
|
||||
}
|
||||
}
|
||||
}
|
||||
var underlyingInviter: RoomMemberProxyProtocol?
|
||||
var inviterClosure: (() async -> RoomMemberProxyProtocol?)?
|
||||
var underlyingInfo: RoomInfoProxy!
|
||||
var id: String {
|
||||
get { return underlyingId }
|
||||
set(value) { underlyingId = value }
|
||||
}
|
||||
var underlyingId: String!
|
||||
var canonicalAlias: String?
|
||||
var ownUserID: String {
|
||||
get { return underlyingOwnUserID }
|
||||
set(value) { underlyingOwnUserID = value }
|
||||
}
|
||||
var underlyingOwnUserID: String!
|
||||
var name: String?
|
||||
var topic: String?
|
||||
var avatar: RoomAvatar {
|
||||
get { return underlyingAvatar }
|
||||
set(value) { underlyingAvatar = value }
|
||||
}
|
||||
var underlyingAvatar: RoomAvatar!
|
||||
var avatarURL: URL?
|
||||
var isPublic: Bool {
|
||||
get { return underlyingIsPublic }
|
||||
set(value) { underlyingIsPublic = value }
|
||||
}
|
||||
var underlyingIsPublic: Bool!
|
||||
var isDirect: Bool {
|
||||
get { return underlyingIsDirect }
|
||||
set(value) { underlyingIsDirect = value }
|
||||
}
|
||||
var underlyingIsDirect: Bool!
|
||||
var isSpace: Bool {
|
||||
get { return underlyingIsSpace }
|
||||
set(value) { underlyingIsSpace = value }
|
||||
}
|
||||
var underlyingIsSpace: Bool!
|
||||
var joinedMembersCount: Int {
|
||||
get { return underlyingJoinedMembersCount }
|
||||
set(value) { underlyingJoinedMembersCount = value }
|
||||
}
|
||||
var underlyingJoinedMembersCount: Int!
|
||||
var activeMembersCount: Int {
|
||||
get { return underlyingActiveMembersCount }
|
||||
set(value) { underlyingActiveMembersCount = value }
|
||||
}
|
||||
var underlyingActiveMembersCount: Int!
|
||||
|
||||
//MARK: - rejectInvitation
|
||||
|
||||
@@ -6021,46 +5975,11 @@ class JoinedRoomProxyMock: JoinedRoomProxyProtocol {
|
||||
set(value) { underlyingIsEncrypted = value }
|
||||
}
|
||||
var underlyingIsEncrypted: Bool!
|
||||
var isFavouriteCallsCount = 0
|
||||
var isFavouriteCalled: Bool {
|
||||
return isFavouriteCallsCount > 0
|
||||
var infoPublisher: CurrentValuePublisher<RoomInfoProxy, Never> {
|
||||
get { return underlyingInfoPublisher }
|
||||
set(value) { underlyingInfoPublisher = value }
|
||||
}
|
||||
|
||||
var isFavourite: Bool {
|
||||
get async {
|
||||
isFavouriteCallsCount += 1
|
||||
if let isFavouriteClosure = isFavouriteClosure {
|
||||
return await isFavouriteClosure()
|
||||
} else {
|
||||
return underlyingIsFavourite
|
||||
}
|
||||
}
|
||||
}
|
||||
var underlyingIsFavourite: Bool!
|
||||
var isFavouriteClosure: (() async -> Bool)?
|
||||
var pinnedEventIDsCallsCount = 0
|
||||
var pinnedEventIDsCalled: Bool {
|
||||
return pinnedEventIDsCallsCount > 0
|
||||
}
|
||||
|
||||
var pinnedEventIDs: Set<String> {
|
||||
get async {
|
||||
pinnedEventIDsCallsCount += 1
|
||||
if let pinnedEventIDsClosure = pinnedEventIDsClosure {
|
||||
return await pinnedEventIDsClosure()
|
||||
} else {
|
||||
return underlyingPinnedEventIDs
|
||||
}
|
||||
}
|
||||
}
|
||||
var underlyingPinnedEventIDs: Set<String>!
|
||||
var pinnedEventIDsClosure: (() async -> Set<String>)?
|
||||
var hasOngoingCall: Bool {
|
||||
get { return underlyingHasOngoingCall }
|
||||
set(value) { underlyingHasOngoingCall = value }
|
||||
}
|
||||
var underlyingHasOngoingCall: Bool!
|
||||
var activeRoomCallParticipants: [String] = []
|
||||
var underlyingInfoPublisher: CurrentValuePublisher<RoomInfoProxy, Never>!
|
||||
var membersPublisher: CurrentValuePublisher<[RoomMemberProxyProtocol], Never> {
|
||||
get { return underlyingMembersPublisher }
|
||||
set(value) { underlyingMembersPublisher = value }
|
||||
@@ -6076,11 +5995,6 @@ class JoinedRoomProxyMock: JoinedRoomProxyProtocol {
|
||||
set(value) { underlyingIdentityStatusChangesPublisher = value }
|
||||
}
|
||||
var underlyingIdentityStatusChangesPublisher: CurrentValuePublisher<[IdentityStatusChange], Never>!
|
||||
var actionsPublisher: AnyPublisher<JoinedRoomProxyAction, Never> {
|
||||
get { return underlyingActionsPublisher }
|
||||
set(value) { underlyingActionsPublisher = value }
|
||||
}
|
||||
var underlyingActionsPublisher: AnyPublisher<JoinedRoomProxyAction, Never>!
|
||||
var timeline: TimelineProxyProtocol {
|
||||
get { return underlyingTimeline }
|
||||
set(value) { underlyingTimeline = value }
|
||||
@@ -6108,45 +6022,11 @@ class JoinedRoomProxyMock: JoinedRoomProxyProtocol {
|
||||
set(value) { underlyingId = value }
|
||||
}
|
||||
var underlyingId: String!
|
||||
var canonicalAlias: String?
|
||||
var ownUserID: String {
|
||||
get { return underlyingOwnUserID }
|
||||
set(value) { underlyingOwnUserID = value }
|
||||
}
|
||||
var underlyingOwnUserID: String!
|
||||
var name: String?
|
||||
var topic: String?
|
||||
var avatar: RoomAvatar {
|
||||
get { return underlyingAvatar }
|
||||
set(value) { underlyingAvatar = value }
|
||||
}
|
||||
var underlyingAvatar: RoomAvatar!
|
||||
var avatarURL: URL?
|
||||
var isPublic: Bool {
|
||||
get { return underlyingIsPublic }
|
||||
set(value) { underlyingIsPublic = value }
|
||||
}
|
||||
var underlyingIsPublic: Bool!
|
||||
var isDirect: Bool {
|
||||
get { return underlyingIsDirect }
|
||||
set(value) { underlyingIsDirect = value }
|
||||
}
|
||||
var underlyingIsDirect: Bool!
|
||||
var isSpace: Bool {
|
||||
get { return underlyingIsSpace }
|
||||
set(value) { underlyingIsSpace = value }
|
||||
}
|
||||
var underlyingIsSpace: Bool!
|
||||
var joinedMembersCount: Int {
|
||||
get { return underlyingJoinedMembersCount }
|
||||
set(value) { underlyingJoinedMembersCount = value }
|
||||
}
|
||||
var underlyingJoinedMembersCount: Int!
|
||||
var activeMembersCount: Int {
|
||||
get { return underlyingActiveMembersCount }
|
||||
set(value) { underlyingActiveMembersCount = value }
|
||||
}
|
||||
var underlyingActiveMembersCount: Int!
|
||||
|
||||
//MARK: - subscribeForUpdates
|
||||
|
||||
@@ -9752,50 +9632,21 @@ class KeychainControllerMock: KeychainControllerProtocol {
|
||||
}
|
||||
}
|
||||
class KnockedRoomProxyMock: KnockedRoomProxyProtocol {
|
||||
var info: RoomInfoProxy {
|
||||
get { return underlyingInfo }
|
||||
set(value) { underlyingInfo = value }
|
||||
}
|
||||
var underlyingInfo: RoomInfoProxy!
|
||||
var id: String {
|
||||
get { return underlyingId }
|
||||
set(value) { underlyingId = value }
|
||||
}
|
||||
var underlyingId: String!
|
||||
var canonicalAlias: String?
|
||||
var ownUserID: String {
|
||||
get { return underlyingOwnUserID }
|
||||
set(value) { underlyingOwnUserID = value }
|
||||
}
|
||||
var underlyingOwnUserID: String!
|
||||
var name: String?
|
||||
var topic: String?
|
||||
var avatar: RoomAvatar {
|
||||
get { return underlyingAvatar }
|
||||
set(value) { underlyingAvatar = value }
|
||||
}
|
||||
var underlyingAvatar: RoomAvatar!
|
||||
var avatarURL: URL?
|
||||
var isPublic: Bool {
|
||||
get { return underlyingIsPublic }
|
||||
set(value) { underlyingIsPublic = value }
|
||||
}
|
||||
var underlyingIsPublic: Bool!
|
||||
var isDirect: Bool {
|
||||
get { return underlyingIsDirect }
|
||||
set(value) { underlyingIsDirect = value }
|
||||
}
|
||||
var underlyingIsDirect: Bool!
|
||||
var isSpace: Bool {
|
||||
get { return underlyingIsSpace }
|
||||
set(value) { underlyingIsSpace = value }
|
||||
}
|
||||
var underlyingIsSpace: Bool!
|
||||
var joinedMembersCount: Int {
|
||||
get { return underlyingJoinedMembersCount }
|
||||
set(value) { underlyingJoinedMembersCount = value }
|
||||
}
|
||||
var underlyingJoinedMembersCount: Int!
|
||||
var activeMembersCount: Int {
|
||||
get { return underlyingActiveMembersCount }
|
||||
set(value) { underlyingActiveMembersCount = value }
|
||||
}
|
||||
var underlyingActiveMembersCount: Int!
|
||||
|
||||
//MARK: - cancelKnock
|
||||
|
||||
@@ -12934,45 +12785,11 @@ class RoomProxyMock: RoomProxyProtocol {
|
||||
set(value) { underlyingId = value }
|
||||
}
|
||||
var underlyingId: String!
|
||||
var canonicalAlias: String?
|
||||
var ownUserID: String {
|
||||
get { return underlyingOwnUserID }
|
||||
set(value) { underlyingOwnUserID = value }
|
||||
}
|
||||
var underlyingOwnUserID: String!
|
||||
var name: String?
|
||||
var topic: String?
|
||||
var avatar: RoomAvatar {
|
||||
get { return underlyingAvatar }
|
||||
set(value) { underlyingAvatar = value }
|
||||
}
|
||||
var underlyingAvatar: RoomAvatar!
|
||||
var avatarURL: URL?
|
||||
var isPublic: Bool {
|
||||
get { return underlyingIsPublic }
|
||||
set(value) { underlyingIsPublic = value }
|
||||
}
|
||||
var underlyingIsPublic: Bool!
|
||||
var isDirect: Bool {
|
||||
get { return underlyingIsDirect }
|
||||
set(value) { underlyingIsDirect = value }
|
||||
}
|
||||
var underlyingIsDirect: Bool!
|
||||
var isSpace: Bool {
|
||||
get { return underlyingIsSpace }
|
||||
set(value) { underlyingIsSpace = value }
|
||||
}
|
||||
var underlyingIsSpace: Bool!
|
||||
var joinedMembersCount: Int {
|
||||
get { return underlyingJoinedMembersCount }
|
||||
set(value) { underlyingJoinedMembersCount = value }
|
||||
}
|
||||
var underlyingJoinedMembersCount: Int!
|
||||
var activeMembersCount: Int {
|
||||
get { return underlyingActiveMembersCount }
|
||||
set(value) { underlyingActiveMembersCount = value }
|
||||
}
|
||||
var underlyingActiveMembersCount: Int!
|
||||
|
||||
}
|
||||
class RoomSummaryProviderMock: RoomSummaryProviderProtocol {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
import Combine
|
||||
import Foundation
|
||||
import MatrixRustSDK
|
||||
|
||||
@MainActor
|
||||
struct InvitedRoomProxyMockConfiguration {
|
||||
@@ -22,10 +23,55 @@ extension InvitedRoomProxyMock {
|
||||
convenience init(_ configuration: InvitedRoomProxyMockConfiguration) {
|
||||
self.init()
|
||||
id = configuration.id
|
||||
name = configuration.name
|
||||
avatarURL = configuration.avatarURL
|
||||
avatar = .room(id: configuration.id, name: configuration.name, avatarURL: configuration.avatarURL) // Note: This doesn't replicate the real proxy logic.
|
||||
underlyingInviter = configuration.inviter
|
||||
activeMembersCount = configuration.members.filter { $0.membership == .join || $0.membership == .invite }.count
|
||||
info = RoomInfoProxy(roomInfo: .init(configuration))
|
||||
}
|
||||
}
|
||||
|
||||
extension RoomInfo {
|
||||
@MainActor init(_ configuration: InvitedRoomProxyMockConfiguration) {
|
||||
self.init(id: configuration.id,
|
||||
creator: nil,
|
||||
displayName: configuration.name,
|
||||
rawName: nil,
|
||||
topic: nil,
|
||||
avatarUrl: configuration.avatarURL?.absoluteString,
|
||||
isDirect: false,
|
||||
isPublic: false,
|
||||
isSpace: false,
|
||||
isTombstoned: false,
|
||||
isFavourite: false,
|
||||
canonicalAlias: nil,
|
||||
alternativeAliases: [],
|
||||
membership: .knocked,
|
||||
inviter: .init(configuration.inviter),
|
||||
heroes: [],
|
||||
activeMembersCount: UInt64(configuration.members.filter { $0.membership == .join || $0.membership == .invite }.count),
|
||||
invitedMembersCount: UInt64(configuration.members.filter { $0.membership == .invite }.count),
|
||||
joinedMembersCount: UInt64(configuration.members.filter { $0.membership == .join }.count),
|
||||
userPowerLevels: [:],
|
||||
highlightCount: 0,
|
||||
notificationCount: 0,
|
||||
cachedUserDefinedNotificationMode: nil,
|
||||
hasRoomCall: false,
|
||||
activeRoomCallParticipants: [],
|
||||
isMarkedUnread: false,
|
||||
numUnreadMessages: 0,
|
||||
numUnreadNotifications: 0,
|
||||
numUnreadMentions: 0,
|
||||
pinnedEventIds: [])
|
||||
}
|
||||
}
|
||||
|
||||
private extension RoomMember {
|
||||
init(_ proxy: RoomMemberProxyProtocol) {
|
||||
self.init(userId: proxy.userID,
|
||||
displayName: proxy.displayName,
|
||||
avatarUrl: proxy.avatarURL?.absoluteString,
|
||||
membership: proxy.membership,
|
||||
isNameAmbiguous: proxy.disambiguatedDisplayName != proxy.displayName,
|
||||
powerLevel: Int64(proxy.powerLevel),
|
||||
normalizedPowerLevel: Int64(proxy.powerLevel),
|
||||
isIgnored: proxy.isIgnored,
|
||||
suggestedRoleForPowerLevel: proxy.role)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
import Combine
|
||||
import Foundation
|
||||
import MatrixRustSDK
|
||||
|
||||
enum RoomProxyMockError: Error {
|
||||
case generic
|
||||
@@ -46,18 +47,7 @@ extension JoinedRoomProxyMock {
|
||||
self.init()
|
||||
|
||||
id = configuration.id
|
||||
name = configuration.name
|
||||
topic = configuration.topic
|
||||
avatar = .room(id: configuration.id, name: configuration.name, avatarURL: configuration.avatarURL) // Note: This doesn't replicate the real proxy logic.
|
||||
avatarURL = configuration.avatarURL
|
||||
isDirect = configuration.isDirect
|
||||
isSpace = configuration.isSpace
|
||||
isPublic = configuration.isPublic
|
||||
isEncrypted = configuration.isEncrypted
|
||||
hasOngoingCall = configuration.hasOngoingCall
|
||||
canonicalAlias = configuration.canonicalAlias
|
||||
|
||||
underlyingPinnedEventIDs = configuration.pinnedEventIDs
|
||||
|
||||
let timeline = TimelineProxyMock()
|
||||
timeline.sendMessageEventContentReturnValue = .success(())
|
||||
@@ -78,15 +68,12 @@ extension JoinedRoomProxyMock {
|
||||
|
||||
ownUserID = configuration.ownUserID
|
||||
|
||||
infoPublisher = CurrentValueSubject(.init(roomInfo: .init(configuration))).asCurrentValuePublisher()
|
||||
membersPublisher = CurrentValueSubject(configuration.members).asCurrentValuePublisher()
|
||||
typingMembersPublisher = CurrentValueSubject([]).asCurrentValuePublisher()
|
||||
identityStatusChangesPublisher = CurrentValueSubject([]).asCurrentValuePublisher()
|
||||
|
||||
joinedMembersCount = configuration.members.filter { $0.membership == .join }.count
|
||||
activeMembersCount = configuration.members.filter { $0.membership == .join || $0.membership == .invite }.count
|
||||
|
||||
updateMembersClosure = { }
|
||||
underlyingActionsPublisher = Empty(completeImmediately: false).eraseToAnyPublisher()
|
||||
setNameClosure = { _ in .success(()) }
|
||||
setTopicClosure = { _ in .success(()) }
|
||||
getMemberUserIDClosure = { [weak self] userID in
|
||||
@@ -102,7 +89,6 @@ extension JoinedRoomProxyMock {
|
||||
|
||||
flagAsUnreadReturnValue = .success(())
|
||||
markAsReadReceiptTypeReturnValue = .success(())
|
||||
underlyingIsFavourite = false
|
||||
flagAsFavouriteReturnValue = .success(())
|
||||
|
||||
powerLevelsReturnValue = .success(.mock)
|
||||
@@ -154,3 +140,46 @@ extension JoinedRoomProxyMock {
|
||||
clearDraftReturnValue = .success(())
|
||||
}
|
||||
}
|
||||
|
||||
extension RoomInfo {
|
||||
@MainActor init(_ configuration: JoinedRoomProxyMockConfiguration) {
|
||||
self.init(id: configuration.id,
|
||||
creator: nil,
|
||||
displayName: configuration.name,
|
||||
rawName: configuration.name,
|
||||
topic: configuration.topic,
|
||||
avatarUrl: configuration.avatarURL?.absoluteString,
|
||||
isDirect: configuration.isDirect,
|
||||
isPublic: configuration.isPublic,
|
||||
isSpace: configuration.isSpace,
|
||||
isTombstoned: false,
|
||||
isFavourite: false,
|
||||
canonicalAlias: configuration.canonicalAlias,
|
||||
alternativeAliases: [],
|
||||
membership: .joined,
|
||||
inviter: configuration.inviter.map { RoomMember(userId: $0.userID,
|
||||
displayName: $0.displayName,
|
||||
avatarUrl: $0.avatarURL?.absoluteString,
|
||||
membership: $0.membership,
|
||||
isNameAmbiguous: false,
|
||||
powerLevel: Int64($0.powerLevel),
|
||||
normalizedPowerLevel: Int64($0.powerLevel),
|
||||
isIgnored: $0.isIgnored,
|
||||
suggestedRoleForPowerLevel: $0.role) },
|
||||
heroes: [],
|
||||
activeMembersCount: UInt64(configuration.members.filter { $0.membership == .join || $0.membership == .invite }.count),
|
||||
invitedMembersCount: UInt64(configuration.members.filter { $0.membership == .invite }.count),
|
||||
joinedMembersCount: UInt64(configuration.members.filter { $0.membership == .join }.count),
|
||||
userPowerLevels: [:],
|
||||
highlightCount: 0,
|
||||
notificationCount: 0,
|
||||
cachedUserDefinedNotificationMode: .allMessages,
|
||||
hasRoomCall: configuration.hasOngoingCall,
|
||||
activeRoomCallParticipants: [],
|
||||
isMarkedUnread: false,
|
||||
numUnreadMessages: 0,
|
||||
numUnreadNotifications: 0,
|
||||
numUnreadMentions: 0,
|
||||
pinnedEventIds: Array(configuration.pinnedEventIDs))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
import Combine
|
||||
import Foundation
|
||||
import MatrixRustSDK
|
||||
|
||||
@MainActor
|
||||
struct KnockedRoomProxyMockConfiguration {
|
||||
@@ -21,9 +22,41 @@ extension KnockedRoomProxyMock {
|
||||
convenience init(_ configuration: KnockedRoomProxyMockConfiguration) {
|
||||
self.init()
|
||||
id = configuration.id
|
||||
name = configuration.name
|
||||
avatarURL = configuration.avatarURL
|
||||
avatar = .room(id: configuration.id, name: configuration.name, avatarURL: configuration.avatarURL) // Note: This doesn't replicate the real proxy logic.
|
||||
activeMembersCount = configuration.members.filter { $0.membership == .join || $0.membership == .invite }.count
|
||||
info = RoomInfoProxy(roomInfo: .init(configuration))
|
||||
}
|
||||
}
|
||||
|
||||
extension RoomInfo {
|
||||
@MainActor init(_ configuration: KnockedRoomProxyMockConfiguration) {
|
||||
self.init(id: configuration.id,
|
||||
creator: nil,
|
||||
displayName: configuration.name,
|
||||
rawName: nil,
|
||||
topic: nil,
|
||||
avatarUrl: configuration.avatarURL?.absoluteString,
|
||||
isDirect: false,
|
||||
isPublic: false,
|
||||
isSpace: false,
|
||||
isTombstoned: false,
|
||||
isFavourite: false,
|
||||
canonicalAlias: nil,
|
||||
alternativeAliases: [],
|
||||
membership: .knocked,
|
||||
inviter: nil,
|
||||
heroes: [],
|
||||
activeMembersCount: UInt64(configuration.members.filter { $0.membership == .join || $0.membership == .invite }.count),
|
||||
invitedMembersCount: UInt64(configuration.members.filter { $0.membership == .invite }.count),
|
||||
joinedMembersCount: UInt64(configuration.members.filter { $0.membership == .join }.count),
|
||||
userPowerLevels: [:],
|
||||
highlightCount: 0,
|
||||
notificationCount: 0,
|
||||
cachedUserDefinedNotificationMode: nil,
|
||||
hasRoomCall: false,
|
||||
activeRoomCallParticipants: [],
|
||||
isMarkedUnread: false,
|
||||
numUnreadMessages: 0,
|
||||
numUnreadNotifications: 0,
|
||||
numUnreadMentions: 0,
|
||||
pinnedEventIds: [])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user