Allow overriding the push gateway. (#3970)

This commit is contained in:
Doug
2025-04-03 10:42:09 +01:00
committed by GitHub
parent 27070f77fd
commit b8bf2a08f6
4 changed files with 10 additions and 7 deletions
@@ -92,6 +92,7 @@ final class AppSettings {
// swiftlint:disable:next function_parameter_count // swiftlint:disable:next function_parameter_count
func override(defaultHomeserverAddress: String, func override(defaultHomeserverAddress: String,
pushGatewayBaseURL: URL,
oidcRedirectURL: URL, oidcRedirectURL: URL,
websiteURL: URL, websiteURL: URL,
logoURL: URL, logoURL: URL,
@@ -103,6 +104,7 @@ final class AppSettings {
analyticsTermsURL: URL?, analyticsTermsURL: URL?,
mapTilerConfiguration: MapTilerConfiguration) { mapTilerConfiguration: MapTilerConfiguration) {
self.defaultHomeserverAddress = defaultHomeserverAddress self.defaultHomeserverAddress = defaultHomeserverAddress
self.pushGatewayBaseURL = pushGatewayBaseURL
self.oidcRedirectURL = oidcRedirectURL self.oidcRedirectURL = oidcRedirectURL
self.websiteURL = websiteURL self.websiteURL = websiteURL
self.logoURL = logoURL self.logoURL = logoURL
@@ -206,7 +208,7 @@ final class AppSettings {
// MARK: - Notifications // MARK: - Notifications
var pusherAppId: String { var pusherAppID: String {
#if DEBUG #if DEBUG
InfoPlistReader.main.baseBundleIdentifier + ".ios.dev" InfoPlistReader.main.baseBundleIdentifier + ".ios.dev"
#else #else
@@ -214,7 +216,8 @@ final class AppSettings {
#endif #endif
} }
let pushGatewayBaseURL: URL = "https://matrix.org/_matrix/push/v1/notify" private(set) var pushGatewayBaseURL: URL = "https://matrix.org"
var pushGatewayNotifyEndpoint: URL { pushGatewayBaseURL.appending(path: "_matrix/push/v1/notify") }
@UserPreference(key: UserDefaultsKeys.enableNotifications, defaultValue: true, storageType: .userDefaults(store)) @UserPreference(key: UserDefaultsKeys.enableNotifications, defaultValue: true, storageType: .userDefaults(store))
var enableNotifications var enableNotifications
@@ -145,8 +145,8 @@ final class NotificationManager: NSObject, NotificationManagerProtocol {
pusherNotificationClientIdentifier: clientProxy.pusherNotificationClientIdentifier) pusherNotificationClientIdentifier: clientProxy.pusherNotificationClientIdentifier)
let configuration = try await PusherConfiguration(identifiers: .init(pushkey: deviceToken.base64EncodedString(), let configuration = try await PusherConfiguration(identifiers: .init(pushkey: deviceToken.base64EncodedString(),
appId: appSettings.pusherAppId), appId: appSettings.pusherAppID),
kind: .http(data: .init(url: appSettings.pushGatewayBaseURL.absoluteString, kind: .http(data: .init(url: appSettings.pushGatewayNotifyEndpoint.absoluteString,
format: .eventIdOnly, format: .eventIdOnly,
defaultPayload: defaultPayload.toJsonString())), defaultPayload: defaultPayload.toJsonString())),
appDisplayName: "\(InfoPlistReader.main.bundleDisplayName) (iOS)", appDisplayName: "\(InfoPlistReader.main.bundleDisplayName) (iOS)",
@@ -73,7 +73,7 @@ final class NotificationManagerTests: XCTestCase {
} }
XCTAssertEqual(configuration.identifiers.pushkey, pushkeyData.base64EncodedString()) XCTAssertEqual(configuration.identifiers.pushkey, pushkeyData.base64EncodedString())
XCTAssertEqual(configuration.identifiers.appId, appSettings.pusherAppId) XCTAssertEqual(configuration.identifiers.appId, appSettings.pusherAppID)
XCTAssertEqual(configuration.appDisplayName, "\(InfoPlistReader.main.bundleDisplayName) (iOS)") XCTAssertEqual(configuration.appDisplayName, "\(InfoPlistReader.main.bundleDisplayName) (iOS)")
XCTAssertEqual(configuration.deviceDisplayName, UIDevice.current.name) XCTAssertEqual(configuration.deviceDisplayName, UIDevice.current.name)
XCTAssertNotNil(configuration.profileTag) XCTAssertNotNil(configuration.profileTag)
@@ -82,7 +82,7 @@ final class NotificationManagerTests: XCTestCase {
XCTFail("Http kind expected") XCTFail("Http kind expected")
return return
} }
XCTAssertEqual(data.url, appSettings.pushGatewayBaseURL.absoluteString) XCTAssertEqual(data.url, appSettings.pushGatewayNotifyEndpoint.absoluteString)
XCTAssertEqual(data.format, .eventIdOnly) XCTAssertEqual(data.format, .eventIdOnly)
let defaultPayload = APNSPayload(aps: APSInfo(mutableContent: 1, let defaultPayload = APNSPayload(aps: APSInfo(mutableContent: 1,
alert: APSAlert(locKey: "Notification", alert: APSAlert(locKey: "Notification",