Handle media previews and invite avatars through the account data (#4142)

* added account data media display policy handling to NSE

* pr suggestions

* update compound

* code improvement
This commit is contained in:
Mauro
2025-05-28 19:51:34 +02:00
committed by GitHub
parent 256292c5a9
commit aef91b5bc9
24 changed files with 626 additions and 61 deletions
@@ -17,6 +17,9 @@ struct ClientProxyMockConfiguration {
var roomDirectorySearchProxy: RoomDirectorySearchProxyProtocol?
var recoveryState: SecureBackupRecoveryState = .enabled
var timelineMediaVisibility = TimelineMediaVisibility.always
var hideInviteAvatars = false
}
enum ClientProxyMockError: Error {
@@ -94,5 +97,8 @@ extension ClientProxyMock {
userIdentityForReturnValue = .success(UserIdentityProxyMock(configuration: .init()))
underlyingIsReportRoomSupported = true
underlyingTimelineMediaVisibilityPublisher = CurrentValueSubject<TimelineMediaVisibility, Never>(configuration.timelineMediaVisibility).asCurrentValuePublisher()
underlyingHideInviteAvatarsPublisher = CurrentValueSubject<Bool, Never>(configuration.hideInviteAvatars).asCurrentValuePublisher()
}
}
@@ -2271,6 +2271,16 @@ class ClientProxyMock: ClientProxyProtocol, @unchecked Sendable {
set(value) { underlyingIgnoredUsersPublisher = value }
}
var underlyingIgnoredUsersPublisher: CurrentValuePublisher<[String]?, Never>!
var timelineMediaVisibilityPublisher: CurrentValuePublisher<TimelineMediaVisibility, Never> {
get { return underlyingTimelineMediaVisibilityPublisher }
set(value) { underlyingTimelineMediaVisibilityPublisher = value }
}
var underlyingTimelineMediaVisibilityPublisher: CurrentValuePublisher<TimelineMediaVisibility, Never>!
var hideInviteAvatarsPublisher: CurrentValuePublisher<Bool, Never> {
get { return underlyingHideInviteAvatarsPublisher }
set(value) { underlyingHideInviteAvatarsPublisher = value }
}
var underlyingHideInviteAvatarsPublisher: CurrentValuePublisher<Bool, Never>!
var pusherNotificationClientIdentifier: String?
var roomSummaryProvider: RoomSummaryProviderProtocol {
get { return underlyingRoomSummaryProvider }
@@ -4363,6 +4373,70 @@ class ClientProxyMock: ClientProxyProtocol, @unchecked Sendable {
return clearCachesReturnValue
}
}
//MARK: - fetchMediaPreviewConfiguration
var fetchMediaPreviewConfigurationUnderlyingCallsCount = 0
var fetchMediaPreviewConfigurationCallsCount: Int {
get {
if Thread.isMainThread {
return fetchMediaPreviewConfigurationUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = fetchMediaPreviewConfigurationUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
fetchMediaPreviewConfigurationUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
fetchMediaPreviewConfigurationUnderlyingCallsCount = newValue
}
}
}
}
var fetchMediaPreviewConfigurationCalled: Bool {
return fetchMediaPreviewConfigurationCallsCount > 0
}
var fetchMediaPreviewConfigurationUnderlyingReturnValue: Result<MediaPreviewConfig?, ClientProxyError>!
var fetchMediaPreviewConfigurationReturnValue: Result<MediaPreviewConfig?, ClientProxyError>! {
get {
if Thread.isMainThread {
return fetchMediaPreviewConfigurationUnderlyingReturnValue
} else {
var returnValue: Result<MediaPreviewConfig?, ClientProxyError>? = nil
DispatchQueue.main.sync {
returnValue = fetchMediaPreviewConfigurationUnderlyingReturnValue
}
return returnValue!
}
}
set {
if Thread.isMainThread {
fetchMediaPreviewConfigurationUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
fetchMediaPreviewConfigurationUnderlyingReturnValue = newValue
}
}
}
}
var fetchMediaPreviewConfigurationClosure: (() async -> Result<MediaPreviewConfig?, ClientProxyError>)?
func fetchMediaPreviewConfiguration() async -> Result<MediaPreviewConfig?, ClientProxyError> {
fetchMediaPreviewConfigurationCallsCount += 1
if let fetchMediaPreviewConfigurationClosure = fetchMediaPreviewConfigurationClosure {
return await fetchMediaPreviewConfigurationClosure()
} else {
return fetchMediaPreviewConfigurationReturnValue
}
}
//MARK: - ignoreUser
var ignoreUserUnderlyingCallsCount = 0
@@ -5103,6 +5177,146 @@ class ClientProxyMock: ClientProxyProtocol, @unchecked Sendable {
return userIdentityForReturnValue
}
}
//MARK: - setTimelineMediaVisibility
var setTimelineMediaVisibilityUnderlyingCallsCount = 0
var setTimelineMediaVisibilityCallsCount: Int {
get {
if Thread.isMainThread {
return setTimelineMediaVisibilityUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = setTimelineMediaVisibilityUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
setTimelineMediaVisibilityUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
setTimelineMediaVisibilityUnderlyingCallsCount = newValue
}
}
}
}
var setTimelineMediaVisibilityCalled: Bool {
return setTimelineMediaVisibilityCallsCount > 0
}
var setTimelineMediaVisibilityReceivedValue: TimelineMediaVisibility?
var setTimelineMediaVisibilityReceivedInvocations: [TimelineMediaVisibility] = []
var setTimelineMediaVisibilityUnderlyingReturnValue: Result<Void, ClientProxyError>!
var setTimelineMediaVisibilityReturnValue: Result<Void, ClientProxyError>! {
get {
if Thread.isMainThread {
return setTimelineMediaVisibilityUnderlyingReturnValue
} else {
var returnValue: Result<Void, ClientProxyError>? = nil
DispatchQueue.main.sync {
returnValue = setTimelineMediaVisibilityUnderlyingReturnValue
}
return returnValue!
}
}
set {
if Thread.isMainThread {
setTimelineMediaVisibilityUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
setTimelineMediaVisibilityUnderlyingReturnValue = newValue
}
}
}
}
var setTimelineMediaVisibilityClosure: ((TimelineMediaVisibility) async -> Result<Void, ClientProxyError>)?
func setTimelineMediaVisibility(_ value: TimelineMediaVisibility) async -> Result<Void, ClientProxyError> {
setTimelineMediaVisibilityCallsCount += 1
setTimelineMediaVisibilityReceivedValue = value
DispatchQueue.main.async {
self.setTimelineMediaVisibilityReceivedInvocations.append(value)
}
if let setTimelineMediaVisibilityClosure = setTimelineMediaVisibilityClosure {
return await setTimelineMediaVisibilityClosure(value)
} else {
return setTimelineMediaVisibilityReturnValue
}
}
//MARK: - setHideInviteAvatars
var setHideInviteAvatarsUnderlyingCallsCount = 0
var setHideInviteAvatarsCallsCount: Int {
get {
if Thread.isMainThread {
return setHideInviteAvatarsUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = setHideInviteAvatarsUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
setHideInviteAvatarsUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
setHideInviteAvatarsUnderlyingCallsCount = newValue
}
}
}
}
var setHideInviteAvatarsCalled: Bool {
return setHideInviteAvatarsCallsCount > 0
}
var setHideInviteAvatarsReceivedValue: Bool?
var setHideInviteAvatarsReceivedInvocations: [Bool] = []
var setHideInviteAvatarsUnderlyingReturnValue: Result<Void, ClientProxyError>!
var setHideInviteAvatarsReturnValue: Result<Void, ClientProxyError>! {
get {
if Thread.isMainThread {
return setHideInviteAvatarsUnderlyingReturnValue
} else {
var returnValue: Result<Void, ClientProxyError>? = nil
DispatchQueue.main.sync {
returnValue = setHideInviteAvatarsUnderlyingReturnValue
}
return returnValue!
}
}
set {
if Thread.isMainThread {
setHideInviteAvatarsUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
setHideInviteAvatarsUnderlyingReturnValue = newValue
}
}
}
}
var setHideInviteAvatarsClosure: ((Bool) async -> Result<Void, ClientProxyError>)?
func setHideInviteAvatars(_ value: Bool) async -> Result<Void, ClientProxyError> {
setHideInviteAvatarsCallsCount += 1
setHideInviteAvatarsReceivedValue = value
DispatchQueue.main.async {
self.setHideInviteAvatarsReceivedInvocations.append(value)
}
if let setHideInviteAvatarsClosure = setHideInviteAvatarsClosure {
return await setHideInviteAvatarsClosure(value)
} else {
return setHideInviteAvatarsReturnValue
}
}
//MARK: - loadMediaContentForSource
var loadMediaContentForSourceThrowableError: Error?
@@ -1050,6 +1050,75 @@ open class ClientSDKMock: MatrixRustSDK.Client, @unchecked Sendable {
}
}
//MARK: - fetchMediaPreviewConfig
open var fetchMediaPreviewConfigThrowableError: Error?
var fetchMediaPreviewConfigUnderlyingCallsCount = 0
open var fetchMediaPreviewConfigCallsCount: Int {
get {
if Thread.isMainThread {
return fetchMediaPreviewConfigUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = fetchMediaPreviewConfigUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
fetchMediaPreviewConfigUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
fetchMediaPreviewConfigUnderlyingCallsCount = newValue
}
}
}
}
open var fetchMediaPreviewConfigCalled: Bool {
return fetchMediaPreviewConfigCallsCount > 0
}
var fetchMediaPreviewConfigUnderlyingReturnValue: MediaPreviewConfig?
open var fetchMediaPreviewConfigReturnValue: MediaPreviewConfig? {
get {
if Thread.isMainThread {
return fetchMediaPreviewConfigUnderlyingReturnValue
} else {
var returnValue: MediaPreviewConfig?? = nil
DispatchQueue.main.sync {
returnValue = fetchMediaPreviewConfigUnderlyingReturnValue
}
return returnValue!
}
}
set {
if Thread.isMainThread {
fetchMediaPreviewConfigUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
fetchMediaPreviewConfigUnderlyingReturnValue = newValue
}
}
}
}
open var fetchMediaPreviewConfigClosure: (() async throws -> MediaPreviewConfig?)?
open override func fetchMediaPreviewConfig() async throws -> MediaPreviewConfig? {
if let error = fetchMediaPreviewConfigThrowableError {
throw error
}
fetchMediaPreviewConfigCallsCount += 1
if let fetchMediaPreviewConfigClosure = fetchMediaPreviewConfigClosure {
return try await fetchMediaPreviewConfigClosure()
} else {
return fetchMediaPreviewConfigReturnValue
}
}
//MARK: - getDmRoom
open var getDmRoomUserIdThrowableError: Error?
@@ -1156,13 +1225,13 @@ open class ClientSDKMock: MatrixRustSDK.Client, @unchecked Sendable {
return getInviteAvatarsDisplayPolicyCallsCount > 0
}
var getInviteAvatarsDisplayPolicyUnderlyingReturnValue: InviteAvatars!
open var getInviteAvatarsDisplayPolicyReturnValue: InviteAvatars! {
var getInviteAvatarsDisplayPolicyUnderlyingReturnValue: InviteAvatars?
open var getInviteAvatarsDisplayPolicyReturnValue: InviteAvatars? {
get {
if Thread.isMainThread {
return getInviteAvatarsDisplayPolicyUnderlyingReturnValue
} else {
var returnValue: InviteAvatars? = nil
var returnValue: InviteAvatars?? = nil
DispatchQueue.main.sync {
returnValue = getInviteAvatarsDisplayPolicyUnderlyingReturnValue
}
@@ -1180,9 +1249,9 @@ open class ClientSDKMock: MatrixRustSDK.Client, @unchecked Sendable {
}
}
}
open var getInviteAvatarsDisplayPolicyClosure: (() async throws -> InviteAvatars)?
open var getInviteAvatarsDisplayPolicyClosure: (() async throws -> InviteAvatars?)?
open override func getInviteAvatarsDisplayPolicy() async throws -> InviteAvatars {
open override func getInviteAvatarsDisplayPolicy() async throws -> InviteAvatars? {
if let error = getInviteAvatarsDisplayPolicyThrowableError {
throw error
}
@@ -1375,13 +1444,13 @@ open class ClientSDKMock: MatrixRustSDK.Client, @unchecked Sendable {
return getMediaPreviewDisplayPolicyCallsCount > 0
}
var getMediaPreviewDisplayPolicyUnderlyingReturnValue: MediaPreviews!
open var getMediaPreviewDisplayPolicyReturnValue: MediaPreviews! {
var getMediaPreviewDisplayPolicyUnderlyingReturnValue: MediaPreviews?
open var getMediaPreviewDisplayPolicyReturnValue: MediaPreviews? {
get {
if Thread.isMainThread {
return getMediaPreviewDisplayPolicyUnderlyingReturnValue
} else {
var returnValue: MediaPreviews? = nil
var returnValue: MediaPreviews?? = nil
DispatchQueue.main.sync {
returnValue = getMediaPreviewDisplayPolicyUnderlyingReturnValue
}
@@ -1399,9 +1468,9 @@ open class ClientSDKMock: MatrixRustSDK.Client, @unchecked Sendable {
}
}
}
open var getMediaPreviewDisplayPolicyClosure: (() async throws -> MediaPreviews)?
open var getMediaPreviewDisplayPolicyClosure: (() async throws -> MediaPreviews?)?
open override func getMediaPreviewDisplayPolicy() async throws -> MediaPreviews {
open override func getMediaPreviewDisplayPolicy() async throws -> MediaPreviews? {
if let error = getMediaPreviewDisplayPolicyThrowableError {
throw error
}