mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Generating SDK Mocks through the usage of swift run tools generate-sdk-mocks (#982)
* basic implementation, that works for now only with the local SDK * replaced a handmade mock with a generated mock
This commit is contained in:
@@ -1094,10 +1094,10 @@ class UserDiscoveryServiceMock: UserDiscoveryServiceProtocol {
|
||||
}
|
||||
var searchProfilesWithReceivedSearchQuery: String?
|
||||
var searchProfilesWithReceivedInvocations: [String] = []
|
||||
var searchProfilesWithReturnValue: Result<[UserProfile], UserDiscoveryErrorType>!
|
||||
var searchProfilesWithClosure: ((String) async -> Result<[UserProfile], UserDiscoveryErrorType>)?
|
||||
var searchProfilesWithReturnValue: Result<[UserProfileProxy], UserDiscoveryErrorType>!
|
||||
var searchProfilesWithClosure: ((String) async -> Result<[UserProfileProxy], UserDiscoveryErrorType>)?
|
||||
|
||||
func searchProfiles(with searchQuery: String) async -> Result<[UserProfile], UserDiscoveryErrorType> {
|
||||
func searchProfiles(with searchQuery: String) async -> Result<[UserProfileProxy], UserDiscoveryErrorType> {
|
||||
searchProfilesWithCallsCount += 1
|
||||
searchProfilesWithReceivedSearchQuery = searchQuery
|
||||
searchProfilesWithReceivedInvocations.append(searchQuery)
|
||||
@@ -1113,10 +1113,10 @@ class UserDiscoveryServiceMock: UserDiscoveryServiceProtocol {
|
||||
var fetchSuggestionsCalled: Bool {
|
||||
return fetchSuggestionsCallsCount > 0
|
||||
}
|
||||
var fetchSuggestionsReturnValue: Result<[UserProfile], UserDiscoveryErrorType>!
|
||||
var fetchSuggestionsClosure: (() async -> Result<[UserProfile], UserDiscoveryErrorType>)?
|
||||
var fetchSuggestionsReturnValue: Result<[UserProfileProxy], UserDiscoveryErrorType>!
|
||||
var fetchSuggestionsClosure: (() async -> Result<[UserProfileProxy], UserDiscoveryErrorType>)?
|
||||
|
||||
func fetchSuggestions() async -> Result<[UserProfile], UserDiscoveryErrorType> {
|
||||
func fetchSuggestions() async -> Result<[UserProfileProxy], UserDiscoveryErrorType> {
|
||||
fetchSuggestionsCallsCount += 1
|
||||
if let fetchSuggestionsClosure = fetchSuggestionsClosure {
|
||||
return await fetchSuggestionsClosure()
|
||||
|
||||
@@ -0,0 +1,646 @@
|
||||
// Generated using Sourcery 2.0.2 — https://github.com/krzysztofzablocki/Sourcery
|
||||
// DO NOT EDIT
|
||||
|
||||
// swiftlint:disable all
|
||||
import Foundation
|
||||
import MatrixRustSDK
|
||||
class SDKClientMock: SDKClientProtocol {
|
||||
|
||||
//MARK: - `accountData`
|
||||
|
||||
public var accountDataEventTypeThrowableError: Error?
|
||||
public var accountDataEventTypeCallsCount = 0
|
||||
public var accountDataEventTypeCalled: Bool {
|
||||
return accountDataEventTypeCallsCount > 0
|
||||
}
|
||||
public var accountDataEventTypeReceivedEventType: String?
|
||||
public var accountDataEventTypeReceivedInvocations: [String] = []
|
||||
public var accountDataEventTypeReturnValue: String?
|
||||
public var accountDataEventTypeClosure: ((String) throws -> String?)?
|
||||
|
||||
public func `accountData`(`eventType`: String) throws -> String? {
|
||||
if let error = accountDataEventTypeThrowableError {
|
||||
throw error
|
||||
}
|
||||
accountDataEventTypeCallsCount += 1
|
||||
accountDataEventTypeReceivedEventType = eventType
|
||||
accountDataEventTypeReceivedInvocations.append(`eventType`)
|
||||
if let accountDataEventTypeClosure = accountDataEventTypeClosure {
|
||||
return try accountDataEventTypeClosure(`eventType`)
|
||||
} else {
|
||||
return accountDataEventTypeReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - `avatarUrl`
|
||||
|
||||
public var avatarUrlThrowableError: Error?
|
||||
public var avatarUrlCallsCount = 0
|
||||
public var avatarUrlCalled: Bool {
|
||||
return avatarUrlCallsCount > 0
|
||||
}
|
||||
public var avatarUrlReturnValue: String?
|
||||
public var avatarUrlClosure: (() throws -> String?)?
|
||||
|
||||
public func `avatarUrl`() throws -> String? {
|
||||
if let error = avatarUrlThrowableError {
|
||||
throw error
|
||||
}
|
||||
avatarUrlCallsCount += 1
|
||||
if let avatarUrlClosure = avatarUrlClosure {
|
||||
return try avatarUrlClosure()
|
||||
} else {
|
||||
return avatarUrlReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - `cachedAvatarUrl`
|
||||
|
||||
public var cachedAvatarUrlThrowableError: Error?
|
||||
public var cachedAvatarUrlCallsCount = 0
|
||||
public var cachedAvatarUrlCalled: Bool {
|
||||
return cachedAvatarUrlCallsCount > 0
|
||||
}
|
||||
public var cachedAvatarUrlReturnValue: String?
|
||||
public var cachedAvatarUrlClosure: (() throws -> String?)?
|
||||
|
||||
public func `cachedAvatarUrl`() throws -> String? {
|
||||
if let error = cachedAvatarUrlThrowableError {
|
||||
throw error
|
||||
}
|
||||
cachedAvatarUrlCallsCount += 1
|
||||
if let cachedAvatarUrlClosure = cachedAvatarUrlClosure {
|
||||
return try cachedAvatarUrlClosure()
|
||||
} else {
|
||||
return cachedAvatarUrlReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - `createRoom`
|
||||
|
||||
public var createRoomRequestThrowableError: Error?
|
||||
public var createRoomRequestCallsCount = 0
|
||||
public var createRoomRequestCalled: Bool {
|
||||
return createRoomRequestCallsCount > 0
|
||||
}
|
||||
public var createRoomRequestReceivedRequest: CreateRoomParameters?
|
||||
public var createRoomRequestReceivedInvocations: [CreateRoomParameters] = []
|
||||
public var createRoomRequestReturnValue: String!
|
||||
public var createRoomRequestClosure: ((CreateRoomParameters) throws -> String)?
|
||||
|
||||
public func `createRoom`(`request`: CreateRoomParameters) throws -> String {
|
||||
if let error = createRoomRequestThrowableError {
|
||||
throw error
|
||||
}
|
||||
createRoomRequestCallsCount += 1
|
||||
createRoomRequestReceivedRequest = request
|
||||
createRoomRequestReceivedInvocations.append(`request`)
|
||||
if let createRoomRequestClosure = createRoomRequestClosure {
|
||||
return try createRoomRequestClosure(`request`)
|
||||
} else {
|
||||
return createRoomRequestReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - `deviceId`
|
||||
|
||||
public var deviceIdThrowableError: Error?
|
||||
public var deviceIdCallsCount = 0
|
||||
public var deviceIdCalled: Bool {
|
||||
return deviceIdCallsCount > 0
|
||||
}
|
||||
public var deviceIdReturnValue: String!
|
||||
public var deviceIdClosure: (() throws -> String)?
|
||||
|
||||
public func `deviceId`() throws -> String {
|
||||
if let error = deviceIdThrowableError {
|
||||
throw error
|
||||
}
|
||||
deviceIdCallsCount += 1
|
||||
if let deviceIdClosure = deviceIdClosure {
|
||||
return try deviceIdClosure()
|
||||
} else {
|
||||
return deviceIdReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - `displayName`
|
||||
|
||||
public var displayNameThrowableError: Error?
|
||||
public var displayNameCallsCount = 0
|
||||
public var displayNameCalled: Bool {
|
||||
return displayNameCallsCount > 0
|
||||
}
|
||||
public var displayNameReturnValue: String!
|
||||
public var displayNameClosure: (() throws -> String)?
|
||||
|
||||
public func `displayName`() throws -> String {
|
||||
if let error = displayNameThrowableError {
|
||||
throw error
|
||||
}
|
||||
displayNameCallsCount += 1
|
||||
if let displayNameClosure = displayNameClosure {
|
||||
return try displayNameClosure()
|
||||
} else {
|
||||
return displayNameReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - `getDmRoom`
|
||||
|
||||
public var getDmRoomUserIdThrowableError: Error?
|
||||
public var getDmRoomUserIdCallsCount = 0
|
||||
public var getDmRoomUserIdCalled: Bool {
|
||||
return getDmRoomUserIdCallsCount > 0
|
||||
}
|
||||
public var getDmRoomUserIdReceivedUserId: String?
|
||||
public var getDmRoomUserIdReceivedInvocations: [String] = []
|
||||
public var getDmRoomUserIdReturnValue: Room?
|
||||
public var getDmRoomUserIdClosure: ((String) throws -> Room?)?
|
||||
|
||||
public func `getDmRoom`(`userId`: String) throws -> Room? {
|
||||
if let error = getDmRoomUserIdThrowableError {
|
||||
throw error
|
||||
}
|
||||
getDmRoomUserIdCallsCount += 1
|
||||
getDmRoomUserIdReceivedUserId = userId
|
||||
getDmRoomUserIdReceivedInvocations.append(`userId`)
|
||||
if let getDmRoomUserIdClosure = getDmRoomUserIdClosure {
|
||||
return try getDmRoomUserIdClosure(`userId`)
|
||||
} else {
|
||||
return getDmRoomUserIdReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - `getMediaContent`
|
||||
|
||||
public var getMediaContentMediaSourceThrowableError: Error?
|
||||
public var getMediaContentMediaSourceCallsCount = 0
|
||||
public var getMediaContentMediaSourceCalled: Bool {
|
||||
return getMediaContentMediaSourceCallsCount > 0
|
||||
}
|
||||
public var getMediaContentMediaSourceReceivedMediaSource: MediaSource?
|
||||
public var getMediaContentMediaSourceReceivedInvocations: [MediaSource] = []
|
||||
public var getMediaContentMediaSourceReturnValue: [UInt8]!
|
||||
public var getMediaContentMediaSourceClosure: ((MediaSource) throws -> [UInt8])?
|
||||
|
||||
public func `getMediaContent`(`mediaSource`: MediaSource) throws -> [UInt8] {
|
||||
if let error = getMediaContentMediaSourceThrowableError {
|
||||
throw error
|
||||
}
|
||||
getMediaContentMediaSourceCallsCount += 1
|
||||
getMediaContentMediaSourceReceivedMediaSource = mediaSource
|
||||
getMediaContentMediaSourceReceivedInvocations.append(`mediaSource`)
|
||||
if let getMediaContentMediaSourceClosure = getMediaContentMediaSourceClosure {
|
||||
return try getMediaContentMediaSourceClosure(`mediaSource`)
|
||||
} else {
|
||||
return getMediaContentMediaSourceReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - `getMediaFile`
|
||||
|
||||
public var getMediaFileMediaSourceBodyMimeTypeThrowableError: Error?
|
||||
public var getMediaFileMediaSourceBodyMimeTypeCallsCount = 0
|
||||
public var getMediaFileMediaSourceBodyMimeTypeCalled: Bool {
|
||||
return getMediaFileMediaSourceBodyMimeTypeCallsCount > 0
|
||||
}
|
||||
public var getMediaFileMediaSourceBodyMimeTypeReceivedArguments: (`mediaSource`: MediaSource, `body`: String?, `mimeType`: String)?
|
||||
public var getMediaFileMediaSourceBodyMimeTypeReceivedInvocations: [(`mediaSource`: MediaSource, `body`: String?, `mimeType`: String)] = []
|
||||
public var getMediaFileMediaSourceBodyMimeTypeReturnValue: MediaFileHandle!
|
||||
public var getMediaFileMediaSourceBodyMimeTypeClosure: ((MediaSource, String?, String) throws -> MediaFileHandle)?
|
||||
|
||||
public func `getMediaFile`(`mediaSource`: MediaSource, `body`: String?, `mimeType`: String) throws -> MediaFileHandle {
|
||||
if let error = getMediaFileMediaSourceBodyMimeTypeThrowableError {
|
||||
throw error
|
||||
}
|
||||
getMediaFileMediaSourceBodyMimeTypeCallsCount += 1
|
||||
getMediaFileMediaSourceBodyMimeTypeReceivedArguments = (`mediaSource`: `mediaSource`, `body`: `body`, `mimeType`: `mimeType`)
|
||||
getMediaFileMediaSourceBodyMimeTypeReceivedInvocations.append((`mediaSource`: `mediaSource`, `body`: `body`, `mimeType`: `mimeType`))
|
||||
if let getMediaFileMediaSourceBodyMimeTypeClosure = getMediaFileMediaSourceBodyMimeTypeClosure {
|
||||
return try getMediaFileMediaSourceBodyMimeTypeClosure(`mediaSource`, `body`, `mimeType`)
|
||||
} else {
|
||||
return getMediaFileMediaSourceBodyMimeTypeReturnValue
|
||||
}
|
||||
}
|
||||
//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 getMediaThumbnailMediaSourceWidthHeightReturnValue: [UInt8]!
|
||||
public var getMediaThumbnailMediaSourceWidthHeightClosure: ((MediaSource, UInt64, UInt64) throws -> [UInt8])?
|
||||
|
||||
public func `getMediaThumbnail`(`mediaSource`: MediaSource, `width`: UInt64, `height`: UInt64) throws -> [UInt8] {
|
||||
if let error = getMediaThumbnailMediaSourceWidthHeightThrowableError {
|
||||
throw error
|
||||
}
|
||||
getMediaThumbnailMediaSourceWidthHeightCallsCount += 1
|
||||
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`)
|
||||
} else {
|
||||
return getMediaThumbnailMediaSourceWidthHeightReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - `getNotificationItem`
|
||||
|
||||
public var getNotificationItemRoomIdEventIdThrowableError: Error?
|
||||
public var getNotificationItemRoomIdEventIdCallsCount = 0
|
||||
public var getNotificationItemRoomIdEventIdCalled: Bool {
|
||||
return getNotificationItemRoomIdEventIdCallsCount > 0
|
||||
}
|
||||
public var getNotificationItemRoomIdEventIdReceivedArguments: (`roomId`: String, `eventId`: String)?
|
||||
public var getNotificationItemRoomIdEventIdReceivedInvocations: [(`roomId`: String, `eventId`: String)] = []
|
||||
public var getNotificationItemRoomIdEventIdReturnValue: NotificationItem!
|
||||
public var getNotificationItemRoomIdEventIdClosure: ((String, String) throws -> NotificationItem)?
|
||||
|
||||
public func `getNotificationItem`(`roomId`: String, `eventId`: String) throws -> NotificationItem {
|
||||
if let error = getNotificationItemRoomIdEventIdThrowableError {
|
||||
throw error
|
||||
}
|
||||
getNotificationItemRoomIdEventIdCallsCount += 1
|
||||
getNotificationItemRoomIdEventIdReceivedArguments = (`roomId`: `roomId`, `eventId`: `eventId`)
|
||||
getNotificationItemRoomIdEventIdReceivedInvocations.append((`roomId`: `roomId`, `eventId`: `eventId`))
|
||||
if let getNotificationItemRoomIdEventIdClosure = getNotificationItemRoomIdEventIdClosure {
|
||||
return try getNotificationItemRoomIdEventIdClosure(`roomId`, `eventId`)
|
||||
} else {
|
||||
return getNotificationItemRoomIdEventIdReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - `getProfile`
|
||||
|
||||
public var getProfileUserIdThrowableError: Error?
|
||||
public var getProfileUserIdCallsCount = 0
|
||||
public var getProfileUserIdCalled: Bool {
|
||||
return getProfileUserIdCallsCount > 0
|
||||
}
|
||||
public var getProfileUserIdReceivedUserId: String?
|
||||
public var getProfileUserIdReceivedInvocations: [String] = []
|
||||
public var getProfileUserIdReturnValue: UserProfile!
|
||||
public var getProfileUserIdClosure: ((String) throws -> UserProfile)?
|
||||
|
||||
public func `getProfile`(`userId`: String) throws -> UserProfile {
|
||||
if let error = getProfileUserIdThrowableError {
|
||||
throw error
|
||||
}
|
||||
getProfileUserIdCallsCount += 1
|
||||
getProfileUserIdReceivedUserId = userId
|
||||
getProfileUserIdReceivedInvocations.append(`userId`)
|
||||
if let getProfileUserIdClosure = getProfileUserIdClosure {
|
||||
return try getProfileUserIdClosure(`userId`)
|
||||
} else {
|
||||
return getProfileUserIdReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - `getSessionVerificationController`
|
||||
|
||||
public var getSessionVerificationControllerThrowableError: Error?
|
||||
public var getSessionVerificationControllerCallsCount = 0
|
||||
public var getSessionVerificationControllerCalled: Bool {
|
||||
return getSessionVerificationControllerCallsCount > 0
|
||||
}
|
||||
public var getSessionVerificationControllerReturnValue: SessionVerificationController!
|
||||
public var getSessionVerificationControllerClosure: (() throws -> SessionVerificationController)?
|
||||
|
||||
public func `getSessionVerificationController`() throws -> SessionVerificationController {
|
||||
if let error = getSessionVerificationControllerThrowableError {
|
||||
throw error
|
||||
}
|
||||
getSessionVerificationControllerCallsCount += 1
|
||||
if let getSessionVerificationControllerClosure = getSessionVerificationControllerClosure {
|
||||
return try getSessionVerificationControllerClosure()
|
||||
} else {
|
||||
return getSessionVerificationControllerReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - `homeserver`
|
||||
|
||||
public var homeserverCallsCount = 0
|
||||
public var homeserverCalled: Bool {
|
||||
return homeserverCallsCount > 0
|
||||
}
|
||||
public var homeserverReturnValue: String!
|
||||
public var homeserverClosure: (() -> String)?
|
||||
|
||||
public func `homeserver`() -> String {
|
||||
homeserverCallsCount += 1
|
||||
if let homeserverClosure = homeserverClosure {
|
||||
return homeserverClosure()
|
||||
} else {
|
||||
return homeserverReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - `ignoreUser`
|
||||
|
||||
public var ignoreUserUserIdThrowableError: Error?
|
||||
public var ignoreUserUserIdCallsCount = 0
|
||||
public var ignoreUserUserIdCalled: Bool {
|
||||
return ignoreUserUserIdCallsCount > 0
|
||||
}
|
||||
public var ignoreUserUserIdReceivedUserId: String?
|
||||
public var ignoreUserUserIdReceivedInvocations: [String] = []
|
||||
public var ignoreUserUserIdClosure: ((String) throws -> Void)?
|
||||
|
||||
public func `ignoreUser`(`userId`: String) throws {
|
||||
if let error = ignoreUserUserIdThrowableError {
|
||||
throw error
|
||||
}
|
||||
ignoreUserUserIdCallsCount += 1
|
||||
ignoreUserUserIdReceivedUserId = userId
|
||||
ignoreUserUserIdReceivedInvocations.append(`userId`)
|
||||
try ignoreUserUserIdClosure?(`userId`)
|
||||
}
|
||||
//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 loginUsernamePasswordInitialDeviceNameDeviceIdClosure: ((String, String, String?, String?) throws -> Void)?
|
||||
|
||||
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`)
|
||||
}
|
||||
//MARK: - `logout`
|
||||
|
||||
public var logoutThrowableError: Error?
|
||||
public var logoutCallsCount = 0
|
||||
public var logoutCalled: Bool {
|
||||
return logoutCallsCount > 0
|
||||
}
|
||||
public var logoutClosure: (() throws -> Void)?
|
||||
|
||||
public func `logout`() throws {
|
||||
if let error = logoutThrowableError {
|
||||
throw error
|
||||
}
|
||||
logoutCallsCount += 1
|
||||
try logoutClosure?()
|
||||
}
|
||||
//MARK: - `restoreSession`
|
||||
|
||||
public var restoreSessionSessionThrowableError: Error?
|
||||
public var restoreSessionSessionCallsCount = 0
|
||||
public var restoreSessionSessionCalled: Bool {
|
||||
return restoreSessionSessionCallsCount > 0
|
||||
}
|
||||
public var restoreSessionSessionReceivedSession: Session?
|
||||
public var restoreSessionSessionReceivedInvocations: [Session] = []
|
||||
public var restoreSessionSessionClosure: ((Session) throws -> Void)?
|
||||
|
||||
public func `restoreSession`(`session`: Session) throws {
|
||||
if let error = restoreSessionSessionThrowableError {
|
||||
throw error
|
||||
}
|
||||
restoreSessionSessionCallsCount += 1
|
||||
restoreSessionSessionReceivedSession = session
|
||||
restoreSessionSessionReceivedInvocations.append(`session`)
|
||||
try restoreSessionSessionClosure?(`session`)
|
||||
}
|
||||
//MARK: - `rooms`
|
||||
|
||||
public var roomsCallsCount = 0
|
||||
public var roomsCalled: Bool {
|
||||
return roomsCallsCount > 0
|
||||
}
|
||||
public var roomsReturnValue: [Room]!
|
||||
public var roomsClosure: (() -> [Room])?
|
||||
|
||||
public func `rooms`() -> [Room] {
|
||||
roomsCallsCount += 1
|
||||
if let roomsClosure = roomsClosure {
|
||||
return roomsClosure()
|
||||
} else {
|
||||
return roomsReturnValue
|
||||
}
|
||||
}
|
||||
//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 searchUsersSearchTermLimitReturnValue: SearchUsersResults!
|
||||
public var searchUsersSearchTermLimitClosure: ((String, UInt64) throws -> SearchUsersResults)?
|
||||
|
||||
public func `searchUsers`(`searchTerm`: String, `limit`: UInt64) throws -> SearchUsersResults {
|
||||
if let error = searchUsersSearchTermLimitThrowableError {
|
||||
throw error
|
||||
}
|
||||
searchUsersSearchTermLimitCallsCount += 1
|
||||
searchUsersSearchTermLimitReceivedArguments = (`searchTerm`: `searchTerm`, `limit`: `limit`)
|
||||
searchUsersSearchTermLimitReceivedInvocations.append((`searchTerm`: `searchTerm`, `limit`: `limit`))
|
||||
if let searchUsersSearchTermLimitClosure = searchUsersSearchTermLimitClosure {
|
||||
return try searchUsersSearchTermLimitClosure(`searchTerm`, `limit`)
|
||||
} else {
|
||||
return searchUsersSearchTermLimitReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - `session`
|
||||
|
||||
public var sessionThrowableError: Error?
|
||||
public var sessionCallsCount = 0
|
||||
public var sessionCalled: Bool {
|
||||
return sessionCallsCount > 0
|
||||
}
|
||||
public var sessionReturnValue: Session!
|
||||
public var sessionClosure: (() throws -> Session)?
|
||||
|
||||
public func `session`() throws -> Session {
|
||||
if let error = sessionThrowableError {
|
||||
throw error
|
||||
}
|
||||
sessionCallsCount += 1
|
||||
if let sessionClosure = sessionClosure {
|
||||
return try sessionClosure()
|
||||
} else {
|
||||
return sessionReturnValue
|
||||
}
|
||||
}
|
||||
//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 setAccountDataEventTypeContentClosure: ((String, String) throws -> Void)?
|
||||
|
||||
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`)
|
||||
}
|
||||
//MARK: - `setDelegate`
|
||||
|
||||
public var setDelegateDelegateCallsCount = 0
|
||||
public var setDelegateDelegateCalled: Bool {
|
||||
return setDelegateDelegateCallsCount > 0
|
||||
}
|
||||
public var setDelegateDelegateReceivedDelegate: ClientDelegate?
|
||||
public var setDelegateDelegateReceivedInvocations: [ClientDelegate?] = []
|
||||
public var setDelegateDelegateClosure: ((ClientDelegate?) -> Void)?
|
||||
|
||||
public func `setDelegate`(`delegate`: ClientDelegate?) {
|
||||
setDelegateDelegateCallsCount += 1
|
||||
setDelegateDelegateReceivedDelegate = delegate
|
||||
setDelegateDelegateReceivedInvocations.append(`delegate`)
|
||||
setDelegateDelegateClosure?(`delegate`)
|
||||
}
|
||||
//MARK: - `setDisplayName`
|
||||
|
||||
public var setDisplayNameNameThrowableError: Error?
|
||||
public var setDisplayNameNameCallsCount = 0
|
||||
public var setDisplayNameNameCalled: Bool {
|
||||
return setDisplayNameNameCallsCount > 0
|
||||
}
|
||||
public var setDisplayNameNameReceivedName: String?
|
||||
public var setDisplayNameNameReceivedInvocations: [String] = []
|
||||
public var setDisplayNameNameClosure: ((String) throws -> Void)?
|
||||
|
||||
public func `setDisplayName`(`name`: String) throws {
|
||||
if let error = setDisplayNameNameThrowableError {
|
||||
throw error
|
||||
}
|
||||
setDisplayNameNameCallsCount += 1
|
||||
setDisplayNameNameReceivedName = name
|
||||
setDisplayNameNameReceivedInvocations.append(`name`)
|
||||
try setDisplayNameNameClosure?(`name`)
|
||||
}
|
||||
//MARK: - `setNotificationDelegate`
|
||||
|
||||
public var setNotificationDelegateNotificationDelegateCallsCount = 0
|
||||
public var setNotificationDelegateNotificationDelegateCalled: Bool {
|
||||
return setNotificationDelegateNotificationDelegateCallsCount > 0
|
||||
}
|
||||
public var setNotificationDelegateNotificationDelegateReceivedNotificationDelegate: NotificationDelegate?
|
||||
public var setNotificationDelegateNotificationDelegateReceivedInvocations: [NotificationDelegate?] = []
|
||||
public var setNotificationDelegateNotificationDelegateClosure: ((NotificationDelegate?) -> Void)?
|
||||
|
||||
public func `setNotificationDelegate`(`notificationDelegate`: NotificationDelegate?) {
|
||||
setNotificationDelegateNotificationDelegateCallsCount += 1
|
||||
setNotificationDelegateNotificationDelegateReceivedNotificationDelegate = notificationDelegate
|
||||
setNotificationDelegateNotificationDelegateReceivedInvocations.append(`notificationDelegate`)
|
||||
setNotificationDelegateNotificationDelegateClosure?(`notificationDelegate`)
|
||||
}
|
||||
//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 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 {
|
||||
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`)
|
||||
}
|
||||
//MARK: - `slidingSync`
|
||||
|
||||
public var slidingSyncCallsCount = 0
|
||||
public var slidingSyncCalled: Bool {
|
||||
return slidingSyncCallsCount > 0
|
||||
}
|
||||
public var slidingSyncReturnValue: SlidingSyncBuilder!
|
||||
public var slidingSyncClosure: (() -> SlidingSyncBuilder)?
|
||||
|
||||
public func `slidingSync`() -> SlidingSyncBuilder {
|
||||
slidingSyncCallsCount += 1
|
||||
if let slidingSyncClosure = slidingSyncClosure {
|
||||
return slidingSyncClosure()
|
||||
} else {
|
||||
return slidingSyncReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - `unignoreUser`
|
||||
|
||||
public var unignoreUserUserIdThrowableError: Error?
|
||||
public var unignoreUserUserIdCallsCount = 0
|
||||
public var unignoreUserUserIdCalled: Bool {
|
||||
return unignoreUserUserIdCallsCount > 0
|
||||
}
|
||||
public var unignoreUserUserIdReceivedUserId: String?
|
||||
public var unignoreUserUserIdReceivedInvocations: [String] = []
|
||||
public var unignoreUserUserIdClosure: ((String) throws -> Void)?
|
||||
|
||||
public func `unignoreUser`(`userId`: String) throws {
|
||||
if let error = unignoreUserUserIdThrowableError {
|
||||
throw error
|
||||
}
|
||||
unignoreUserUserIdCallsCount += 1
|
||||
unignoreUserUserIdReceivedUserId = userId
|
||||
unignoreUserUserIdReceivedInvocations.append(`userId`)
|
||||
try unignoreUserUserIdClosure?(`userId`)
|
||||
}
|
||||
//MARK: - `uploadMedia`
|
||||
|
||||
public var uploadMediaMimeTypeDataThrowableError: Error?
|
||||
public var uploadMediaMimeTypeDataCallsCount = 0
|
||||
public var uploadMediaMimeTypeDataCalled: Bool {
|
||||
return uploadMediaMimeTypeDataCallsCount > 0
|
||||
}
|
||||
public var uploadMediaMimeTypeDataReceivedArguments: (`mimeType`: String, `data`: [UInt8])?
|
||||
public var uploadMediaMimeTypeDataReceivedInvocations: [(`mimeType`: String, `data`: [UInt8])] = []
|
||||
public var uploadMediaMimeTypeDataReturnValue: String!
|
||||
public var uploadMediaMimeTypeDataClosure: ((String, [UInt8]) throws -> String)?
|
||||
|
||||
public func `uploadMedia`(`mimeType`: String, `data`: [UInt8]) throws -> String {
|
||||
if let error = uploadMediaMimeTypeDataThrowableError {
|
||||
throw error
|
||||
}
|
||||
uploadMediaMimeTypeDataCallsCount += 1
|
||||
uploadMediaMimeTypeDataReceivedArguments = (`mimeType`: `mimeType`, `data`: `data`)
|
||||
uploadMediaMimeTypeDataReceivedInvocations.append((`mimeType`: `mimeType`, `data`: `data`))
|
||||
if let uploadMediaMimeTypeDataClosure = uploadMediaMimeTypeDataClosure {
|
||||
return try uploadMediaMimeTypeDataClosure(`mimeType`, `data`)
|
||||
} else {
|
||||
return uploadMediaMimeTypeDataReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - `userId`
|
||||
|
||||
public var userIdThrowableError: Error?
|
||||
public var userIdCallsCount = 0
|
||||
public var userIdCalled: Bool {
|
||||
return userIdCallsCount > 0
|
||||
}
|
||||
public var userIdReturnValue: String!
|
||||
public var userIdClosure: (() throws -> String)?
|
||||
|
||||
public func `userId`() throws -> String {
|
||||
if let error = userIdThrowableError {
|
||||
throw error
|
||||
}
|
||||
userIdCallsCount += 1
|
||||
if let userIdClosure = userIdClosure {
|
||||
return try userIdClosure()
|
||||
} else {
|
||||
return userIdReturnValue
|
||||
}
|
||||
}
|
||||
}
|
||||
// swiftlint:enable all
|
||||
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// Copyright 2023 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import MatrixRustSDK
|
||||
|
||||
// sourcery: AutoMockable
|
||||
protocol SDKClientProtocol: ClientProtocol { }
|
||||
@@ -16,21 +16,21 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
extension UserProfile {
|
||||
extension UserProfileProxy {
|
||||
// Mocks
|
||||
static var mockAlice: UserProfile {
|
||||
static var mockAlice: UserProfileProxy {
|
||||
.init(userID: "@alice:matrix.org", displayName: "Alice", avatarURL: URL(staticString: "mxc://matrix.org/UcCimidcvpFvWkPzvjXMQPHA"))
|
||||
}
|
||||
|
||||
static var mockBob: UserProfile {
|
||||
static var mockBob: UserProfileProxy {
|
||||
.init(userID: "@bob:matrix.org", displayName: "Bob", avatarURL: nil)
|
||||
}
|
||||
|
||||
static var mockBobby: UserProfile {
|
||||
static var mockBobby: UserProfileProxy {
|
||||
.init(userID: "@bobby:matrix.org", displayName: "Bobby", avatarURL: nil)
|
||||
}
|
||||
|
||||
static var mockCharlie: UserProfile {
|
||||
static var mockCharlie: UserProfileProxy {
|
||||
.init(userID: "@charlie:matrix.org", displayName: "Charlie", avatarURL: nil)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import MatrixRustSDK
|
||||
import SwiftUI
|
||||
|
||||
struct UserProfileCell: View {
|
||||
let user: UserProfile
|
||||
let user: UserProfileProxy
|
||||
let membership: MembershipState?
|
||||
let imageProvider: ImageProviderProtocol?
|
||||
|
||||
|
||||
@@ -21,12 +21,12 @@ struct CreateRoomCoordinatorParameters {
|
||||
let userSession: UserSessionProtocol
|
||||
weak var userIndicatorController: UserIndicatorControllerProtocol?
|
||||
let createRoomParameters: CurrentValuePublisher<CreateRoomFlowParameters, Never>
|
||||
let selectedUsers: CurrentValuePublisher<[UserProfile], Never>
|
||||
let selectedUsers: CurrentValuePublisher<[UserProfileProxy], Never>
|
||||
}
|
||||
|
||||
enum CreateRoomCoordinatorAction {
|
||||
case openRoom(withIdentifier: String)
|
||||
case deselectUser(UserProfile)
|
||||
case deselectUser(UserProfileProxy)
|
||||
case updateDetails(CreateRoomFlowParameters)
|
||||
}
|
||||
|
||||
|
||||
@@ -23,12 +23,12 @@ enum CreateRoomScreenErrorType: Error {
|
||||
|
||||
enum CreateRoomViewModelAction {
|
||||
case openRoom(withIdentifier: String)
|
||||
case deselectUser(UserProfile)
|
||||
case deselectUser(UserProfileProxy)
|
||||
case updateDetails(CreateRoomFlowParameters)
|
||||
}
|
||||
|
||||
struct CreateRoomViewState: BindableState {
|
||||
var selectedUsers: [UserProfile]
|
||||
var selectedUsers: [UserProfileProxy]
|
||||
var bindings: CreateRoomViewStateBindings
|
||||
|
||||
var canCreateRoom: Bool {
|
||||
@@ -47,5 +47,5 @@ struct CreateRoomViewStateBindings {
|
||||
|
||||
enum CreateRoomViewAction {
|
||||
case createRoom
|
||||
case deselectUser(UserProfile)
|
||||
case deselectUser(UserProfileProxy)
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ class CreateRoomViewModel: CreateRoomViewModelType, CreateRoomViewModelProtocol
|
||||
init(userSession: UserSessionProtocol,
|
||||
userIndicatorController: UserIndicatorControllerProtocol?,
|
||||
createRoomParameters: CurrentValuePublisher<CreateRoomFlowParameters, Never>,
|
||||
selectedUsers: CurrentValuePublisher<[UserProfile], Never>) {
|
||||
selectedUsers: CurrentValuePublisher<[UserProfileProxy], Never>) {
|
||||
let parameters = createRoomParameters.value
|
||||
self.userSession = userSession
|
||||
self.userIndicatorController = userIndicatorController
|
||||
|
||||
@@ -164,7 +164,7 @@ struct CreateRoom_Previews: PreviewProvider {
|
||||
let userSession = MockUserSession(clientProxy: MockClientProxy(userID: "@userid:example.com"),
|
||||
mediaProvider: MockMediaProvider())
|
||||
let parameters = CreateRoomFlowParameters()
|
||||
let selectedUsers: [UserProfile] = [.mockAlice, .mockBob, .mockCharlie]
|
||||
let selectedUsers: [UserProfileProxy] = [.mockAlice, .mockBob, .mockCharlie]
|
||||
|
||||
return CreateRoomViewModel(userSession: userSession, userIndicatorController: nil, createRoomParameters: .init(parameters), selectedUsers: .init(selectedUsers))
|
||||
}()
|
||||
|
||||
@@ -18,7 +18,7 @@ import Combine
|
||||
import SwiftUI
|
||||
|
||||
struct InviteUsersScreenCoordinatorParameters {
|
||||
let selectedUsers: CurrentValuePublisher<[UserProfile], Never>
|
||||
let selectedUsers: CurrentValuePublisher<[UserProfileProxy], Never>
|
||||
let roomType: InviteUsersScreenRoomType
|
||||
let mediaProvider: MediaProviderProtocol
|
||||
let userDiscoveryService: UserDiscoveryServiceProtocol
|
||||
@@ -27,7 +27,7 @@ struct InviteUsersScreenCoordinatorParameters {
|
||||
enum InviteUsersScreenCoordinatorAction {
|
||||
case proceed
|
||||
case invite(users: [String])
|
||||
case toggleUser(UserProfile)
|
||||
case toggleUser(UserProfileProxy)
|
||||
}
|
||||
|
||||
final class InviteUsersScreenCoordinator: CoordinatorProtocol {
|
||||
|
||||
@@ -24,7 +24,7 @@ enum InviteUsersScreenErrorType: Error {
|
||||
enum InviteUsersScreenViewModelAction {
|
||||
case proceed
|
||||
case invite(users: [String])
|
||||
case toggleUser(UserProfile)
|
||||
case toggleUser(UserProfileProxy)
|
||||
}
|
||||
|
||||
enum InviteUsersScreenRoomType {
|
||||
@@ -37,7 +37,7 @@ struct InviteUsersScreenViewState: BindableState {
|
||||
|
||||
var usersSection: UserDiscoverySection = .init(type: .suggestions, users: [])
|
||||
|
||||
var selectedUsers: [UserProfile] = []
|
||||
var selectedUsers: [UserProfileProxy] = []
|
||||
var membershipState: [String: MembershipState] = .init()
|
||||
|
||||
var isSearching: Bool {
|
||||
@@ -50,16 +50,16 @@ struct InviteUsersScreenViewState: BindableState {
|
||||
|
||||
var scrollToLastID: String?
|
||||
|
||||
func isUserSelected(_ user: UserProfile) -> Bool {
|
||||
func isUserSelected(_ user: UserProfileProxy) -> Bool {
|
||||
isUserDisabled(user) || selectedUsers.contains { $0.userID == user.userID }
|
||||
}
|
||||
|
||||
func isUserDisabled(_ user: UserProfile) -> Bool {
|
||||
func isUserDisabled(_ user: UserProfileProxy) -> Bool {
|
||||
let membershipState = membershipState(user)
|
||||
return membershipState == .invite || membershipState == .join
|
||||
}
|
||||
|
||||
func membershipState(_ user: UserProfile) -> MembershipState? {
|
||||
func membershipState(_ user: UserProfileProxy) -> MembershipState? {
|
||||
membershipState[user.userID]
|
||||
}
|
||||
|
||||
@@ -87,5 +87,5 @@ struct InviteUsersScreenViewStateBindings {
|
||||
|
||||
enum InviteUsersScreenViewAction {
|
||||
case proceed
|
||||
case toggleUser(UserProfile)
|
||||
case toggleUser(UserProfileProxy)
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ class InviteUsersScreenViewModel: InviteUsersScreenViewModelType, InviteUsersScr
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
init(selectedUsers: CurrentValuePublisher<[UserProfile], Never>,
|
||||
init(selectedUsers: CurrentValuePublisher<[UserProfileProxy], Never>,
|
||||
roomType: InviteUsersScreenRoomType,
|
||||
mediaProvider: MediaProviderProtocol,
|
||||
userDiscoveryService: UserDiscoveryServiceProtocol) {
|
||||
@@ -85,7 +85,7 @@ class InviteUsersScreenViewModel: InviteUsersScreenViewModelType, InviteUsersScr
|
||||
@CancellableTask
|
||||
private var fetchUsersTask: Task<Void, Never>?
|
||||
|
||||
private func setupSubscriptions(selectedUsers: CurrentValuePublisher<[UserProfile], Never>) {
|
||||
private func setupSubscriptions(selectedUsers: CurrentValuePublisher<[UserProfileProxy], Never>) {
|
||||
context.$viewState
|
||||
.map(\.bindings.searchQuery)
|
||||
.debounceAndRemoveDuplicates()
|
||||
@@ -125,7 +125,7 @@ class InviteUsersScreenViewModel: InviteUsersScreenViewModelType, InviteUsersScr
|
||||
}
|
||||
}
|
||||
|
||||
private func handleResult(for sectionType: UserDiscoverySectionType, result: Result<[UserProfile], UserDiscoveryErrorType>) {
|
||||
private func handleResult(for sectionType: UserDiscoverySectionType, result: Result<[UserProfileProxy], UserDiscoveryErrorType>) {
|
||||
switch result {
|
||||
case .success(let users):
|
||||
state.usersSection = .init(type: sectionType, users: users)
|
||||
|
||||
@@ -123,7 +123,7 @@ struct InviteUsersScreen: View {
|
||||
.disabled(context.viewState.isActionDisabled)
|
||||
}
|
||||
|
||||
private func deselect(_ user: UserProfile) {
|
||||
private func deselect(_ user: UserProfileProxy) {
|
||||
context.send(viewAction: .toggleUser(user))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
import SwiftUI
|
||||
|
||||
struct InviteUsersScreenSelectedItem: View {
|
||||
let user: UserProfile
|
||||
let user: UserProfileProxy
|
||||
let imageProvider: ImageProviderProtocol?
|
||||
let dismissAction: () -> Void
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ final class RoomDetailsScreenCoordinator: CoordinatorProtocol {
|
||||
private let parameters: RoomDetailsScreenCoordinatorParameters
|
||||
private var viewModel: RoomDetailsScreenViewModelProtocol
|
||||
private var cancellables: Set<AnyCancellable> = .init()
|
||||
private let selectedUsers: CurrentValueSubject<[UserProfile], Never> = .init([])
|
||||
private let selectedUsers: CurrentValueSubject<[UserProfileProxy], Never> = .init([])
|
||||
private var navigationStackCoordinator: NavigationStackCoordinator {
|
||||
parameters.navigationStackCoordinator
|
||||
}
|
||||
@@ -142,7 +142,7 @@ final class RoomDetailsScreenCoordinator: CoordinatorProtocol {
|
||||
parameters.navigationStackCoordinator.setSheetCoordinator(userIndicatorController)
|
||||
}
|
||||
|
||||
private func toggleUser(_ user: UserProfile) {
|
||||
private func toggleUser(_ user: UserProfileProxy) {
|
||||
var selectedUsers = selectedUsers.value
|
||||
if let index = selectedUsers.firstIndex(where: { $0.userID == user.userID }) {
|
||||
selectedUsers.remove(at: index)
|
||||
|
||||
@@ -40,8 +40,8 @@ final class StartChatScreenCoordinator: CoordinatorProtocol {
|
||||
createRoomParameters.asCurrentValuePublisher()
|
||||
}
|
||||
|
||||
private let selectedUsers = CurrentValueSubject<[UserProfile], Never>([])
|
||||
private var selectedUsersPublisher: CurrentValuePublisher<[UserProfile], Never> {
|
||||
private let selectedUsers = CurrentValueSubject<[UserProfileProxy], Never>([])
|
||||
private var selectedUsersPublisher: CurrentValuePublisher<[UserProfileProxy], Never> {
|
||||
selectedUsers.asCurrentValuePublisher()
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ final class StartChatScreenCoordinator: CoordinatorProtocol {
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func toggleUser(_ user: UserProfile) {
|
||||
private func toggleUser(_ user: UserProfileProxy) {
|
||||
var selectedUsers = selectedUsers.value
|
||||
if let index = selectedUsers.firstIndex(where: { $0.userID == user.userID }) {
|
||||
selectedUsers.remove(at: index)
|
||||
|
||||
@@ -51,5 +51,5 @@ struct StartChatScreenViewStateBindings {
|
||||
enum StartChatScreenViewAction {
|
||||
case close
|
||||
case createRoom
|
||||
case selectUser(UserProfile)
|
||||
case selectUser(UserProfileProxy)
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ class StartChatScreenViewModel: StartChatScreenViewModelType, StartChatScreenVie
|
||||
}
|
||||
}
|
||||
|
||||
private func handleResult(for sectionType: UserDiscoverySectionType, result: Result<[UserProfile], UserDiscoveryErrorType>) {
|
||||
private func handleResult(for sectionType: UserDiscoverySectionType, result: Result<[UserProfileProxy], UserDiscoveryErrorType>) {
|
||||
switch result {
|
||||
case .success(let users):
|
||||
state.usersSection = .init(type: sectionType, users: users)
|
||||
@@ -126,7 +126,7 @@ class StartChatScreenViewModel: StartChatScreenViewModelType, StartChatScreenVie
|
||||
}
|
||||
}
|
||||
|
||||
private func createDirectRoom(with user: UserProfile) async {
|
||||
private func createDirectRoom(with user: UserProfileProxy) async {
|
||||
defer {
|
||||
hideLoadingIndicator()
|
||||
}
|
||||
|
||||
@@ -351,7 +351,7 @@ class ClientProxy: ClientProxyProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func searchUsers(searchTerm: String, limit: UInt) async -> Result<SearchUsersResults, ClientProxyError> {
|
||||
func searchUsers(searchTerm: String, limit: UInt) async -> Result<SearchUsersResultsProxy, ClientProxyError> {
|
||||
await Task.dispatch(on: clientQueue) {
|
||||
do {
|
||||
return try .success(.init(sdkResults: self.client.searchUsers(searchTerm: searchTerm, limit: UInt64(limit))))
|
||||
@@ -361,7 +361,7 @@ class ClientProxy: ClientProxyProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func profile(for userID: String) async -> Result<UserProfile, ClientProxyError> {
|
||||
func profile(for userID: String) async -> Result<UserProfileProxy, ClientProxyError> {
|
||||
await Task.dispatch(on: clientQueue) {
|
||||
do {
|
||||
return try .success(.init(sdkUserProfile: self.client.getProfile(userId: userID)))
|
||||
|
||||
@@ -110,7 +110,7 @@ protocol ClientProxyProtocol: AnyObject, MediaLoaderProtocol {
|
||||
|
||||
func setPusher(with configuration: PusherConfiguration) async throws
|
||||
|
||||
func searchUsers(searchTerm: String, limit: UInt) async -> Result<SearchUsersResults, ClientProxyError>
|
||||
func searchUsers(searchTerm: String, limit: UInt) async -> Result<SearchUsersResultsProxy, ClientProxyError>
|
||||
|
||||
func profile(for userID: String) async -> Result<UserProfile, ClientProxyError>
|
||||
func profile(for userID: String) async -> Result<UserProfileProxy, ClientProxyError>
|
||||
}
|
||||
|
||||
@@ -127,14 +127,14 @@ class MockClientProxy: ClientProxyProtocol {
|
||||
setPusherArgument = configuration
|
||||
}
|
||||
|
||||
var searchUsersResult: Result<SearchUsersResults, ClientProxyError> = .success(.init(results: [], limited: false))
|
||||
func searchUsers(searchTerm: String, limit: UInt) async -> Result<SearchUsersResults, ClientProxyError> {
|
||||
var searchUsersResult: Result<SearchUsersResultsProxy, ClientProxyError> = .success(.init(results: [], limited: false))
|
||||
func searchUsers(searchTerm: String, limit: UInt) async -> Result<SearchUsersResultsProxy, ClientProxyError> {
|
||||
searchUsersResult
|
||||
}
|
||||
|
||||
var getProfileResult: Result<UserProfile, ClientProxyError> = .success(.init(userID: "@a:b.com", displayName: "Some user"))
|
||||
var getProfileResult: Result<UserProfileProxy, ClientProxyError> = .success(.init(userID: "@a:b.com", displayName: "Some user"))
|
||||
private(set) var getProfileCalled = false
|
||||
func profile(for userID: String) async -> Result<UserProfile, ClientProxyError> {
|
||||
func profile(for userID: String) async -> Result<UserProfileProxy, ClientProxyError> {
|
||||
getProfileCalled = true
|
||||
return getProfileResult
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
//
|
||||
|
||||
import Combine
|
||||
import MatrixRustSDK
|
||||
|
||||
struct MockRoomTimelineProvider: RoomTimelineProviderProtocol {
|
||||
var itemsPublisher = CurrentValuePublisher<[TimelineItemProxy], Never>([])
|
||||
|
||||
@@ -18,7 +18,7 @@ import Foundation
|
||||
|
||||
struct UserDiscoverySection {
|
||||
let type: UserDiscoverySectionType
|
||||
let users: [UserProfile]
|
||||
let users: [UserProfileProxy]
|
||||
|
||||
var title: String? {
|
||||
switch type {
|
||||
|
||||
@@ -23,11 +23,11 @@ final class UserDiscoveryService: UserDiscoveryServiceProtocol {
|
||||
self.clientProxy = clientProxy
|
||||
}
|
||||
|
||||
func fetchSuggestions() async -> Result<[UserProfile], UserDiscoveryErrorType> {
|
||||
func fetchSuggestions() async -> Result<[UserProfileProxy], UserDiscoveryErrorType> {
|
||||
.success([.mockAlice, .mockBob, .mockCharlie])
|
||||
}
|
||||
|
||||
func searchProfiles(with searchQuery: String) async -> Result<[UserProfile], UserDiscoveryErrorType> {
|
||||
func searchProfiles(with searchQuery: String) async -> Result<[UserProfileProxy], UserDiscoveryErrorType> {
|
||||
do {
|
||||
async let queriedProfile = try? profileIfPossible(with: searchQuery).get()
|
||||
async let searchedUsers = clientProxy.searchUsers(searchTerm: searchQuery, limit: 5)
|
||||
@@ -38,8 +38,8 @@ final class UserDiscoveryService: UserDiscoveryServiceProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
private func merge(searchQuery: String, queriedProfile: UserProfile?, searchResults: SearchUsersResults) -> [UserProfile] {
|
||||
let localProfile = queriedProfile ?? UserProfile(searchQuery: searchQuery)
|
||||
private func merge(searchQuery: String, queriedProfile: UserProfileProxy?, searchResults: SearchUsersResultsProxy) -> [UserProfileProxy] {
|
||||
let localProfile = queriedProfile ?? UserProfileProxy(searchQuery: searchQuery)
|
||||
let searchResults = searchResults.results
|
||||
guard let localProfile else {
|
||||
return searchResults
|
||||
@@ -52,7 +52,7 @@ final class UserDiscoveryService: UserDiscoveryServiceProtocol {
|
||||
return [localProfile] + filteredSearchResult
|
||||
}
|
||||
|
||||
private func profileIfPossible(with searchQuery: String) async -> Result<UserProfile, ClientProxyError> {
|
||||
private func profileIfPossible(with searchQuery: String) async -> Result<UserProfileProxy, ClientProxyError> {
|
||||
guard searchQuery.isMatrixIdentifier else {
|
||||
return .failure(.failedGettingUserProfile)
|
||||
}
|
||||
@@ -67,7 +67,7 @@ private extension String {
|
||||
}
|
||||
}
|
||||
|
||||
private extension UserProfile {
|
||||
private extension UserProfileProxy {
|
||||
init?(searchQuery: String) {
|
||||
guard searchQuery.isMatrixIdentifier else {
|
||||
return nil
|
||||
|
||||
@@ -23,6 +23,6 @@ enum UserDiscoveryErrorType: Error {
|
||||
|
||||
// sourcery: AutoMockable
|
||||
protocol UserDiscoveryServiceProtocol {
|
||||
func searchProfiles(with searchQuery: String) async -> Result<[UserProfile], UserDiscoveryErrorType>
|
||||
func fetchSuggestions() async -> Result<[UserProfile], UserDiscoveryErrorType>
|
||||
func searchProfiles(with searchQuery: String) async -> Result<[UserProfileProxy], UserDiscoveryErrorType>
|
||||
func fetchSuggestions() async -> Result<[UserProfileProxy], UserDiscoveryErrorType>
|
||||
}
|
||||
|
||||
+5
-5
@@ -17,7 +17,7 @@
|
||||
import Foundation
|
||||
import MatrixRustSDK
|
||||
|
||||
struct UserProfile {
|
||||
struct UserProfileProxy {
|
||||
let userID: String
|
||||
let displayName: String?
|
||||
let avatarURL: URL?
|
||||
@@ -41,14 +41,14 @@ struct UserProfile {
|
||||
}
|
||||
}
|
||||
|
||||
struct SearchUsersResults {
|
||||
let results: [UserProfile]
|
||||
struct SearchUsersResultsProxy {
|
||||
let results: [UserProfileProxy]
|
||||
let limited: Bool
|
||||
}
|
||||
|
||||
extension SearchUsersResults {
|
||||
extension SearchUsersResultsProxy {
|
||||
init(sdkResults: MatrixRustSDK.SearchUsersResults) {
|
||||
results = sdkResults.results.map(UserProfile.init)
|
||||
results = sdkResults.results.map(UserProfileProxy.init)
|
||||
limited = sdkResults.limited
|
||||
}
|
||||
}
|
||||
@@ -464,7 +464,7 @@ class MockScreen: Identifiable {
|
||||
userDiscoveryMock.fetchSuggestionsReturnValue = .success([.mockAlice, .mockBob, .mockCharlie])
|
||||
userDiscoveryMock.searchProfilesWithReturnValue = .success([])
|
||||
let mediaProvider = MockMediaProvider()
|
||||
let usersSubject = CurrentValueSubject<[UserProfile], Never>([])
|
||||
let usersSubject = CurrentValueSubject<[UserProfileProxy], Never>([])
|
||||
let members: [RoomMemberProxyMock] = id == .inviteUsersInRoomExistingMembers ? [.mockInvitedAlice, .mockBob] : []
|
||||
let roomType: InviteUsersScreenRoomType = id == .inviteUsers ? .draft : .room(members: members, userIndicatorController: MockUserIndicatorController())
|
||||
let coordinator = InviteUsersScreenCoordinator(parameters: .init(selectedUsers: usersSubject.asCurrentValuePublisher(), roomType: roomType, mediaProvider: mediaProvider, userDiscoveryService: userDiscoveryMock))
|
||||
@@ -490,7 +490,7 @@ class MockScreen: Identifiable {
|
||||
let clientProxy = MockClientProxy(userID: "@mock:client.com")
|
||||
let mockUserSession = MockUserSession(clientProxy: clientProxy, mediaProvider: MockMediaProvider())
|
||||
let createRoomParameters = CreateRoomFlowParameters()
|
||||
let selectedUsers: [UserProfile] = [.mockAlice, .mockBob, .mockCharlie]
|
||||
let selectedUsers: [UserProfileProxy] = [.mockAlice, .mockBob, .mockCharlie]
|
||||
let parameters = CreateRoomCoordinatorParameters(userSession: mockUserSession, userIndicatorController: nil, createRoomParameters: .init(createRoomParameters), selectedUsers: .init(selectedUsers))
|
||||
let coordinator = CreateRoomCoordinator(parameters: parameters)
|
||||
navigationStackCoordinator.setRootCoordinator(coordinator)
|
||||
|
||||
Reference in New Issue
Block a user