mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Make the remote settings hook usable within the app extensions. (#4342)
This commit is contained in:
+20
-8
@@ -8,15 +8,25 @@
|
||||
import Foundation
|
||||
import MatrixRustSDK
|
||||
|
||||
protocol ElementWellKnownHookProtocol {
|
||||
func validate(using client: ClientProtocol) async -> Result<Void, ElementWellKnownError>
|
||||
enum RemoteSettingsError: Error {
|
||||
case elementProRequired(serverName: String)
|
||||
}
|
||||
|
||||
struct DefaultElementWellKnownHook: ElementWellKnownHookProtocol {
|
||||
protocol RemoteSettingsHookProtocol {
|
||||
#if IS_MAIN_APP
|
||||
func initializeCache(using client: ClientProtocol, applyingTo appSettings: CommonSettingsProtocol) async -> Result<Void, RemoteSettingsError>
|
||||
func updateCache(using client: ClientProtocol) async
|
||||
func reset(_ appSettings: CommonSettingsProtocol)
|
||||
#endif
|
||||
func loadCache(forHomeserver: String, applyingTo appSettings: CommonSettingsProtocol)
|
||||
}
|
||||
|
||||
struct DefaultRemoteSettingsHook: RemoteSettingsHookProtocol {
|
||||
#if IS_MAIN_APP
|
||||
/// A best effort implementation to let Element X advertise to users when they should be using
|
||||
/// Element Pro. In an ideal world the backend would be able to validate the client's requests
|
||||
/// instead of relying on it to check a well-known file for this.
|
||||
func validate(using client: ClientProtocol) async -> Result<Void, ElementWellKnownError> {
|
||||
func initializeCache(using client: ClientProtocol, applyingTo appSettings: CommonSettingsProtocol) async -> Result<Void, RemoteSettingsError> {
|
||||
guard case let .success(wellKnownData) = await client.elementWellKnown() else {
|
||||
// Nothing to check, carry on as normal.
|
||||
return .success(())
|
||||
@@ -36,6 +46,12 @@ struct DefaultElementWellKnownHook: ElementWellKnownHookProtocol {
|
||||
return .success(())
|
||||
}
|
||||
}
|
||||
|
||||
func updateCache(using client: ClientProtocol) async { }
|
||||
func reset(_ appSettings: any CommonSettingsProtocol) { }
|
||||
#endif
|
||||
|
||||
func loadCache(forHomeserver: String, applyingTo appSettings: CommonSettingsProtocol) { }
|
||||
}
|
||||
|
||||
private struct ElementWellKnown: Decodable {
|
||||
@@ -47,7 +63,3 @@ private struct ElementWellKnown: Decodable {
|
||||
case enforceElementPro = "enforce_element_pro"
|
||||
}
|
||||
}
|
||||
|
||||
enum ElementWellKnownError: Error {
|
||||
case elementProRequired(serverName: String)
|
||||
}
|
||||
Reference in New Issue
Block a user