Files
damus/damus/Nostr/NostrFilter.swift
William Casarin 6111e244de filter: add reposts query filter helper
Add a filter helper to easily query quote repost queries.

Signed-off-by: William Casarin <jb55@jb55.com>
2024-03-16 12:03:08 +00:00

58 lines
1.7 KiB
Swift

//
// NostrFilter.swift
// damus
//
// Created by William Casarin on 2022-04-11.
//
import Foundation
struct NostrFilter: Codable, Equatable {
var ids: [NoteId]?
var kinds: [NostrKind]?
var referenced_ids: [NoteId]?
var pubkeys: [Pubkey]?
var since: UInt32?
var until: UInt32?
var limit: UInt32?
var authors: [Pubkey]?
var hashtag: [String]?
var parameter: [String]?
var quotes: [NoteId]?
private enum CodingKeys : String, CodingKey {
case ids
case kinds
case referenced_ids = "#e"
case pubkeys = "#p"
case hashtag = "#t"
case parameter = "#d"
case quotes = "#q"
case since
case until
case authors
case limit
}
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) {
self.ids = ids
self.kinds = kinds
self.referenced_ids = referenced_ids
self.pubkeys = pubkeys
self.since = since
self.until = until
self.limit = limit
self.authors = authors
self.hashtag = hashtag
self.quotes = quotes
}
public static func copy(from: NostrFilter) -> NostrFilter {
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)
}
public static func filter_hashtag(_ htags: [String]) -> NostrFilter {
NostrFilter(hashtag: htags.map { $0.lowercased() })
}
}