Skip to content

feat(hashtag-column): allow multiple hashtags #817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/notedeck_columns/src/actionbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn execute_note_action(
}

NoteAction::Hashtag(htag) => {
let kind = TimelineKind::Hashtag(htag.clone());
let kind = TimelineKind::Hashtag(vec![htag.to_string()]);
router.route_to(Route::Timeline(kind.clone()));
timeline_cache.open(ndb, note_cache, txn, pool, &kind)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/notedeck_columns/src/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ impl fmt::Display for Route {
TimelineKind::Universe => write!(f, "Universe"),
TimelineKind::Generic(_) => write!(f, "Custom"),
TimelineKind::Search(_) => write!(f, "Search"),
TimelineKind::Hashtag(ht) => write!(f, "Hashtag ({})", ht),
TimelineKind::Hashtag(ht) => write!(f, "Hashtag ({})", ht.join(" ")),
TimelineKind::Thread(_id) => write!(f, "Thread"),
TimelineKind::Profile(_id) => write!(f, "Profile"),
},
Expand Down
32 changes: 22 additions & 10 deletions crates/notedeck_columns/src/timeline/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ pub enum TimelineKind {
/// Generic filter, references a hash of a filter
Generic(u64),

Hashtag(String),
Hashtag(Vec<String>),
}

const NOTIFS_TOKEN_DEPRECATED: &str = "notifs";
Expand Down Expand Up @@ -335,7 +335,7 @@ impl TimelineKind {
}
TimelineKind::Hashtag(ht) => {
writer.write_token("hashtag");
writer.write_token(ht);
writer.write_token(&ht.join(" "));
}
}
}
Expand Down Expand Up @@ -395,7 +395,12 @@ impl TimelineKind {
},
|p| {
p.parse_token("hashtag")?;
Ok(TimelineKind::Hashtag(p.pull_token()?.to_string()))
Ok(TimelineKind::Hashtag(
p.pull_token()?
.split_whitespace()
.map(|s| s.to_string())
.collect(),
))
},
|p| {
p.parse_token("search")?;
Expand Down Expand Up @@ -457,12 +462,19 @@ impl TimelineKind {
.build()]),

TimelineKind::Hashtag(hashtag) => {
let url: &str = &hashtag.to_lowercase();
FilterState::ready(vec![Filter::new()
.kinds([1])
.limit(filter::default_limit())
.tags([url], 't')
.build()])
let filters = hashtag
.iter()
.filter(|tag| !tag.is_empty())
.map(|tag| {
Filter::new()
.kinds([1])
.limit(filter::default_limit())
.tags([tag.to_lowercase().as_str()], 't')
.build()
})
.collect::<Vec<_>>();

FilterState::ready(filters)
}

TimelineKind::Algo(algo_timeline) => match algo_timeline {
Expand Down Expand Up @@ -613,7 +625,7 @@ impl TimelineKind {
TimelineKind::Thread(_root_id) => ColumnTitle::simple("Thread"),
TimelineKind::Universe => ColumnTitle::simple("Universe"),
TimelineKind::Generic(_) => ColumnTitle::simple("Custom"),
TimelineKind::Hashtag(hashtag) => ColumnTitle::formatted(hashtag.to_string()),
TimelineKind::Hashtag(hashtag) => ColumnTitle::formatted(hashtag.join(" ").to_string()),
}
}
}
Expand Down
21 changes: 12 additions & 9 deletions crates/notedeck_columns/src/timeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,18 +243,21 @@ impl Timeline {
))
}

pub fn hashtag(hashtag: String) -> Self {
let hashtag = hashtag.to_lowercase();
let htag: &str = &hashtag;
let filter = Filter::new()
.kinds([1])
.limit(filter::default_limit())
.tags([htag], 't')
.build();
pub fn hashtag(hashtag: Vec<String>) -> Self {
let filters = hashtag
.iter()
.map(|tag| {
Filter::new()
.kinds([1])
.limit(filter::default_limit())
.tags([tag.as_str()], 't')
.build()
})
.collect::<Vec<_>>();

Timeline::new(
TimelineKind::Hashtag(hashtag),
FilterState::ready(vec![filter]),
FilterState::ready(filters),
TimelineTab::only_notes_and_replies(),
)
}
Expand Down
11 changes: 8 additions & 3 deletions crates/notedeck_columns/src/ui/add_column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ pub fn hashtag_ui(

let text_edit = egui::TextEdit::singleline(text_buffer)
.hint_text(
RichText::new("Enter the desired hashtag here")
RichText::new("Enter the desired hashtags here (for multiple space-separated)")
.text_style(NotedeckTextStyle::Body.text_style()),
)
.vertical_align(Align::Center)
Expand All @@ -767,8 +767,13 @@ pub fn hashtag_ui(
.add_sized(egui::vec2(50.0, 40.0), add_column_button())
.clicked()
{
let resp =
AddColumnResponse::Timeline(TimelineKind::Hashtag(sanitize_hashtag(text_buffer)));
let resp = AddColumnResponse::Timeline(TimelineKind::Hashtag(
sanitize_hashtag(text_buffer)
.split_whitespace()
.filter(|s| !s.is_empty())
.map(|s| s.to_string())
.collect::<Vec<_>>(),
));
id_string_map.remove(&id);
Some(resp)
} else {
Expand Down