FriendFilter.swift (1116B)
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_of_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_of_friends: 31 return contacts.is_in_friendosphere(pubkey) 32 } 33 } 34 35 func description() -> String { 36 switch self { 37 case .all: 38 return NSLocalizedString("All", comment: "Human-readable short description of the 'friends filter' when it is set to 'all'") 39 case .friends_of_friends: 40 return NSLocalizedString("Friends of friends", comment: "Human-readable short description of the 'friends filter' when it is set to 'friends-of-friends'") 41 } 42 } 43 }