mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Add hooks for the RoomDetails, RoomMemberDetails and UserProfile screens. (#5980)
Also adds an @AppHook macro.
This commit is contained in:
@@ -7,105 +7,57 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Macros
|
||||
import Synchronization
|
||||
|
||||
final nonisolated class AppHooks: AppHooksProtocol {
|
||||
#if IS_MAIN_APP
|
||||
func configure(with userSession: UserSessionProtocol?) async {
|
||||
await roomScreenHook.configure(with: userSession)
|
||||
await userSessionHook.configure(with: userSession)
|
||||
}
|
||||
|
||||
private let _appSettingsHook: Mutex<AppSettingsHookProtocol> = Mutex(DefaultAppSettingsHook())
|
||||
var appSettingsHook: AppSettingsHookProtocol {
|
||||
_appSettingsHook.withLock { $0 }
|
||||
}
|
||||
@AppHook(default: DefaultAppSettingsHook())
|
||||
var appSettingsHook: AppSettingsHookProtocol
|
||||
|
||||
func registerAppSettingsHook(_ hook: AppSettingsHookProtocol) {
|
||||
_appSettingsHook.withLock { $0 = hook }
|
||||
}
|
||||
@AppHook(default: DefaultCompoundHook())
|
||||
var compoundHook: CompoundHookProtocol
|
||||
|
||||
private let _compoundHook: Mutex<CompoundHookProtocol> = Mutex(DefaultCompoundHook())
|
||||
var compoundHook: CompoundHookProtocol {
|
||||
_compoundHook.withLock { $0 }
|
||||
}
|
||||
@AppHook(default: DefaultBugReportHook())
|
||||
var bugReportHook: BugReportHookProtocol
|
||||
|
||||
func registerCompoundHook(_ hook: CompoundHookProtocol) {
|
||||
_compoundHook.withLock { $0 = hook }
|
||||
}
|
||||
@AppHook(default: DefaultOAuthPresenterHook())
|
||||
var oAuthPresenterHook: OAuthPresenterHookProtocol
|
||||
|
||||
private let _bugReportHook: Mutex<BugReportHookProtocol> = Mutex(DefaultBugReportHook())
|
||||
var bugReportHook: BugReportHookProtocol {
|
||||
_bugReportHook.withLock { $0 }
|
||||
}
|
||||
@AppHook(default: DefaultUserSessionHook())
|
||||
var userSessionHook: UserSessionHookProtocol
|
||||
|
||||
func registerBugReportHook(_ hook: BugReportHookProtocol) {
|
||||
_bugReportHook.withLock { $0 = hook }
|
||||
}
|
||||
@AppHook(default: DefaultRoomScreenHook())
|
||||
var roomScreenHook: RoomScreenHookProtocol
|
||||
|
||||
private let _oAuthPresenterHook: Mutex<OAuthPresenterHookProtocol> = Mutex(DefaultOAuthPresenterHook())
|
||||
var oAuthPresenterHook: OAuthPresenterHookProtocol {
|
||||
_oAuthPresenterHook.withLock { $0 }
|
||||
}
|
||||
@AppHook(default: DefaultRoomDetailsScreenHook())
|
||||
var roomDetailsScreenHook: RoomDetailsScreenHookProtocol
|
||||
|
||||
func registerOAuthPresenterHook(_ hook: OAuthPresenterHookProtocol) {
|
||||
_oAuthPresenterHook.withLock { $0 = hook }
|
||||
}
|
||||
@AppHook(default: DefaultRoomMemberDetailsScreenHook())
|
||||
var roomMemberDetailsScreenHook: RoomMemberDetailsScreenHookProtocol
|
||||
|
||||
private let _roomScreenHook: Mutex<RoomScreenHookProtocol> = Mutex(DefaultRoomScreenHook())
|
||||
var roomScreenHook: RoomScreenHookProtocol {
|
||||
_roomScreenHook.withLock { $0 }
|
||||
}
|
||||
@AppHook(default: DefaultUserProfileScreenHook())
|
||||
var userProfileScreenHook: UserProfileScreenHookProtocol
|
||||
|
||||
func registerRoomScreenHook(_ hook: RoomScreenHookProtocol) {
|
||||
_roomScreenHook.withLock { $0 = hook }
|
||||
}
|
||||
@AppHook(default: DefaultDeveloperOptionsScreenHook())
|
||||
var developerOptionsScreenHook: DeveloperOptionsScreenHookProtocol
|
||||
|
||||
private let _developerOptionsScreenHook: Mutex<DeveloperOptionsScreenHookProtocol> = Mutex(DefaultDeveloperOptionsScreenHook())
|
||||
var developerOptionsScreenHook: DeveloperOptionsScreenHookProtocol {
|
||||
_developerOptionsScreenHook.withLock { $0 }
|
||||
}
|
||||
|
||||
func registerDeveloperOptionsScreenHook(_ hook: DeveloperOptionsScreenHookProtocol) {
|
||||
_developerOptionsScreenHook.withLock { $0 = hook }
|
||||
}
|
||||
|
||||
private let _recoveryKeyScreenHook: Mutex<RecoveryKeyScreenHookProtocol> = Mutex(DefaultRecoveryKeyScreenHook())
|
||||
var recoveryKeyScreenHook: RecoveryKeyScreenHookProtocol {
|
||||
_recoveryKeyScreenHook.withLock { $0 }
|
||||
}
|
||||
|
||||
func registerRecoveryKeyScreenHook(_ hook: RecoveryKeyScreenHookProtocol) {
|
||||
_recoveryKeyScreenHook.withLock { $0 = hook }
|
||||
}
|
||||
@AppHook(default: DefaultRecoveryKeyScreenHook())
|
||||
var recoveryKeyScreenHook: RecoveryKeyScreenHookProtocol
|
||||
#endif
|
||||
|
||||
private let _tracingHook: Mutex<TracingHookProtocol> = Mutex(DefaultTracingHook())
|
||||
var tracingHook: TracingHookProtocol {
|
||||
_tracingHook.withLock { $0 }
|
||||
}
|
||||
@AppHook(default: DefaultTracingHook())
|
||||
var tracingHook: TracingHookProtocol
|
||||
|
||||
func registerTracingHook(_ hook: TracingHookProtocol) {
|
||||
_tracingHook.withLock { $0 = hook }
|
||||
}
|
||||
@AppHook(default: DefaultClientBuilderHook())
|
||||
var clientBuilderHook: ClientBuilderHookProtocol
|
||||
|
||||
private let _clientBuilderHook: Mutex<ClientBuilderHookProtocol> = Mutex(DefaultClientBuilderHook())
|
||||
var clientBuilderHook: ClientBuilderHookProtocol {
|
||||
_clientBuilderHook.withLock { $0 }
|
||||
}
|
||||
|
||||
// periphery:ignore - might be useful to have
|
||||
func registerClientBuilderHook(_ hook: ClientBuilderHookProtocol) {
|
||||
_clientBuilderHook.withLock { $0 = hook }
|
||||
}
|
||||
|
||||
private let _remoteSettingsHook: Mutex<RemoteSettingsHookProtocol> = Mutex(DefaultRemoteSettingsHook())
|
||||
var remoteSettingsHook: RemoteSettingsHookProtocol {
|
||||
_remoteSettingsHook.withLock { $0 }
|
||||
}
|
||||
|
||||
func registerRemoteSettingsHook(_ hook: RemoteSettingsHookProtocol) {
|
||||
_remoteSettingsHook.withLock { $0 = hook }
|
||||
}
|
||||
@AppHook(default: DefaultRemoteSettingsHook())
|
||||
var remoteSettingsHook: RemoteSettingsHookProtocol
|
||||
}
|
||||
|
||||
nonisolated protocol AppHooksProtocol: Sendable {
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// Copyright 2026 Element Creations Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
nonisolated protocol RoomDetailsScreenHookProtocol: Sendable {
|
||||
@MainActor func update(_ viewState: RoomDetailsScreenViewState) -> RoomDetailsScreenViewState
|
||||
}
|
||||
|
||||
struct DefaultRoomDetailsScreenHook: RoomDetailsScreenHookProtocol {
|
||||
func update(_ viewState: RoomDetailsScreenViewState) -> RoomDetailsScreenViewState {
|
||||
viewState
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// Copyright 2026 Element Creations Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
nonisolated protocol RoomMemberDetailsScreenHookProtocol: Sendable {
|
||||
@MainActor func update(_ viewState: RoomMemberDetailsScreenViewState) -> RoomMemberDetailsScreenViewState
|
||||
}
|
||||
|
||||
struct DefaultRoomMemberDetailsScreenHook: RoomMemberDetailsScreenHookProtocol {
|
||||
func update(_ viewState: RoomMemberDetailsScreenViewState) -> RoomMemberDetailsScreenViewState {
|
||||
viewState
|
||||
}
|
||||
}
|
||||
@@ -9,12 +9,10 @@
|
||||
import Foundation
|
||||
|
||||
nonisolated protocol RoomScreenHookProtocol: Sendable {
|
||||
@MainActor func configure(with userSession: UserSessionProtocol?) async
|
||||
@MainActor func update(_ viewState: RoomScreenViewState) -> RoomScreenViewState
|
||||
}
|
||||
|
||||
struct DefaultRoomScreenHook: RoomScreenHookProtocol {
|
||||
func configure(with userSession: UserSessionProtocol?) async { }
|
||||
func update(_ viewState: RoomScreenViewState) -> RoomScreenViewState {
|
||||
viewState
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// Copyright 2026 Element Creations Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
nonisolated protocol UserProfileScreenHookProtocol: Sendable {
|
||||
@MainActor func update(_ viewState: UserProfileScreenViewState) -> UserProfileScreenViewState
|
||||
}
|
||||
|
||||
struct DefaultUserProfileScreenHook: UserProfileScreenHookProtocol {
|
||||
func update(_ viewState: UserProfileScreenViewState) -> UserProfileScreenViewState {
|
||||
viewState
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// Copyright 2026 Element Creations Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import MatrixRustSDK
|
||||
|
||||
nonisolated protocol UserSessionHookProtocol: Sendable {
|
||||
func configure(with userSession: UserSessionProtocol?) async
|
||||
}
|
||||
|
||||
nonisolated struct DefaultUserSessionHook: UserSessionHookProtocol {
|
||||
func configure(with userSession: UserSessionProtocol?) async { }
|
||||
}
|
||||
Reference in New Issue
Block a user