damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

FriendFilter.swift (643B)


      1 //
      2 //  FriendFilter.swift
      3 //  damus
      4 //
      5 //  Created by Daniel D’Aquino on 2023-11-24.
      6 //
      7 
      8 import Foundation
      9 
     10 enum FriendFilter: String, StringCodable {
     11     case all
     12     case friends
     13     
     14     init?(from string: String) {
     15         guard let ff = FriendFilter(rawValue: string) else {
     16             return nil
     17         }
     18         
     19         self = ff
     20     }
     21     
     22     func to_string() -> String {
     23         self.rawValue
     24     }
     25     
     26     func filter(contacts: Contacts, pubkey: Pubkey) -> Bool {
     27         switch self {
     28         case .all:
     29             return true
     30         case .friends:
     31             return contacts.is_in_friendosphere(pubkey)
     32         }
     33     }
     34 }