field_ios

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

TeraTodayDiscoveryPresentation.swift (1245B)


      1 import Foundation
      2 
      3 struct TeraTodayDiscoveryPresentation: Sendable, Equatable {
      4   private(set) var continuation: String?
      5   private(set) var hadIncompleteResponses = false
      6   private(set) var isSearching = false
      7   private(set) var hasSearched = false
      8   private(set) var failure: TeraTodayFailure?
      9 
     10   var canSearchOlder: Bool {
     11     continuation != nil && !isSearching
     12   }
     13 
     14   var message: String? {
     15     guard hasSearched else { return nil }
     16     if hadIncompleteResponses {
     17       return "Some relay responses were incomplete. Older searches may leave gaps."
     18     }
     19     if continuation != nil {
     20       return "More posts may be available. Search older posts to continue."
     21     }
     22     return "No more pages were returned in this search."
     23   }
     24 
     25   mutating func begin() {
     26     isSearching = true
     27     failure = nil
     28   }
     29 
     30   mutating func accept(_ receipt: TeraTodayDiscoveryReceipt) {
     31     continuation = receipt.continuation
     32     hadIncompleteResponses = receipt.hadIncompleteResponses
     33     hasSearched = true
     34     failure = nil
     35   }
     36 
     37   mutating func fail(_ error: Error) {
     38     let failure = TeraTodayFailure(error)
     39     self.failure = failure
     40     if failure.requiresRefresh {
     41       continuation = nil
     42     }
     43   }
     44 
     45   mutating func stop() {
     46     isSearching = false
     47   }
     48 }