Add option to specify custom push notification server for testing
This commit adds an option that allows a user to choose a custom push notification server, as well as the staging notify server, to help with testing Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
This commit is contained in:
@@ -160,7 +160,7 @@ struct PushNotificationClient {
|
||||
}
|
||||
|
||||
func current_push_notification_environment() -> Environment {
|
||||
return self.settings.send_device_token_to_localhost ? .local_test(host: nil) : .production
|
||||
return self.settings.push_notification_environment
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,9 +201,10 @@ extension PushNotificationClient {
|
||||
}
|
||||
|
||||
enum Environment: CaseIterable, Codable, Identifiable, StringCodable, Equatable, Hashable {
|
||||
static var allCases: [Environment] = [.local_test(host: nil), .production]
|
||||
static var allCases: [Environment] = [.local_test(host: nil), .staging, .production]
|
||||
|
||||
case local_test(host: String?)
|
||||
case staging
|
||||
case production
|
||||
|
||||
func text_description() -> String {
|
||||
@@ -212,6 +213,8 @@ extension PushNotificationClient {
|
||||
return NSLocalizedString("Test (local)", comment: "Label indicating a local test environment for Push notification functionality (Developer feature)")
|
||||
case .production:
|
||||
return NSLocalizedString("Production", comment: "Label indicating the production environment for Push notification functionality")
|
||||
case .staging:
|
||||
return NSLocalizedString("Staging (for dev builds)", comment: "Label indicating the staging environment for Push notification functionality")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,6 +224,8 @@ extension PushNotificationClient {
|
||||
URL(string: "http://\(host ?? "localhost:8000")") ?? Constants.PUSH_NOTIFICATION_SERVER_TEST_BASE_URL
|
||||
case .production:
|
||||
Constants.PUSH_NOTIFICATION_SERVER_PRODUCTION_BASE_URL
|
||||
case .staging:
|
||||
Constants.PUSH_NOTIFICATION_SERVER_STAGING_BASE_URL
|
||||
|
||||
}
|
||||
}
|
||||
@@ -240,6 +245,8 @@ extension PushNotificationClient {
|
||||
self = .local_test(host: nil)
|
||||
case "production":
|
||||
self = .production
|
||||
case "staging":
|
||||
self = .staging
|
||||
default:
|
||||
let components = string.split(separator: ":", maxSplits: 1, omittingEmptySubsequences: false)
|
||||
if components.count == 2 && components[0] == "local_test" {
|
||||
@@ -257,6 +264,8 @@ extension PushNotificationClient {
|
||||
return "local_test:\(host)"
|
||||
}
|
||||
return "local_test"
|
||||
case .staging:
|
||||
return "staging"
|
||||
case .production:
|
||||
return "production"
|
||||
}
|
||||
@@ -273,6 +282,8 @@ extension PushNotificationClient {
|
||||
}
|
||||
case .production:
|
||||
return "production"
|
||||
case .staging:
|
||||
return "staging"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,8 +210,8 @@ class UserSettingsStore: ObservableObject {
|
||||
@Setting(key: "enable_experimental_push_notifications", default_value: false)
|
||||
var enable_experimental_push_notifications: Bool
|
||||
|
||||
@Setting(key: "send_device_token_to_localhost", default_value: false)
|
||||
var send_device_token_to_localhost: Bool
|
||||
@StringSetting(key: "push_notification_environment", default_value: .production)
|
||||
var push_notification_environment: PushNotificationClient.Environment
|
||||
|
||||
@Setting(key: "enable_experimental_purple_api", default_value: false)
|
||||
var enable_experimental_purple_api: Bool
|
||||
|
||||
@@ -15,6 +15,7 @@ class Constants {
|
||||
|
||||
// MARK: Push notification server
|
||||
static let PUSH_NOTIFICATION_SERVER_PRODUCTION_BASE_URL: URL = URL(string: "https://notify.damus.io")!
|
||||
static let PUSH_NOTIFICATION_SERVER_STAGING_BASE_URL: URL = URL(string: "https://notify-staging.damus.io")!
|
||||
static let PUSH_NOTIFICATION_SERVER_TEST_BASE_URL: URL = URL(string: "http://localhost:8000")!
|
||||
|
||||
// MARK: Purple
|
||||
|
||||
@@ -21,9 +21,42 @@ struct DeveloperSettingsView: View {
|
||||
|
||||
Toggle(NSLocalizedString("Enable experimental push notifications", comment: "Developer mode setting to enable experimental push notifications."), isOn: $settings.enable_experimental_push_notifications)
|
||||
.toggleStyle(.switch)
|
||||
|
||||
Toggle(NSLocalizedString("Send device token to localhost", comment: "Developer mode setting to send device token metadata to a local server instead of the damus.io server."), isOn: $settings.send_device_token_to_localhost)
|
||||
.toggleStyle(.switch)
|
||||
|
||||
Picker(NSLocalizedString("Push notification environment", comment: "Prompt selection of the Push notification environment (Developer feature to switch between real/production mode to test modes)."),
|
||||
selection: Binding(
|
||||
get: { () -> PushNotificationClient.Environment in
|
||||
switch settings.push_notification_environment {
|
||||
case .local_test(_):
|
||||
return .local_test(host: nil) // Avoid errors related to a value which is not a valid picker option
|
||||
default:
|
||||
return settings.push_notification_environment
|
||||
}
|
||||
},
|
||||
set: { new_value in
|
||||
settings.push_notification_environment = new_value
|
||||
}
|
||||
)
|
||||
) {
|
||||
ForEach(PushNotificationClient.Environment.allCases, id: \.self) { push_notification_environment in
|
||||
Text(push_notification_environment.text_description())
|
||||
.tag(push_notification_environment.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
if case .local_test(_) = settings.push_notification_environment {
|
||||
TextField(
|
||||
NSLocalizedString("URL", comment: "Custom URL host for Damus push notification testing"),
|
||||
text: Binding.init(
|
||||
get: {
|
||||
return settings.push_notification_environment.custom_host() ?? ""
|
||||
}, set: { new_host_value in
|
||||
settings.push_notification_environment = .local_test(host: new_host_value)
|
||||
}
|
||||
)
|
||||
)
|
||||
.disableAutocorrection(true)
|
||||
.autocapitalization(UITextAutocapitalizationType.none)
|
||||
}
|
||||
|
||||
Toggle(NSLocalizedString("Enable experimental Purple API support", comment: "Developer mode setting to enable experimental Purple API support."), isOn: $settings.enable_experimental_purple_api)
|
||||
.toggleStyle(.switch)
|
||||
|
||||
Reference in New Issue
Block a user