args: add search column argument

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2025-02-22 19:46:23 -08:00
parent e09df3e7c3
commit f7c1a39bc1
3 changed files with 23 additions and 3 deletions

View File

@@ -73,15 +73,27 @@ impl ColumnsArgs {
res.columns
.push(ArgColumn::Timeline(TimelineKind::contact_list(
deck_author.to_owned(),
)))
)));
} else {
panic!("No accounts available, could not handle implicit pubkey contacts column")
panic!("No accounts available, could not handle implicit pubkey contacts column");
}
} else if column_name == "search" {
i += 1;
let search = if let Some(next_arg) = args.get(i) {
next_arg
} else {
error!("search filter argument missing?");
continue;
};
res.columns.push(ArgColumn::Timeline(TimelineKind::search(
search.to_string(),
)));
} else if let Some(notif_pk_str) = column_name.strip_prefix("notifications:") {
if let Ok(pubkey) = Pubkey::parse(notif_pk_str) {
info!("got notifications column for user {}", pubkey.hex());
res.columns
.push(ArgColumn::Timeline(TimelineKind::notifications(pubkey)))
.push(ArgColumn::Timeline(TimelineKind::notifications(pubkey)));
} else {
error!("error parsing notifications pubkey {}", notif_pk_str);
continue;

View File

@@ -24,6 +24,10 @@ impl TokenSerializable for SearchQuery {
}
impl SearchQuery {
pub fn new(search: String) -> Self {
let author: Option<Pubkey> = None;
Self { search, author }
}
/// Convert the query to a filter-compatible MessagePack value
fn to_msgpack_value(&self) -> Value {
let mut values: Vec<(Value, Value)> = Vec::with_capacity(2);

View File

@@ -406,6 +406,10 @@ impl TimelineKind {
TimelineKind::List(ListKind::contact_list(pk))
}
pub fn search(s: String) -> Self {
TimelineKind::Search(SearchQuery::new(s))
}
pub fn is_contacts(&self) -> bool {
matches!(self, TimelineKind::List(ListKind::Contact(_)))
}