From 6397b127a4b917288ba377ea65f808e81999d244 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Fri, 25 Aug 2023 12:28:37 +0300 Subject: [PATCH] Register for room info updates --- .../Mocks/Generated/GeneratedMocks.swift | 8 +- .../Mocks/Generated/SDKGeneratedMocks.swift | 206 +++++++++--------- ElementX/Sources/Mocks/RoomProxyMock.swift | 2 +- .../RoomDetailsScreenViewModel.swift | 2 +- .../RoomScreen/RoomScreenViewModel.swift | 2 +- .../Sources/Services/Room/RoomProxy.swift | 35 ++- .../Services/Room/RoomProxyProtocol.swift | 4 +- 7 files changed, 142 insertions(+), 117 deletions(-) diff --git a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift index d5c22a3a4..b1db7ab34 100644 --- a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift +++ b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift @@ -813,11 +813,11 @@ class RoomProxyMock: RoomProxyProtocol { set(value) { underlyingActiveMembersCount = value } } var underlyingActiveMembersCount: Int! - var updatesPublisher: AnyPublisher<[TimelineDiff], Never> { - get { return underlyingUpdatesPublisher } - set(value) { underlyingUpdatesPublisher = value } + var stateUpdatesPublisher: AnyPublisher { + get { return underlyingStateUpdatesPublisher } + set(value) { underlyingStateUpdatesPublisher = value } } - var underlyingUpdatesPublisher: AnyPublisher<[TimelineDiff], Never>! + var underlyingStateUpdatesPublisher: AnyPublisher! var timelineProvider: RoomTimelineProviderProtocol { get { return underlyingTimelineProvider } set(value) { underlyingTimelineProvider = value } diff --git a/ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift b/ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift index 512fa1ab8..72c4cceb7 100644 --- a/ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift +++ b/ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift @@ -6,7 +6,7 @@ import Foundation import MatrixRustSDK class SDKClientMock: SDKClientProtocol { - //MARK: - `accountData` + //MARK: - accountData public var accountDataEventTypeThrowableError: Error? public var accountDataEventTypeCallsCount = 0 @@ -18,20 +18,20 @@ class SDKClientMock: SDKClientProtocol { public var accountDataEventTypeReturnValue: String? public var accountDataEventTypeClosure: ((String) throws -> String?)? - public func `accountData`(`eventType`: String) throws -> String? { + public func accountData(eventType: String) throws -> String? { if let error = accountDataEventTypeThrowableError { throw error } accountDataEventTypeCallsCount += 1 accountDataEventTypeReceivedEventType = eventType - accountDataEventTypeReceivedInvocations.append(`eventType`) + accountDataEventTypeReceivedInvocations.append(eventType) if let accountDataEventTypeClosure = accountDataEventTypeClosure { - return try accountDataEventTypeClosure(`eventType`) + return try accountDataEventTypeClosure(eventType) } else { return accountDataEventTypeReturnValue } } - //MARK: - `accountUrl` + //MARK: - accountUrl public var accountUrlCallsCount = 0 public var accountUrlCalled: Bool { @@ -40,7 +40,7 @@ class SDKClientMock: SDKClientProtocol { public var accountUrlReturnValue: String? public var accountUrlClosure: (() -> String?)? - public func `accountUrl`() -> String? { + public func accountUrl() -> String? { accountUrlCallsCount += 1 if let accountUrlClosure = accountUrlClosure { return accountUrlClosure() @@ -48,7 +48,7 @@ class SDKClientMock: SDKClientProtocol { return accountUrlReturnValue } } - //MARK: - `avatarUrl` + //MARK: - avatarUrl public var avatarUrlThrowableError: Error? public var avatarUrlCallsCount = 0 @@ -58,7 +58,7 @@ class SDKClientMock: SDKClientProtocol { public var avatarUrlReturnValue: String? public var avatarUrlClosure: (() throws -> String?)? - public func `avatarUrl`() throws -> String? { + public func avatarUrl() throws -> String? { if let error = avatarUrlThrowableError { throw error } @@ -69,7 +69,7 @@ class SDKClientMock: SDKClientProtocol { return avatarUrlReturnValue } } - //MARK: - `cachedAvatarUrl` + //MARK: - cachedAvatarUrl public var cachedAvatarUrlThrowableError: Error? public var cachedAvatarUrlCallsCount = 0 @@ -79,7 +79,7 @@ class SDKClientMock: SDKClientProtocol { public var cachedAvatarUrlReturnValue: String? public var cachedAvatarUrlClosure: (() throws -> String?)? - public func `cachedAvatarUrl`() throws -> String? { + public func cachedAvatarUrl() throws -> String? { if let error = cachedAvatarUrlThrowableError { throw error } @@ -90,7 +90,7 @@ class SDKClientMock: SDKClientProtocol { return cachedAvatarUrlReturnValue } } - //MARK: - `createRoom` + //MARK: - createRoom public var createRoomRequestThrowableError: Error? public var createRoomRequestCallsCount = 0 @@ -102,20 +102,20 @@ class SDKClientMock: SDKClientProtocol { public var createRoomRequestReturnValue: String! public var createRoomRequestClosure: ((CreateRoomParameters) throws -> String)? - public func `createRoom`(`request`: CreateRoomParameters) throws -> String { + public func createRoom(request: CreateRoomParameters) throws -> String { if let error = createRoomRequestThrowableError { throw error } createRoomRequestCallsCount += 1 createRoomRequestReceivedRequest = request - createRoomRequestReceivedInvocations.append(`request`) + createRoomRequestReceivedInvocations.append(request) if let createRoomRequestClosure = createRoomRequestClosure { - return try createRoomRequestClosure(`request`) + return try createRoomRequestClosure(request) } else { return createRoomRequestReturnValue } } - //MARK: - `deviceId` + //MARK: - deviceId public var deviceIdThrowableError: Error? public var deviceIdCallsCount = 0 @@ -125,7 +125,7 @@ class SDKClientMock: SDKClientProtocol { public var deviceIdReturnValue: String! public var deviceIdClosure: (() throws -> String)? - public func `deviceId`() throws -> String { + public func deviceId() throws -> String { if let error = deviceIdThrowableError { throw error } @@ -136,7 +136,7 @@ class SDKClientMock: SDKClientProtocol { return deviceIdReturnValue } } - //MARK: - `displayName` + //MARK: - displayName public var displayNameThrowableError: Error? public var displayNameCallsCount = 0 @@ -146,7 +146,7 @@ class SDKClientMock: SDKClientProtocol { public var displayNameReturnValue: String! public var displayNameClosure: (() throws -> String)? - public func `displayName`() throws -> String { + public func displayName() throws -> String { if let error = displayNameThrowableError { throw error } @@ -157,7 +157,7 @@ class SDKClientMock: SDKClientProtocol { return displayNameReturnValue } } - //MARK: - `getDmRoom` + //MARK: - getDmRoom public var getDmRoomUserIdThrowableError: Error? public var getDmRoomUserIdCallsCount = 0 @@ -169,20 +169,20 @@ class SDKClientMock: SDKClientProtocol { public var getDmRoomUserIdReturnValue: Room? public var getDmRoomUserIdClosure: ((String) throws -> Room?)? - public func `getDmRoom`(`userId`: String) throws -> Room? { + public func getDmRoom(userId: String) throws -> Room? { if let error = getDmRoomUserIdThrowableError { throw error } getDmRoomUserIdCallsCount += 1 getDmRoomUserIdReceivedUserId = userId - getDmRoomUserIdReceivedInvocations.append(`userId`) + getDmRoomUserIdReceivedInvocations.append(userId) if let getDmRoomUserIdClosure = getDmRoomUserIdClosure { - return try getDmRoomUserIdClosure(`userId`) + return try getDmRoomUserIdClosure(userId) } else { return getDmRoomUserIdReturnValue } } - //MARK: - `getMediaContent` + //MARK: - getMediaContent public var getMediaContentMediaSourceThrowableError: Error? public var getMediaContentMediaSourceCallsCount = 0 @@ -194,32 +194,32 @@ class SDKClientMock: SDKClientProtocol { public var getMediaContentMediaSourceReturnValue: [UInt8]! public var getMediaContentMediaSourceClosure: ((MediaSource) throws -> [UInt8])? - public func `getMediaContent`(`mediaSource`: MediaSource) throws -> [UInt8] { + public func getMediaContent(mediaSource: MediaSource) throws -> [UInt8] { if let error = getMediaContentMediaSourceThrowableError { throw error } getMediaContentMediaSourceCallsCount += 1 getMediaContentMediaSourceReceivedMediaSource = mediaSource - getMediaContentMediaSourceReceivedInvocations.append(`mediaSource`) + getMediaContentMediaSourceReceivedInvocations.append(mediaSource) if let getMediaContentMediaSourceClosure = getMediaContentMediaSourceClosure { - return try getMediaContentMediaSourceClosure(`mediaSource`) + return try getMediaContentMediaSourceClosure(mediaSource) } else { return getMediaContentMediaSourceReturnValue } } - //MARK: - `getMediaFile` + //MARK: - getMediaFile public var getMediaFileMediaSourceBodyMimeTypeTempDirThrowableError: Error? public var getMediaFileMediaSourceBodyMimeTypeTempDirCallsCount = 0 public var getMediaFileMediaSourceBodyMimeTypeTempDirCalled: Bool { return getMediaFileMediaSourceBodyMimeTypeTempDirCallsCount > 0 } - public var getMediaFileMediaSourceBodyMimeTypeTempDirReceivedArguments: (`mediaSource`: MediaSource, `body`: String?, `mimeType`: String, `tempDir`: String?)? - public var getMediaFileMediaSourceBodyMimeTypeTempDirReceivedInvocations: [(`mediaSource`: MediaSource, `body`: String?, `mimeType`: String, `tempDir`: String?)] = [] + public var getMediaFileMediaSourceBodyMimeTypeTempDirReceivedArguments: (mediaSource: MediaSource, body: String?, mimeType: String, tempDir: String?)? + public var getMediaFileMediaSourceBodyMimeTypeTempDirReceivedInvocations: [(mediaSource: MediaSource, body: String?, mimeType: String, tempDir: String?)] = [] public var getMediaFileMediaSourceBodyMimeTypeTempDirReturnValue: MediaFileHandle! public var getMediaFileMediaSourceBodyMimeTypeTempDirClosure: ((MediaSource, String?, String, String?) throws -> MediaFileHandle)? - public func `getMediaFile`(`mediaSource`: MediaSource, `body`: String?, `mimeType`: String, `tempDir`: String?) throws -> MediaFileHandle { + public func getMediaFile(mediaSource: MediaSource, body: String?, mimeType: String, tempDir: String?) throws -> MediaFileHandle { if let error = getMediaFileMediaSourceBodyMimeTypeTempDirThrowableError { throw error } @@ -227,24 +227,24 @@ class SDKClientMock: SDKClientProtocol { getMediaFileMediaSourceBodyMimeTypeTempDirReceivedArguments = (mediaSource: mediaSource, body: body, mimeType: mimeType, tempDir: tempDir) getMediaFileMediaSourceBodyMimeTypeTempDirReceivedInvocations.append((mediaSource: mediaSource, body: body, mimeType: mimeType, tempDir: tempDir)) if let getMediaFileMediaSourceBodyMimeTypeTempDirClosure = getMediaFileMediaSourceBodyMimeTypeTempDirClosure { - return try getMediaFileMediaSourceBodyMimeTypeTempDirClosure(`mediaSource`, `body`, `mimeType`, `tempDir`) + return try getMediaFileMediaSourceBodyMimeTypeTempDirClosure(mediaSource, body, mimeType, tempDir) } else { return getMediaFileMediaSourceBodyMimeTypeTempDirReturnValue } } - //MARK: - `getMediaThumbnail` + //MARK: - getMediaThumbnail public var getMediaThumbnailMediaSourceWidthHeightThrowableError: Error? public var getMediaThumbnailMediaSourceWidthHeightCallsCount = 0 public var getMediaThumbnailMediaSourceWidthHeightCalled: Bool { return getMediaThumbnailMediaSourceWidthHeightCallsCount > 0 } - public var getMediaThumbnailMediaSourceWidthHeightReceivedArguments: (`mediaSource`: MediaSource, `width`: UInt64, `height`: UInt64)? - public var getMediaThumbnailMediaSourceWidthHeightReceivedInvocations: [(`mediaSource`: MediaSource, `width`: UInt64, `height`: UInt64)] = [] + public var getMediaThumbnailMediaSourceWidthHeightReceivedArguments: (mediaSource: MediaSource, width: UInt64, height: UInt64)? + public var getMediaThumbnailMediaSourceWidthHeightReceivedInvocations: [(mediaSource: MediaSource, width: UInt64, height: UInt64)] = [] public var getMediaThumbnailMediaSourceWidthHeightReturnValue: [UInt8]! public var getMediaThumbnailMediaSourceWidthHeightClosure: ((MediaSource, UInt64, UInt64) throws -> [UInt8])? - public func `getMediaThumbnail`(`mediaSource`: MediaSource, `width`: UInt64, `height`: UInt64) throws -> [UInt8] { + public func getMediaThumbnail(mediaSource: MediaSource, width: UInt64, height: UInt64) throws -> [UInt8] { if let error = getMediaThumbnailMediaSourceWidthHeightThrowableError { throw error } @@ -252,12 +252,12 @@ class SDKClientMock: SDKClientProtocol { getMediaThumbnailMediaSourceWidthHeightReceivedArguments = (mediaSource: mediaSource, width: width, height: height) getMediaThumbnailMediaSourceWidthHeightReceivedInvocations.append((mediaSource: mediaSource, width: width, height: height)) if let getMediaThumbnailMediaSourceWidthHeightClosure = getMediaThumbnailMediaSourceWidthHeightClosure { - return try getMediaThumbnailMediaSourceWidthHeightClosure(`mediaSource`, `width`, `height`) + return try getMediaThumbnailMediaSourceWidthHeightClosure(mediaSource, width, height) } else { return getMediaThumbnailMediaSourceWidthHeightReturnValue } } - //MARK: - `getNotificationSettings` + //MARK: - getNotificationSettings public var getNotificationSettingsCallsCount = 0 public var getNotificationSettingsCalled: Bool { @@ -266,7 +266,7 @@ class SDKClientMock: SDKClientProtocol { public var getNotificationSettingsReturnValue: NotificationSettings! public var getNotificationSettingsClosure: (() -> NotificationSettings)? - public func `getNotificationSettings`() -> NotificationSettings { + public func getNotificationSettings() -> NotificationSettings { getNotificationSettingsCallsCount += 1 if let getNotificationSettingsClosure = getNotificationSettingsClosure { return getNotificationSettingsClosure() @@ -274,7 +274,7 @@ class SDKClientMock: SDKClientProtocol { return getNotificationSettingsReturnValue } } - //MARK: - `getProfile` + //MARK: - getProfile public var getProfileUserIdThrowableError: Error? public var getProfileUserIdCallsCount = 0 @@ -286,20 +286,20 @@ class SDKClientMock: SDKClientProtocol { public var getProfileUserIdReturnValue: UserProfile! public var getProfileUserIdClosure: ((String) throws -> UserProfile)? - public func `getProfile`(`userId`: String) throws -> UserProfile { + public func getProfile(userId: String) throws -> UserProfile { if let error = getProfileUserIdThrowableError { throw error } getProfileUserIdCallsCount += 1 getProfileUserIdReceivedUserId = userId - getProfileUserIdReceivedInvocations.append(`userId`) + getProfileUserIdReceivedInvocations.append(userId) if let getProfileUserIdClosure = getProfileUserIdClosure { - return try getProfileUserIdClosure(`userId`) + return try getProfileUserIdClosure(userId) } else { return getProfileUserIdReturnValue } } - //MARK: - `getSessionVerificationController` + //MARK: - getSessionVerificationController public var getSessionVerificationControllerThrowableError: Error? public var getSessionVerificationControllerCallsCount = 0 @@ -309,7 +309,7 @@ class SDKClientMock: SDKClientProtocol { public var getSessionVerificationControllerReturnValue: SessionVerificationController! public var getSessionVerificationControllerClosure: (() throws -> SessionVerificationController)? - public func `getSessionVerificationController`() throws -> SessionVerificationController { + public func getSessionVerificationController() throws -> SessionVerificationController { if let error = getSessionVerificationControllerThrowableError { throw error } @@ -320,7 +320,7 @@ class SDKClientMock: SDKClientProtocol { return getSessionVerificationControllerReturnValue } } - //MARK: - `homeserver` + //MARK: - homeserver public var homeserverCallsCount = 0 public var homeserverCalled: Bool { @@ -329,7 +329,7 @@ class SDKClientMock: SDKClientProtocol { public var homeserverReturnValue: String! public var homeserverClosure: (() -> String)? - public func `homeserver`() -> String { + public func homeserver() -> String { homeserverCallsCount += 1 if let homeserverClosure = homeserverClosure { return homeserverClosure() @@ -337,7 +337,7 @@ class SDKClientMock: SDKClientProtocol { return homeserverReturnValue } } - //MARK: - `ignoreUser` + //MARK: - ignoreUser public var ignoreUserUserIdThrowableError: Error? public var ignoreUserUserIdCallsCount = 0 @@ -348,36 +348,36 @@ class SDKClientMock: SDKClientProtocol { public var ignoreUserUserIdReceivedInvocations: [String] = [] public var ignoreUserUserIdClosure: ((String) throws -> Void)? - public func `ignoreUser`(`userId`: String) throws { + public func ignoreUser(userId: String) throws { if let error = ignoreUserUserIdThrowableError { throw error } ignoreUserUserIdCallsCount += 1 ignoreUserUserIdReceivedUserId = userId - ignoreUserUserIdReceivedInvocations.append(`userId`) - try ignoreUserUserIdClosure?(`userId`) + ignoreUserUserIdReceivedInvocations.append(userId) + try ignoreUserUserIdClosure?(userId) } - //MARK: - `login` + //MARK: - login public var loginUsernamePasswordInitialDeviceNameDeviceIdThrowableError: Error? public var loginUsernamePasswordInitialDeviceNameDeviceIdCallsCount = 0 public var loginUsernamePasswordInitialDeviceNameDeviceIdCalled: Bool { return loginUsernamePasswordInitialDeviceNameDeviceIdCallsCount > 0 } - public var loginUsernamePasswordInitialDeviceNameDeviceIdReceivedArguments: (`username`: String, `password`: String, `initialDeviceName`: String?, `deviceId`: String?)? - public var loginUsernamePasswordInitialDeviceNameDeviceIdReceivedInvocations: [(`username`: String, `password`: String, `initialDeviceName`: String?, `deviceId`: String?)] = [] + public var loginUsernamePasswordInitialDeviceNameDeviceIdReceivedArguments: (username: String, password: String, initialDeviceName: String?, deviceId: String?)? + public var loginUsernamePasswordInitialDeviceNameDeviceIdReceivedInvocations: [(username: String, password: String, initialDeviceName: String?, deviceId: String?)] = [] public var loginUsernamePasswordInitialDeviceNameDeviceIdClosure: ((String, String, String?, String?) throws -> Void)? - public func `login`(`username`: String, `password`: String, `initialDeviceName`: String?, `deviceId`: String?) throws { + public func login(username: String, password: String, initialDeviceName: String?, deviceId: String?) throws { if let error = loginUsernamePasswordInitialDeviceNameDeviceIdThrowableError { throw error } loginUsernamePasswordInitialDeviceNameDeviceIdCallsCount += 1 loginUsernamePasswordInitialDeviceNameDeviceIdReceivedArguments = (username: username, password: password, initialDeviceName: initialDeviceName, deviceId: deviceId) loginUsernamePasswordInitialDeviceNameDeviceIdReceivedInvocations.append((username: username, password: password, initialDeviceName: initialDeviceName, deviceId: deviceId)) - try loginUsernamePasswordInitialDeviceNameDeviceIdClosure?(`username`, `password`, `initialDeviceName`, `deviceId`) + try loginUsernamePasswordInitialDeviceNameDeviceIdClosure?(username, password, initialDeviceName, deviceId) } - //MARK: - `logout` + //MARK: - logout public var logoutThrowableError: Error? public var logoutCallsCount = 0 @@ -387,7 +387,7 @@ class SDKClientMock: SDKClientProtocol { public var logoutReturnValue: String? public var logoutClosure: (() throws -> String?)? - public func `logout`() throws -> String? { + public func logout() throws -> String? { if let error = logoutThrowableError { throw error } @@ -398,7 +398,7 @@ class SDKClientMock: SDKClientProtocol { return logoutReturnValue } } - //MARK: - `notificationClient` + //MARK: - notificationClient public var notificationClientThrowableError: Error? public var notificationClientCallsCount = 0 @@ -408,7 +408,7 @@ class SDKClientMock: SDKClientProtocol { public var notificationClientReturnValue: NotificationClientBuilder! public var notificationClientClosure: (() throws -> NotificationClientBuilder)? - public func `notificationClient`() throws -> NotificationClientBuilder { + public func notificationClient() throws -> NotificationClientBuilder { if let error = notificationClientThrowableError { throw error } @@ -419,7 +419,7 @@ class SDKClientMock: SDKClientProtocol { return notificationClientReturnValue } } - //MARK: - `restoreSession` + //MARK: - restoreSession public var restoreSessionSessionThrowableError: Error? public var restoreSessionSessionCallsCount = 0 @@ -430,16 +430,16 @@ class SDKClientMock: SDKClientProtocol { public var restoreSessionSessionReceivedInvocations: [Session] = [] public var restoreSessionSessionClosure: ((Session) throws -> Void)? - public func `restoreSession`(`session`: Session) throws { + public func restoreSession(session: Session) throws { if let error = restoreSessionSessionThrowableError { throw error } restoreSessionSessionCallsCount += 1 restoreSessionSessionReceivedSession = session - restoreSessionSessionReceivedInvocations.append(`session`) - try restoreSessionSessionClosure?(`session`) + restoreSessionSessionReceivedInvocations.append(session) + try restoreSessionSessionClosure?(session) } - //MARK: - `rooms` + //MARK: - rooms public var roomsCallsCount = 0 public var roomsCalled: Bool { @@ -448,7 +448,7 @@ class SDKClientMock: SDKClientProtocol { public var roomsReturnValue: [Room]! public var roomsClosure: (() -> [Room])? - public func `rooms`() -> [Room] { + public func rooms() -> [Room] { roomsCallsCount += 1 if let roomsClosure = roomsClosure { return roomsClosure() @@ -456,19 +456,19 @@ class SDKClientMock: SDKClientProtocol { return roomsReturnValue } } - //MARK: - `searchUsers` + //MARK: - searchUsers public var searchUsersSearchTermLimitThrowableError: Error? public var searchUsersSearchTermLimitCallsCount = 0 public var searchUsersSearchTermLimitCalled: Bool { return searchUsersSearchTermLimitCallsCount > 0 } - public var searchUsersSearchTermLimitReceivedArguments: (`searchTerm`: String, `limit`: UInt64)? - public var searchUsersSearchTermLimitReceivedInvocations: [(`searchTerm`: String, `limit`: UInt64)] = [] + public var searchUsersSearchTermLimitReceivedArguments: (searchTerm: String, limit: UInt64)? + public var searchUsersSearchTermLimitReceivedInvocations: [(searchTerm: String, limit: UInt64)] = [] public var searchUsersSearchTermLimitReturnValue: SearchUsersResults! public var searchUsersSearchTermLimitClosure: ((String, UInt64) throws -> SearchUsersResults)? - public func `searchUsers`(`searchTerm`: String, `limit`: UInt64) throws -> SearchUsersResults { + public func searchUsers(searchTerm: String, limit: UInt64) throws -> SearchUsersResults { if let error = searchUsersSearchTermLimitThrowableError { throw error } @@ -476,12 +476,12 @@ class SDKClientMock: SDKClientProtocol { searchUsersSearchTermLimitReceivedArguments = (searchTerm: searchTerm, limit: limit) searchUsersSearchTermLimitReceivedInvocations.append((searchTerm: searchTerm, limit: limit)) if let searchUsersSearchTermLimitClosure = searchUsersSearchTermLimitClosure { - return try searchUsersSearchTermLimitClosure(`searchTerm`, `limit`) + return try searchUsersSearchTermLimitClosure(searchTerm, limit) } else { return searchUsersSearchTermLimitReturnValue } } - //MARK: - `session` + //MARK: - session public var sessionThrowableError: Error? public var sessionCallsCount = 0 @@ -491,7 +491,7 @@ class SDKClientMock: SDKClientProtocol { public var sessionReturnValue: Session! public var sessionClosure: (() throws -> Session)? - public func `session`() throws -> Session { + public func session() throws -> Session { if let error = sessionThrowableError { throw error } @@ -502,27 +502,27 @@ class SDKClientMock: SDKClientProtocol { return sessionReturnValue } } - //MARK: - `setAccountData` + //MARK: - setAccountData public var setAccountDataEventTypeContentThrowableError: Error? public var setAccountDataEventTypeContentCallsCount = 0 public var setAccountDataEventTypeContentCalled: Bool { return setAccountDataEventTypeContentCallsCount > 0 } - public var setAccountDataEventTypeContentReceivedArguments: (`eventType`: String, `content`: String)? - public var setAccountDataEventTypeContentReceivedInvocations: [(`eventType`: String, `content`: String)] = [] + public var setAccountDataEventTypeContentReceivedArguments: (eventType: String, content: String)? + public var setAccountDataEventTypeContentReceivedInvocations: [(eventType: String, content: String)] = [] public var setAccountDataEventTypeContentClosure: ((String, String) throws -> Void)? - public func `setAccountData`(`eventType`: String, `content`: String) throws { + public func setAccountData(eventType: String, content: String) throws { if let error = setAccountDataEventTypeContentThrowableError { throw error } setAccountDataEventTypeContentCallsCount += 1 setAccountDataEventTypeContentReceivedArguments = (eventType: eventType, content: content) setAccountDataEventTypeContentReceivedInvocations.append((eventType: eventType, content: content)) - try setAccountDataEventTypeContentClosure?(`eventType`, `content`) + try setAccountDataEventTypeContentClosure?(eventType, content) } - //MARK: - `setDelegate` + //MARK: - setDelegate public var setDelegateDelegateCallsCount = 0 public var setDelegateDelegateCalled: Bool { @@ -532,13 +532,13 @@ class SDKClientMock: SDKClientProtocol { public var setDelegateDelegateReceivedInvocations: [ClientDelegate?] = [] public var setDelegateDelegateClosure: ((ClientDelegate?) -> Void)? - public func `setDelegate`(`delegate`: ClientDelegate?) { + public func setDelegate(delegate: ClientDelegate?) { setDelegateDelegateCallsCount += 1 setDelegateDelegateReceivedDelegate = delegate - setDelegateDelegateReceivedInvocations.append(`delegate`) - setDelegateDelegateClosure?(`delegate`) + setDelegateDelegateReceivedInvocations.append(delegate) + setDelegateDelegateClosure?(delegate) } - //MARK: - `setDisplayName` + //MARK: - setDisplayName public var setDisplayNameNameThrowableError: Error? public var setDisplayNameNameCallsCount = 0 @@ -549,36 +549,36 @@ class SDKClientMock: SDKClientProtocol { public var setDisplayNameNameReceivedInvocations: [String] = [] public var setDisplayNameNameClosure: ((String) throws -> Void)? - public func `setDisplayName`(`name`: String) throws { + public func setDisplayName(name: String) throws { if let error = setDisplayNameNameThrowableError { throw error } setDisplayNameNameCallsCount += 1 setDisplayNameNameReceivedName = name - setDisplayNameNameReceivedInvocations.append(`name`) - try setDisplayNameNameClosure?(`name`) + setDisplayNameNameReceivedInvocations.append(name) + try setDisplayNameNameClosure?(name) } - //MARK: - `setPusher` + //MARK: - setPusher public var setPusherIdentifiersKindAppDisplayNameDeviceDisplayNameProfileTagLangThrowableError: Error? public var setPusherIdentifiersKindAppDisplayNameDeviceDisplayNameProfileTagLangCallsCount = 0 public var setPusherIdentifiersKindAppDisplayNameDeviceDisplayNameProfileTagLangCalled: Bool { return setPusherIdentifiersKindAppDisplayNameDeviceDisplayNameProfileTagLangCallsCount > 0 } - public var setPusherIdentifiersKindAppDisplayNameDeviceDisplayNameProfileTagLangReceivedArguments: (`identifiers`: PusherIdentifiers, `kind`: PusherKind, `appDisplayName`: String, `deviceDisplayName`: String, `profileTag`: String?, `lang`: String)? - public var setPusherIdentifiersKindAppDisplayNameDeviceDisplayNameProfileTagLangReceivedInvocations: [(`identifiers`: PusherIdentifiers, `kind`: PusherKind, `appDisplayName`: String, `deviceDisplayName`: String, `profileTag`: String?, `lang`: String)] = [] + public var setPusherIdentifiersKindAppDisplayNameDeviceDisplayNameProfileTagLangReceivedArguments: (identifiers: PusherIdentifiers, kind: PusherKind, appDisplayName: String, deviceDisplayName: String, profileTag: String?, lang: String)? + public var setPusherIdentifiersKindAppDisplayNameDeviceDisplayNameProfileTagLangReceivedInvocations: [(identifiers: PusherIdentifiers, kind: PusherKind, appDisplayName: String, deviceDisplayName: String, profileTag: String?, lang: String)] = [] public var setPusherIdentifiersKindAppDisplayNameDeviceDisplayNameProfileTagLangClosure: ((PusherIdentifiers, PusherKind, String, String, String?, String) throws -> Void)? - public func `setPusher`(`identifiers`: PusherIdentifiers, `kind`: PusherKind, `appDisplayName`: String, `deviceDisplayName`: String, `profileTag`: String?, `lang`: String) throws { + public func setPusher(identifiers: PusherIdentifiers, kind: PusherKind, appDisplayName: String, deviceDisplayName: String, profileTag: String?, lang: String) throws { if let error = setPusherIdentifiersKindAppDisplayNameDeviceDisplayNameProfileTagLangThrowableError { throw error } setPusherIdentifiersKindAppDisplayNameDeviceDisplayNameProfileTagLangCallsCount += 1 setPusherIdentifiersKindAppDisplayNameDeviceDisplayNameProfileTagLangReceivedArguments = (identifiers: identifiers, kind: kind, appDisplayName: appDisplayName, deviceDisplayName: deviceDisplayName, profileTag: profileTag, lang: lang) setPusherIdentifiersKindAppDisplayNameDeviceDisplayNameProfileTagLangReceivedInvocations.append((identifiers: identifiers, kind: kind, appDisplayName: appDisplayName, deviceDisplayName: deviceDisplayName, profileTag: profileTag, lang: lang)) - try setPusherIdentifiersKindAppDisplayNameDeviceDisplayNameProfileTagLangClosure?(`identifiers`, `kind`, `appDisplayName`, `deviceDisplayName`, `profileTag`, `lang`) + try setPusherIdentifiersKindAppDisplayNameDeviceDisplayNameProfileTagLangClosure?(identifiers, kind, appDisplayName, deviceDisplayName, profileTag, lang) } - //MARK: - `syncService` + //MARK: - syncService public var syncServiceCallsCount = 0 public var syncServiceCalled: Bool { @@ -587,7 +587,7 @@ class SDKClientMock: SDKClientProtocol { public var syncServiceReturnValue: SyncServiceBuilder! public var syncServiceClosure: (() -> SyncServiceBuilder)? - public func `syncService`() -> SyncServiceBuilder { + public func syncService() -> SyncServiceBuilder { syncServiceCallsCount += 1 if let syncServiceClosure = syncServiceClosure { return syncServiceClosure() @@ -595,7 +595,7 @@ class SDKClientMock: SDKClientProtocol { return syncServiceReturnValue } } - //MARK: - `unignoreUser` + //MARK: - unignoreUser public var unignoreUserUserIdThrowableError: Error? public var unignoreUserUserIdCallsCount = 0 @@ -606,28 +606,28 @@ class SDKClientMock: SDKClientProtocol { public var unignoreUserUserIdReceivedInvocations: [String] = [] public var unignoreUserUserIdClosure: ((String) throws -> Void)? - public func `unignoreUser`(`userId`: String) throws { + public func unignoreUser(userId: String) throws { if let error = unignoreUserUserIdThrowableError { throw error } unignoreUserUserIdCallsCount += 1 unignoreUserUserIdReceivedUserId = userId - unignoreUserUserIdReceivedInvocations.append(`userId`) - try unignoreUserUserIdClosure?(`userId`) + unignoreUserUserIdReceivedInvocations.append(userId) + try unignoreUserUserIdClosure?(userId) } - //MARK: - `uploadMedia` + //MARK: - uploadMedia public var uploadMediaMimeTypeDataProgressWatcherThrowableError: Error? public var uploadMediaMimeTypeDataProgressWatcherCallsCount = 0 public var uploadMediaMimeTypeDataProgressWatcherCalled: Bool { return uploadMediaMimeTypeDataProgressWatcherCallsCount > 0 } - public var uploadMediaMimeTypeDataProgressWatcherReceivedArguments: (`mimeType`: String, `data`: [UInt8], `progressWatcher`: ProgressWatcher?)? - public var uploadMediaMimeTypeDataProgressWatcherReceivedInvocations: [(`mimeType`: String, `data`: [UInt8], `progressWatcher`: ProgressWatcher?)] = [] + public var uploadMediaMimeTypeDataProgressWatcherReceivedArguments: (mimeType: String, data: [UInt8], progressWatcher: ProgressWatcher?)? + public var uploadMediaMimeTypeDataProgressWatcherReceivedInvocations: [(mimeType: String, data: [UInt8], progressWatcher: ProgressWatcher?)] = [] public var uploadMediaMimeTypeDataProgressWatcherReturnValue: String! public var uploadMediaMimeTypeDataProgressWatcherClosure: ((String, [UInt8], ProgressWatcher?) throws -> String)? - public func `uploadMedia`(`mimeType`: String, `data`: [UInt8], `progressWatcher`: ProgressWatcher?) throws -> String { + public func uploadMedia(mimeType: String, data: [UInt8], progressWatcher: ProgressWatcher?) throws -> String { if let error = uploadMediaMimeTypeDataProgressWatcherThrowableError { throw error } @@ -635,12 +635,12 @@ class SDKClientMock: SDKClientProtocol { uploadMediaMimeTypeDataProgressWatcherReceivedArguments = (mimeType: mimeType, data: data, progressWatcher: progressWatcher) uploadMediaMimeTypeDataProgressWatcherReceivedInvocations.append((mimeType: mimeType, data: data, progressWatcher: progressWatcher)) if let uploadMediaMimeTypeDataProgressWatcherClosure = uploadMediaMimeTypeDataProgressWatcherClosure { - return try uploadMediaMimeTypeDataProgressWatcherClosure(`mimeType`, `data`, `progressWatcher`) + return try uploadMediaMimeTypeDataProgressWatcherClosure(mimeType, data, progressWatcher) } else { return uploadMediaMimeTypeDataProgressWatcherReturnValue } } - //MARK: - `userId` + //MARK: - userId public var userIdThrowableError: Error? public var userIdCallsCount = 0 @@ -650,7 +650,7 @@ class SDKClientMock: SDKClientProtocol { public var userIdReturnValue: String! public var userIdClosure: (() throws -> String)? - public func `userId`() throws -> String { + public func userId() throws -> String { if let error = userIdThrowableError { throw error } diff --git a/ElementX/Sources/Mocks/RoomProxyMock.swift b/ElementX/Sources/Mocks/RoomProxyMock.swift index c0a3c1cb2..15e91ee07 100644 --- a/ElementX/Sources/Mocks/RoomProxyMock.swift +++ b/ElementX/Sources/Mocks/RoomProxyMock.swift @@ -74,7 +74,7 @@ extension RoomProxyMock { updateMembersClosure = { } acceptInvitationClosure = { .success(()) } - underlyingUpdatesPublisher = Empty(completeImmediately: false).eraseToAnyPublisher() + underlyingStateUpdatesPublisher = Empty(completeImmediately: false).eraseToAnyPublisher() setNameClosure = { _ in .success(()) } setTopicClosure = { _ in .success(()) } getMemberUserIDReturnValue = .success(configuration.memberForID) diff --git a/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenViewModel.swift b/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenViewModel.swift index ca647dcf3..3ff6a2384 100644 --- a/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenViewModel.swift +++ b/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenViewModel.swift @@ -118,7 +118,7 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr // MARK: - Private private func setupRoomSubscription() { - roomProxy.updatesPublisher + roomProxy.stateUpdatesPublisher .throttle(for: .milliseconds(200), scheduler: DispatchQueue.main, latest: true) .sink { [weak self] _ in guard let self else { return } diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift index 0c92bdaba..73982a67a 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift @@ -193,7 +193,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol .store(in: &cancellables) roomProxy - .updatesPublisher + .stateUpdatesPublisher .throttle(for: .seconds(1), scheduler: DispatchQueue.main, latest: true) .sink { [weak self] _ in guard let self else { return } diff --git a/ElementX/Sources/Services/Room/RoomProxy.swift b/ElementX/Sources/Services/Room/RoomProxy.swift index cf114bdf3..d3d2a911c 100644 --- a/ElementX/Sources/Services/Room/RoomProxy.swift +++ b/ElementX/Sources/Services/Room/RoomProxy.swift @@ -36,6 +36,7 @@ class RoomProxy: RoomProxyProtocol { private var roomTimelineObservationToken: TaskHandle? private var backPaginationStateObservationToken: TaskHandle? + private var roomInfoObservationToken: TaskHandle? private let backPaginationStateSubject = PassthroughSubject() private let membersSubject = CurrentValueSubject<[RoomMemberProxyProtocol], Never>([]) @@ -46,9 +47,12 @@ class RoomProxy: RoomProxyProtocol { } private var timelineListener: RoomTimelineListener? - private let updatesSubject = PassthroughSubject<[TimelineDiff], Never>() - var updatesPublisher: AnyPublisher<[TimelineDiff], Never> { - updatesSubject.eraseToAnyPublisher() + + private let timelineUpdatesSubject = PassthroughSubject<[TimelineDiff], Never>() + + private let stateUpdatesSubject = PassthroughSubject() + var stateUpdatesPublisher: AnyPublisher { + stateUpdatesSubject.eraseToAnyPublisher() } var innerTimelineProvider: RoomTimelineProviderProtocol! @@ -94,7 +98,7 @@ class RoomProxy: RoomProxyProtocol { roomListItem.subscribe(settings: settings) let timelineListener = RoomTimelineListener { [weak self] timelineDiffs in - self?.updatesSubject.send(timelineDiffs) + self?.timelineUpdatesSubject.send(timelineDiffs) } self.timelineListener = timelineListener @@ -104,8 +108,10 @@ class RoomProxy: RoomProxyProtocol { subscribeToBackpagination() + subscribeToRoomStateUpdates() + innerTimelineProvider = await RoomTimelineProvider(currentItems: result.items, - updatePublisher: updatesPublisher, + updatePublisher: timelineUpdatesSubject.eraseToAnyPublisher(), backPaginationStatePublisher: backPaginationStateSubject.eraseToAnyPublisher()) } @@ -697,6 +703,13 @@ class RoomProxy: RoomProxyProtocol { MXLog.error("Failed to subscribe to back pagination state with error: \(error)") } } + + private func subscribeToRoomStateUpdates() { + roomInfoObservationToken = room.subscribeToRoomInfoUpdates(listener: RoomInfoUpdateListener { [weak self] in + MXLog.info("Received room info update") + self?.stateUpdatesSubject.send(()) + }) + } } private final class RoomTimelineListener: TimelineListener { @@ -736,3 +749,15 @@ private final class RoomBackpaginationStatusListener: BackPaginationStatusListen onUpdateClosure(status) } } + +private final class RoomInfoUpdateListener: RoomInfoListener { + private let onUpdateClosure: () -> Void + + init(_ onUpdateClosure: @escaping () -> Void) { + self.onUpdateClosure = onUpdateClosure + } + + func call(roomInfo: RoomInfo) { + onUpdateClosure() + } +} diff --git a/ElementX/Sources/Services/Room/RoomProxyProtocol.swift b/ElementX/Sources/Services/Room/RoomProxyProtocol.swift index 6b771cb92..b954e38d3 100644 --- a/ElementX/Sources/Services/Room/RoomProxyProtocol.swift +++ b/ElementX/Sources/Services/Room/RoomProxyProtocol.swift @@ -72,9 +72,9 @@ protocol RoomProxyProtocol { var activeMembersCount: Int { get } - /// Publishes the room's updates. + /// Publishes room state updates /// The thread on which this publisher sends the output isn't defined. - var updatesPublisher: AnyPublisher<[TimelineDiff], Never> { get } + var stateUpdatesPublisher: AnyPublisher { get } var timelineProvider: RoomTimelineProviderProtocol { get }