NostrFilter.swift (1748B)
1 // 2 // NostrFilter.swift 3 // damus 4 // 5 // Created by William Casarin on 2022-04-11. 6 // 7 8 import Foundation 9 10 struct NostrFilter: Codable, Equatable { 11 var ids: [NoteId]? 12 var kinds: [NostrKind]? 13 var referenced_ids: [NoteId]? 14 var pubkeys: [Pubkey]? 15 var since: UInt32? 16 var until: UInt32? 17 var limit: UInt32? 18 var authors: [Pubkey]? 19 var hashtag: [String]? 20 var parameter: [String]? 21 var quotes: [NoteId]? 22 23 private enum CodingKeys : String, CodingKey { 24 case ids 25 case kinds 26 case referenced_ids = "#e" 27 case pubkeys = "#p" 28 case hashtag = "#t" 29 case parameter = "#d" 30 case quotes = "#q" 31 case since 32 case until 33 case authors 34 case limit 35 } 36 37 init(ids: [NoteId]? = nil, kinds: [NostrKind]? = nil, referenced_ids: [NoteId]? = nil, pubkeys: [Pubkey]? = nil, since: UInt32? = nil, until: UInt32? = nil, limit: UInt32? = nil, authors: [Pubkey]? = nil, hashtag: [String]? = nil, quotes: [NoteId]? = nil) { 38 self.ids = ids 39 self.kinds = kinds 40 self.referenced_ids = referenced_ids 41 self.pubkeys = pubkeys 42 self.since = since 43 self.until = until 44 self.limit = limit 45 self.authors = authors 46 self.hashtag = hashtag 47 self.quotes = quotes 48 } 49 50 public static func copy(from: NostrFilter) -> NostrFilter { 51 NostrFilter(ids: from.ids, kinds: from.kinds, referenced_ids: from.referenced_ids, pubkeys: from.pubkeys, since: from.since, until: from.until, authors: from.authors, hashtag: from.hashtag) 52 } 53 54 public static func filter_hashtag(_ htags: [String]) -> NostrFilter { 55 NostrFilter(hashtag: htags.map { $0.lowercased() }) 56 } 57 }