Revert weak media provider (#4483)

* Revert "Address the real lifetime issue of the SDK's `Client` by making `Context.mediaProvider` weak. (#4466)"

This reverts commit c794144ef1.

* Better docs.
This commit is contained in:
Doug
2025-09-08 17:48:58 +01:00
committed by GitHub
parent 90504d89c8
commit 2f2e6f6226
58 changed files with 161 additions and 380 deletions
+5 -3
View File
@@ -81,9 +81,11 @@ extension ClientProxyMock {
recentlyVisitedRoomsReturnValue = .success([])
recentConversationCounterpartsReturnValue = []
loadMediaContentForSourceThrowableError = ClientProxyError.sdkError(ClientProxyMockError.generic)
loadMediaThumbnailForSourceWidthHeightThrowableError = ClientProxyError.sdkError(ClientProxyMockError.generic)
loadMediaFileForSourceFilenameThrowableError = ClientProxyError.sdkError(ClientProxyMockError.generic)
let mediaLoader = MediaLoaderMock()
mediaLoader.loadMediaContentForSourceThrowableError = ClientProxyError.sdkError(ClientProxyMockError.generic)
mediaLoader.loadMediaThumbnailForSourceWidthHeightThrowableError = ClientProxyError.sdkError(ClientProxyMockError.generic)
mediaLoader.loadMediaFileForSourceFilenameThrowableError = ClientProxyError.sdkError(ClientProxyMockError.generic)
self.mediaLoader = mediaLoader
secureBackupController = SecureBackupControllerMock(.init(recoveryState: configuration.recoveryState))
resetIdentityReturnValue = .success(IdentityResetHandleSDKMock(.init()))
@@ -2130,6 +2130,11 @@ class ClientProxyMock: ClientProxyProtocol, @unchecked Sendable {
}
var underlyingHideInviteAvatarsPublisher: CurrentValuePublisher<Bool, Never>!
var pusherNotificationClientIdentifier: String?
var mediaLoader: MediaLoaderProtocol {
get { return underlyingMediaLoader }
set(value) { underlyingMediaLoader = value }
}
var underlyingMediaLoader: MediaLoaderProtocol!
var roomSummaryProvider: RoomSummaryProviderProtocol {
get { return underlyingRoomSummaryProvider }
set(value) { underlyingRoomSummaryProvider = value }
@@ -5204,228 +5209,6 @@ class ClientProxyMock: ClientProxyProtocol, @unchecked Sendable {
return setHideInviteAvatarsReturnValue
}
}
//MARK: - loadMediaContentForSource
var loadMediaContentForSourceThrowableError: Error?
var loadMediaContentForSourceUnderlyingCallsCount = 0
var loadMediaContentForSourceCallsCount: Int {
get {
if Thread.isMainThread {
return loadMediaContentForSourceUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = loadMediaContentForSourceUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
loadMediaContentForSourceUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
loadMediaContentForSourceUnderlyingCallsCount = newValue
}
}
}
}
var loadMediaContentForSourceCalled: Bool {
return loadMediaContentForSourceCallsCount > 0
}
var loadMediaContentForSourceReceivedSource: MediaSourceProxy?
var loadMediaContentForSourceReceivedInvocations: [MediaSourceProxy] = []
var loadMediaContentForSourceUnderlyingReturnValue: Data!
var loadMediaContentForSourceReturnValue: Data! {
get {
if Thread.isMainThread {
return loadMediaContentForSourceUnderlyingReturnValue
} else {
var returnValue: Data? = nil
DispatchQueue.main.sync {
returnValue = loadMediaContentForSourceUnderlyingReturnValue
}
return returnValue!
}
}
set {
if Thread.isMainThread {
loadMediaContentForSourceUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
loadMediaContentForSourceUnderlyingReturnValue = newValue
}
}
}
}
var loadMediaContentForSourceClosure: ((MediaSourceProxy) async throws -> Data)?
func loadMediaContentForSource(_ source: MediaSourceProxy) async throws -> Data {
if let error = loadMediaContentForSourceThrowableError {
throw error
}
loadMediaContentForSourceCallsCount += 1
loadMediaContentForSourceReceivedSource = source
DispatchQueue.main.async {
self.loadMediaContentForSourceReceivedInvocations.append(source)
}
if let loadMediaContentForSourceClosure = loadMediaContentForSourceClosure {
return try await loadMediaContentForSourceClosure(source)
} else {
return loadMediaContentForSourceReturnValue
}
}
//MARK: - loadMediaThumbnailForSource
var loadMediaThumbnailForSourceWidthHeightThrowableError: Error?
var loadMediaThumbnailForSourceWidthHeightUnderlyingCallsCount = 0
var loadMediaThumbnailForSourceWidthHeightCallsCount: Int {
get {
if Thread.isMainThread {
return loadMediaThumbnailForSourceWidthHeightUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = loadMediaThumbnailForSourceWidthHeightUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
loadMediaThumbnailForSourceWidthHeightUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
loadMediaThumbnailForSourceWidthHeightUnderlyingCallsCount = newValue
}
}
}
}
var loadMediaThumbnailForSourceWidthHeightCalled: Bool {
return loadMediaThumbnailForSourceWidthHeightCallsCount > 0
}
var loadMediaThumbnailForSourceWidthHeightReceivedArguments: (source: MediaSourceProxy, width: UInt, height: UInt)?
var loadMediaThumbnailForSourceWidthHeightReceivedInvocations: [(source: MediaSourceProxy, width: UInt, height: UInt)] = []
var loadMediaThumbnailForSourceWidthHeightUnderlyingReturnValue: Data!
var loadMediaThumbnailForSourceWidthHeightReturnValue: Data! {
get {
if Thread.isMainThread {
return loadMediaThumbnailForSourceWidthHeightUnderlyingReturnValue
} else {
var returnValue: Data? = nil
DispatchQueue.main.sync {
returnValue = loadMediaThumbnailForSourceWidthHeightUnderlyingReturnValue
}
return returnValue!
}
}
set {
if Thread.isMainThread {
loadMediaThumbnailForSourceWidthHeightUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
loadMediaThumbnailForSourceWidthHeightUnderlyingReturnValue = newValue
}
}
}
}
var loadMediaThumbnailForSourceWidthHeightClosure: ((MediaSourceProxy, UInt, UInt) async throws -> Data)?
func loadMediaThumbnailForSource(_ source: MediaSourceProxy, width: UInt, height: UInt) async throws -> Data {
if let error = loadMediaThumbnailForSourceWidthHeightThrowableError {
throw error
}
loadMediaThumbnailForSourceWidthHeightCallsCount += 1
loadMediaThumbnailForSourceWidthHeightReceivedArguments = (source: source, width: width, height: height)
DispatchQueue.main.async {
self.loadMediaThumbnailForSourceWidthHeightReceivedInvocations.append((source: source, width: width, height: height))
}
if let loadMediaThumbnailForSourceWidthHeightClosure = loadMediaThumbnailForSourceWidthHeightClosure {
return try await loadMediaThumbnailForSourceWidthHeightClosure(source, width, height)
} else {
return loadMediaThumbnailForSourceWidthHeightReturnValue
}
}
//MARK: - loadMediaFileForSource
var loadMediaFileForSourceFilenameThrowableError: Error?
var loadMediaFileForSourceFilenameUnderlyingCallsCount = 0
var loadMediaFileForSourceFilenameCallsCount: Int {
get {
if Thread.isMainThread {
return loadMediaFileForSourceFilenameUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = loadMediaFileForSourceFilenameUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
loadMediaFileForSourceFilenameUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
loadMediaFileForSourceFilenameUnderlyingCallsCount = newValue
}
}
}
}
var loadMediaFileForSourceFilenameCalled: Bool {
return loadMediaFileForSourceFilenameCallsCount > 0
}
var loadMediaFileForSourceFilenameReceivedArguments: (source: MediaSourceProxy, filename: String?)?
var loadMediaFileForSourceFilenameReceivedInvocations: [(source: MediaSourceProxy, filename: String?)] = []
var loadMediaFileForSourceFilenameUnderlyingReturnValue: MediaFileHandleProxy!
var loadMediaFileForSourceFilenameReturnValue: MediaFileHandleProxy! {
get {
if Thread.isMainThread {
return loadMediaFileForSourceFilenameUnderlyingReturnValue
} else {
var returnValue: MediaFileHandleProxy? = nil
DispatchQueue.main.sync {
returnValue = loadMediaFileForSourceFilenameUnderlyingReturnValue
}
return returnValue!
}
}
set {
if Thread.isMainThread {
loadMediaFileForSourceFilenameUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
loadMediaFileForSourceFilenameUnderlyingReturnValue = newValue
}
}
}
}
var loadMediaFileForSourceFilenameClosure: ((MediaSourceProxy, String?) async throws -> MediaFileHandleProxy)?
func loadMediaFileForSource(_ source: MediaSourceProxy, filename: String?) async throws -> MediaFileHandleProxy {
if let error = loadMediaFileForSourceFilenameThrowableError {
throw error
}
loadMediaFileForSourceFilenameCallsCount += 1
loadMediaFileForSourceFilenameReceivedArguments = (source: source, filename: filename)
DispatchQueue.main.async {
self.loadMediaFileForSourceFilenameReceivedInvocations.append((source: source, filename: filename))
}
if let loadMediaFileForSourceFilenameClosure = loadMediaFileForSourceFilenameClosure {
return try await loadMediaFileForSourceFilenameClosure(source, filename)
} else {
return loadMediaFileForSourceFilenameReturnValue
}
}
}
class CompletionSuggestionServiceMock: CompletionSuggestionServiceProtocol, @unchecked Sendable {
var suggestionsPublisher: AnyPublisher<[SuggestionItem], Never> {
@@ -7,17 +7,11 @@
import SwiftUI
extension MediaProviderProtocol where Self == MediaProviderMock {
static var mock: MediaProviderMock { .shared }
}
extension MediaProviderMock {
static let shared = MediaProviderMock(.init())
struct Configuration { }
// swiftlint:disable:next cyclomatic_complexity
convenience init(_ configuration: Configuration) {
convenience init(configuration: Configuration) {
self.init()
imageFromSourceSizeClosure = { mediaSource, _ in
+1 -1
View File
@@ -17,7 +17,7 @@ extension UserSessionMock {
self.init()
clientProxy = configuration.clientProxy
mediaProvider = .mock
mediaProvider = MediaProviderMock(configuration: .init())
voiceMessageMediaManager = VoiceMessageMediaManagerMock()
sessionSecurityStatePublisher = CurrentValueSubject<SessionSecurityState, Never>(.init(verificationState: .verified, recoveryState: .enabled)).asCurrentValuePublisher()