Add Damus Purple impending expiry notification support
This commit adds Damus Purple expiry notification support. How it works: Whenever the app initiates or enters the foreground, it checks the user's account expiry, and calculates what notifications to display (It is functional, not imperative, to better match how the notifications view works) The notification handlers work the same as every other notification handler for Nostr events. However, local iOS notifications were not implemented to maintain these reminders more discreet. Current limitations: - Notifications cannot be dismissed - Notifications are dismissed only when Damus Purple is extended - After making a purchase, notifications are not dismissed right away - Bell icon with purple badge shows up on every app restart if user's account is expired Testing ------- Device: iPhone 13 Mini iOS: 17.3.1 Damus: This commit damus-api: d3801376fa204433661be6de8b7974f12b0ad25f Setup: - Local servers Setup - Debug endpoints enabled for changing expiry date on the fly Coverage: 1. Expired account 1. Starting the app on home screen shows bell icon with purple badge. PASS 2. 4 notifications appear on notifications view (7,3,1,0 days to expiry). PASS 3. Notifications appear in correct chronological order. PASS 4. Notifications look consistent in appearance. PASS 5. Expiry notifications' text size follows text size settings. PASS 6. Clicking on notification CTA takes user to account info page. PASS 2. Non-expired account (set expiry, restart app) 1. No expiry notifications, no bell icon. PASS 3. Expiry in 6 days (set expiry, restart app) 1. Starting the app on home screen shows bell icon with purple badge. PASS 2. Starting the app on the notification screen renders notifications the same way. PASS 3. Only one notification (7 days remaining) appears. PASS 4. Expiry in 2 days. PASS 5. General 1. Clicking bell icon clears away "new notifications" badge. PASS 2. Performance of notifications view does not seem affected. PASS 3. Performance of app on startup does not seem affected. PASS 6. IAP 1. Active IAP + expiry date in 2 days does not trigger reminder notification (Because it is auto-renewed). PASS Closes: https://github.com/damus-io/damus/issues/1973 Changelog-Added: Notification reminders for Damus Purple impending expiration Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
This commit is contained in:
@@ -269,6 +269,44 @@ class DamusPurple: StoreObserverDelegate {
|
||||
throw PurpleError.error_processing_response
|
||||
}
|
||||
|
||||
@MainActor
|
||||
func new_ln_checkout(product_template_name: String) async throws -> LNCheckoutInfo? {
|
||||
let url = environment.api_base_url().appendingPathComponent("ln-checkout")
|
||||
|
||||
let json_text: [String: String] = ["product_template_name": product_template_name]
|
||||
let json_data = try JSONSerialization.data(withJSONObject: json_text)
|
||||
|
||||
let (data, response) = try await make_nip98_authenticated_request(
|
||||
method: .post,
|
||||
url: url,
|
||||
payload: json_data,
|
||||
payload_type: .json,
|
||||
auth_keypair: self.keypair
|
||||
)
|
||||
|
||||
if let httpResponse = response as? HTTPURLResponse {
|
||||
switch httpResponse.statusCode {
|
||||
case 200:
|
||||
return try JSONDecoder().decode(LNCheckoutInfo.self, from: data)
|
||||
case 404:
|
||||
return nil
|
||||
default:
|
||||
throw PurpleError.http_response_error(status_code: httpResponse.statusCode, response: data)
|
||||
}
|
||||
}
|
||||
throw PurpleError.error_processing_response
|
||||
}
|
||||
|
||||
@MainActor
|
||||
func generate_verified_ln_checkout_link(product_template_name: String) async throws -> URL {
|
||||
let checkout = try await self.new_ln_checkout(product_template_name: product_template_name)
|
||||
guard let checkout_id = checkout?.id.uuidString.lowercased() else { throw PurpleError.error_processing_response }
|
||||
try await self.verify_npub_for_checkout(checkout_id: checkout_id)
|
||||
return self.environment.purple_landing_page_url()
|
||||
.appendingPathComponent("checkout")
|
||||
.appending(queryItems: [URLQueryItem(name: "id", value: checkout_id)])
|
||||
}
|
||||
|
||||
@MainActor
|
||||
/// This function checks the status of all checkout objects in progress with the server, and it does two things:
|
||||
/// - It returns the ones that were freshly completed
|
||||
|
||||
Reference in New Issue
Block a user