field_ios

In-the-field app for Radroots on iOS
git clone https://radroots.dev/git/field_ios.git
Log | Files | Refs | README | LICENSE

TeraTodayPageModels.swift (3016B)


      1 import Foundation
      2 
      3 struct TeraTodayPageRequest: Sendable, Equatable {
      4   let context: TeraLocalNetwork
      5   let limit: UInt16
      6   let asOfUnixSeconds: UInt64?
      7   let cursor: String?
      8   let viewerTimeZone: String?
      9 
     10   static func first(
     11     context: TeraLocalNetwork,
     12     limit: UInt16,
     13     asOfUnixSeconds: UInt64,
     14     timeZone: TimeZone = .current
     15   ) -> Self {
     16     Self(context: context, limit: limit, asOfUnixSeconds: asOfUnixSeconds, cursor: nil, viewerTimeZone: timeZone.identifier)
     17   }
     18 
     19   static func after(context: TeraLocalNetwork, limit: UInt16, cursor: String) -> Self {
     20     Self(context: context, limit: limit, asOfUnixSeconds: nil, cursor: cursor, viewerTimeZone: nil)
     21   }
     22 }
     23 
     24 struct TeraTodayPage: Sendable, Equatable {
     25   let asOfUnixSeconds: UInt64
     26   let items: [TeraTodayCard]
     27   let nextCursor: String?
     28   var projectionGeneration: UInt64?
     29   let calendar: TeraViewerCalendarContext
     30 }
     31 
     32 struct TeraTodayCard: Sendable, Equatable, Hashable, Identifiable {
     33   let id: String
     34   let type: TeraTodayCardType
     35   let sourceEventID: String
     36   let sourceAddress: String?
     37   let authorPublicKey: String
     38   let contractID: String
     39   let title: String?
     40   let content: String
     41   let authoredAtUnixSeconds: UInt64
     42   let effectiveAtUnixSeconds: UInt64
     43   let calendarTiming: TeraCalendarTiming?
     44   let location: String?
     45   let priceAmount: String?
     46   let priceCurrency: String?
     47   let priceUnit: String?
     48   let quantity: String?
     49   let foodSummary: String?
     50   let foodPublishedAtUnixSeconds: UInt64?
     51   let foodStatus: String?
     52   let contextRank: UInt8
     53   let inclusionReason: String
     54   let media: [TeraMediaReference]
     55   let lifecycle: TeraCardLifecycleState
     56   let rankDigest: String?
     57   let authorProfile: TeraProfileSummary?
     58   let thread: [TeraThreadEntry]
     59   let threadNextCursor: String?
     60   var localSourceDraftID: String?
     61   let localOperationID: String?
     62   let localOperationState: String?
     63 
     64   var authorName: String {
     65     authorProfile?.preferredName
     66       ?? TeraProfileSummary(
     67         authorPublicKey: authorPublicKey,
     68         name: nil,
     69         displayName: nil,
     70         about: nil,
     71         picture: nil,
     72         banner: nil,
     73         nip05: nil,
     74         website: nil,
     75         lightningAddress: nil
     76       ).preferredName
     77   }
     78 
     79   var priceSummary: String? {
     80     guard let priceAmount, let priceCurrency, let priceUnit else { return nil }
     81     return "\(priceAmount) \(priceCurrency)/\(priceUnit)"
     82   }
     83 
     84   var retractionTargetKind: UInt32? {
     85     switch type {
     86     case .update, .photoUpdate, .ask:
     87       guard sourceAddress == nil else { return nil }
     88       return 1
     89     case .event:
     90       guard let kind = sourceAddressKind, kind == 31922 || kind == 31923 else { return nil }
     91       return kind
     92     case .foodAvailability:
     93       guard sourceAddressKind == 30402 else { return nil }
     94       return 30402
     95     }
     96   }
     97 
     98   private var sourceAddressKind: UInt32? {
     99     guard let sourceAddress,
    100       let rawKind = sourceAddress.split(separator: ":", maxSplits: 1).first,
    101       let kind = UInt32(rawKind)
    102     else {
    103       return nil
    104     }
    105     return kind
    106   }
    107 }