purple: add subscriber number on the Purple supporter badge
This change adds an subscriber number to the supporter badge. Testing -------- PASS Device: iPhone 15 simulator iOS: 17.2 Damus: This commit damus-api: `53fd7fef1c8c0bbf82bb28d1d776e45379433d23` Setup: - `damus-api` running on `npm run dev` mode - Damus configured to enable experimental Purple support + localhost mode Test steps: 1. Wipe local database and rerun server 2. Purchase purple using In-app purchase (Xcode environment) flow 3. Make sure that badge to the side of the user's name on the event shows a golden star without any ordinal numbers 4. Make sure that the badge to the side of the user's name on the profile page shows a golden star with the text "1st" 5. Repeat steps 2–4 and make sure the text says "2nd" 6. Look at the SupporterBadge view previews. Ordinals should show up correctly for all previews (They should always show up, no matter the number) Closes: https://github.com/damus-io/damus/issues/1873 Signed-off-by: Daniel D’Aquino <daniel@daquino.me> Reviewed-by: William Casarin <jb55@jb55.com> Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
committed by
William Casarin
parent
838ce26c64
commit
854036b413
@@ -10,7 +10,7 @@ import Foundation
|
||||
class DamusPurple: StoreObserverDelegate {
|
||||
let environment: ServerEnvironment
|
||||
let keypair: Keypair
|
||||
var starred_profiles_cache: [Pubkey: Bool]
|
||||
var starred_profiles_cache: [Pubkey: UserBadgeInfo]
|
||||
|
||||
init(environment: ServerEnvironment, keypair: Keypair) {
|
||||
self.environment = environment
|
||||
@@ -20,16 +20,23 @@ class DamusPurple: StoreObserverDelegate {
|
||||
|
||||
// MARK: Functions
|
||||
func is_profile_subscribed_to_purple(pubkey: Pubkey) async -> Bool? {
|
||||
return await self.profile_purple_badge_info(pubkey: pubkey)?.active
|
||||
}
|
||||
|
||||
func profile_purple_badge_info(pubkey: Pubkey) async -> UserBadgeInfo? {
|
||||
if let cached_result = self.starred_profiles_cache[pubkey] {
|
||||
return cached_result
|
||||
}
|
||||
|
||||
guard let data = await self.get_account_data(pubkey: pubkey) else { return nil }
|
||||
|
||||
if let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
|
||||
let active = json["active"] as? Bool {
|
||||
self.starred_profiles_cache[pubkey] = active
|
||||
return active
|
||||
guard let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] else { return nil }
|
||||
|
||||
if let active = json["active"] as? Bool {
|
||||
let subscriber_number: Int? = json["subscriber_number"] as? Int
|
||||
let badge_info = UserBadgeInfo(active: active, subscriber_number: subscriber_number)
|
||||
self.starred_profiles_cache[pubkey] = badge_info
|
||||
return badge_info
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -180,6 +187,18 @@ class DamusPurple: StoreObserverDelegate {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct UserBadgeInfo {
|
||||
var active: Bool
|
||||
var subscriber_number: Int?
|
||||
|
||||
func ordinal() -> String? {
|
||||
guard let number = self.subscriber_number else { return nil }
|
||||
let formatter = NumberFormatter()
|
||||
formatter.numberStyle = .ordinal
|
||||
return formatter.string(from: NSNumber(integerLiteral: number))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: API types
|
||||
|
||||
Reference in New Issue
Block a user