purple: switch local testing to staging testing
This commit is contained in:
@@ -63,7 +63,7 @@ class DamusState: HeadlessDamusState {
|
|||||||
self.video = video
|
self.video = video
|
||||||
self.ndb = ndb
|
self.ndb = ndb
|
||||||
self.purple = purple ?? DamusPurple(
|
self.purple = purple ?? DamusPurple(
|
||||||
environment: settings.purple_api_local_test_mode ? .local_test : .production,
|
settings: settings,
|
||||||
keypair: keypair
|
keypair: keypair
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,12 +8,12 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
class DamusPurple: StoreObserverDelegate {
|
class DamusPurple: StoreObserverDelegate {
|
||||||
let environment: ServerEnvironment
|
let settings: UserSettingsStore
|
||||||
let keypair: Keypair
|
let keypair: Keypair
|
||||||
var starred_profiles_cache: [Pubkey: UserBadgeInfo]
|
var starred_profiles_cache: [Pubkey: UserBadgeInfo]
|
||||||
|
|
||||||
init(environment: ServerEnvironment, keypair: Keypair) {
|
init(settings: UserSettingsStore, keypair: Keypair) {
|
||||||
self.environment = environment
|
self.settings = settings
|
||||||
self.keypair = keypair
|
self.keypair = keypair
|
||||||
self.starred_profiles_cache = [:]
|
self.starred_profiles_cache = [:]
|
||||||
}
|
}
|
||||||
@@ -23,6 +23,10 @@ class DamusPurple: StoreObserverDelegate {
|
|||||||
return await self.profile_purple_badge_info(pubkey: pubkey)?.active
|
return await self.profile_purple_badge_info(pubkey: pubkey)?.active
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var environment: ServerEnvironment {
|
||||||
|
self.settings.purple_api_staging ? .staging : .production
|
||||||
|
}
|
||||||
|
|
||||||
func profile_purple_badge_info(pubkey: Pubkey) async -> UserBadgeInfo? {
|
func profile_purple_badge_info(pubkey: Pubkey) async -> UserBadgeInfo? {
|
||||||
if let cached_result = self.starred_profiles_cache[pubkey] {
|
if let cached_result = self.starred_profiles_cache[pubkey] {
|
||||||
return cached_result
|
return cached_result
|
||||||
@@ -216,12 +220,12 @@ extension DamusPurple {
|
|||||||
|
|
||||||
extension DamusPurple {
|
extension DamusPurple {
|
||||||
enum ServerEnvironment {
|
enum ServerEnvironment {
|
||||||
case local_test
|
case staging
|
||||||
case production
|
case production
|
||||||
|
|
||||||
func get_base_url() -> URL {
|
func get_base_url() -> URL {
|
||||||
switch self {
|
switch self {
|
||||||
case .local_test:
|
case .staging:
|
||||||
Constants.PURPLE_API_TEST_BASE_URL
|
Constants.PURPLE_API_TEST_BASE_URL
|
||||||
case .production:
|
case .production:
|
||||||
Constants.PURPLE_API_PRODUCTION_BASE_URL
|
Constants.PURPLE_API_PRODUCTION_BASE_URL
|
||||||
|
|||||||
@@ -205,8 +205,8 @@ class UserSettingsStore: ObservableObject {
|
|||||||
@Setting(key: "enable_experimental_purple_api", default_value: false)
|
@Setting(key: "enable_experimental_purple_api", default_value: false)
|
||||||
var enable_experimental_purple_api: Bool
|
var enable_experimental_purple_api: Bool
|
||||||
|
|
||||||
@Setting(key: "purple_api_local_test_mode", default_value: false)
|
@Setting(key: "purple_api_staging", default_value: false)
|
||||||
var purple_api_local_test_mode: Bool
|
var purple_api_staging: Bool
|
||||||
|
|
||||||
@Setting(key: "emoji_reactions", default_value: default_emoji_reactions)
|
@Setting(key: "emoji_reactions", default_value: default_emoji_reactions)
|
||||||
var emoji_reactions: [String]
|
var emoji_reactions: [String]
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ func make_nip98_authenticated_request(method: HTTPMethod, url: URL, payload: Dat
|
|||||||
createdAt: UInt32(Date().timeIntervalSince1970)
|
createdAt: UInt32(Date().timeIntervalSince1970)
|
||||||
)
|
)
|
||||||
|
|
||||||
let auth_note_json_data: Data = try JSONEncoder().encode(auth_note)
|
let auth_note_json_data: Data = try encode_json_data(auth_note)
|
||||||
let auth_note_base64: String = base64_encode(auth_note_json_data.bytes)
|
let auth_note_base64: String = base64_encode(auth_note_json_data.bytes)
|
||||||
|
|
||||||
request.setValue("Nostr " + auth_note_base64, forHTTPHeaderField: "Authorization")
|
request.setValue("Nostr " + auth_note_base64, forHTTPHeaderField: "Authorization")
|
||||||
|
|||||||
@@ -325,7 +325,13 @@ func decode_nostr_event(txt: String) -> NostrResponse? {
|
|||||||
func encode_json<T: Encodable>(_ val: T) -> String? {
|
func encode_json<T: Encodable>(_ val: T) -> String? {
|
||||||
let encoder = JSONEncoder()
|
let encoder = JSONEncoder()
|
||||||
encoder.outputFormatting = .withoutEscapingSlashes
|
encoder.outputFormatting = .withoutEscapingSlashes
|
||||||
return (try? encoder.encode(val)).map { String(decoding: $0, as: UTF8.self) }
|
return (try? encode_json_data(val)).map { String(decoding: $0, as: UTF8.self) }
|
||||||
|
}
|
||||||
|
|
||||||
|
func encode_json_data<T: Encodable>(_ val: T) throws -> Data {
|
||||||
|
let encoder = JSONEncoder()
|
||||||
|
encoder.outputFormatting = .withoutEscapingSlashes
|
||||||
|
return try encoder.encode(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
func decode_nostr_event_json(json: String) -> NostrEvent? {
|
func decode_nostr_event_json(json: String) -> NostrEvent? {
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ class Constants {
|
|||||||
static let DEVICE_TOKEN_RECEIVER_TEST_URL: URL = URL(string: "http://localhost:8000/user-info")!
|
static let DEVICE_TOKEN_RECEIVER_TEST_URL: URL = URL(string: "http://localhost:8000/user-info")!
|
||||||
static let MAIN_APP_BUNDLE_IDENTIFIER: String = "com.jb55.damus2"
|
static let MAIN_APP_BUNDLE_IDENTIFIER: String = "com.jb55.damus2"
|
||||||
static let NOTIFICATION_EXTENSION_BUNDLE_IDENTIFIER: String = "com.jb55.damus2.DamusNotificationService"
|
static let NOTIFICATION_EXTENSION_BUNDLE_IDENTIFIER: String = "com.jb55.damus2.DamusNotificationService"
|
||||||
static let PURPLE_API_PRODUCTION_BASE_URL: URL = URL(string: "https://purple.damus.io")!
|
static let PURPLE_API_PRODUCTION_BASE_URL: URL = URL(string: "https://api.damus.io")!
|
||||||
static let PURPLE_API_TEST_BASE_URL: URL = URL(string: "http://127.0.0.1:8989")!
|
static let PURPLE_API_TEST_BASE_URL: URL = URL(string: "https://api-staging.damus.io")!
|
||||||
static let PURPLE_LANDING_PAGE_TEST_URL: URL = URL(string: "http://localhost:3000/purple")!
|
static let PURPLE_LANDING_PAGE_TEST_URL: URL = URL(string: "https://staging.damus.io/purple")!
|
||||||
static let PURPLE_LANDING_PAGE_PRODUCTION_URL: URL = URL(string: "https://damus.io/purple")!
|
static let PURPLE_LANDING_PAGE_PRODUCTION_URL: URL = URL(string: "https://damus.io/purple")!
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -412,7 +412,7 @@ struct DamusPurpleView: View {
|
|||||||
Spacer()
|
Spacer()
|
||||||
Link(
|
Link(
|
||||||
NSLocalizedString("Learn more", comment: "Label for a link to the Damus Purple landing page"),
|
NSLocalizedString("Learn more", comment: "Label for a link to the Damus Purple landing page"),
|
||||||
destination: damus_state.settings.purple_api_local_test_mode ? Constants.PURPLE_LANDING_PAGE_TEST_URL : Constants.PURPLE_LANDING_PAGE_PRODUCTION_URL
|
destination: damus_state.settings.purple_api_staging ? Constants.PURPLE_LANDING_PAGE_TEST_URL : Constants.PURPLE_LANDING_PAGE_PRODUCTION_URL
|
||||||
)
|
)
|
||||||
.foregroundColor(DamusColors.pink)
|
.foregroundColor(DamusColors.pink)
|
||||||
.padding()
|
.padding()
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ struct DeveloperSettingsView: View {
|
|||||||
Toggle("Enable experimental Purple API support", isOn: $settings.enable_experimental_purple_api)
|
Toggle("Enable experimental Purple API support", isOn: $settings.enable_experimental_purple_api)
|
||||||
.toggleStyle(.switch)
|
.toggleStyle(.switch)
|
||||||
|
|
||||||
Toggle("Purple API localhost test mode", isOn: $settings.purple_api_local_test_mode)
|
Toggle("Purple API staging mode", isOn: $settings.purple_api_staging)
|
||||||
.toggleStyle(.switch)
|
.toggleStyle(.switch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user