Skip to content

Commit

Permalink
feat(term): match feed url
Browse files Browse the repository at this point in the history
  • Loading branch information
ymgyt committed Jun 1, 2024
1 parent 6366062 commit d077a32
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 9 deletions.
33 changes: 33 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ axum-server = { version = "0.6.0", features = ["tls-rustls"] }
bitflags = { version = "2.5.0", default-features = false }
chrono = { version = "0.4.31", default-features = false }
clap = { version = "4.5", default-features = false }
fake = { version = "2.9.2", features = ["derive", "chrono"] }
fdlimit = { version = "0.3.0", default-features = false }
feed-rs = { version = "1.4", default-features = false }
futures-util = { version = "0.3.30", default-features = false }
Expand Down
3 changes: 2 additions & 1 deletion crates/synd_term/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ path = "src/main.rs"

[dependencies]
synd-auth = { path = "../synd_auth", version = "0.2.2" }
synd-feed = { path = "../synd_feed", version = "0.3.2" }
synd-feed = { path = "../synd_feed", version = "0.3.2", features = ["fake"] }
synd-o11y = { path = "../synd_o11y", version = "0.1.6" }

anyhow = { workspace = true }
Expand Down Expand Up @@ -65,6 +65,7 @@ synd-test = { path = "../synd_test" }

assert_cmd = { workspace = true }
axum-server = { workspace = true }
fake = { workspace = true }
insta = { workspace = true }
kvsd = { workspace = true }
serial_test = { version = "3.0.0", default_features = false, features = ["async", "file_locks"] }
Expand Down
9 changes: 6 additions & 3 deletions crates/synd_term/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ mod requirement_ext;
pub use requirement_ext::RequirementExt;

#[derive(Debug, Clone)]
#[cfg_attr(test, derive(fake::Dummy))]
pub struct Link {
pub href: String,
pub rel: Option<String>,
Expand Down Expand Up @@ -51,6 +52,7 @@ impl From<mutation::subscribe_feed::Link> for Link {
}

#[derive(Debug, Clone)]
#[cfg_attr(test, derive(fake::Dummy))]
pub struct EntryMeta {
pub title: Option<String>,
pub published: Option<Time>,
Expand Down Expand Up @@ -89,8 +91,9 @@ impl EntryMeta {
}

#[derive(Debug, Clone)]
#[cfg_attr(test, derive(fake::Dummy))]
pub struct Feed {
pub r#type: Option<FeedType>,
pub feed_type: Option<FeedType>,
pub title: Option<String>,
pub url: FeedUrl,
pub updated: Option<Time>,
Expand All @@ -117,7 +120,7 @@ impl Feed {
impl From<query::subscription::Feed> for Feed {
fn from(f: query::subscription::Feed) -> Self {
Self {
r#type: match f.type_ {
feed_type: match f.type_ {
query::subscription::FeedType::ATOM => Some(FeedType::Atom),
query::subscription::FeedType::RSS1 => Some(FeedType::RSS1),
query::subscription::FeedType::RSS2 => Some(FeedType::RSS2),
Expand Down Expand Up @@ -148,7 +151,7 @@ impl From<query::subscription::Feed> for Feed {
impl From<mutation::subscribe_feed::Feed> for Feed {
fn from(f: mutation::subscribe_feed::Feed) -> Self {
Self {
r#type: match f.type_ {
feed_type: match f.type_ {
mutation::subscribe_feed::FeedType::ATOM => Some(FeedType::Atom),
mutation::subscribe_feed::FeedType::RSS1 => Some(FeedType::RSS1),
mutation::subscribe_feed::FeedType::RSS2 => Some(FeedType::RSS2),
Expand Down
38 changes: 34 additions & 4 deletions crates/synd_term/src/ui/components/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static LABELS: &[char] = &[
't', 'u', 'v', 'w', 'x', 'y', 'z',
];

#[derive(Clone, Copy, PartialEq, Eq)]
#[derive(Clone, Debug, Copy, PartialEq, Eq)]
pub(crate) enum FilterResult {
Use,
Discard,
Expand Down Expand Up @@ -85,13 +85,16 @@ impl FeedFilter {
if let Some(FilterCategoryState::Inactive) = self.categories.get(feed.category()) {
return FilterResult::Discard;
}
if !self
if self
.matcher
.r#match(feed.title.as_deref().unwrap_or_default())
|| self
.matcher
.r#match(feed.website_url.as_deref().unwrap_or_default())
{
return FilterResult::Discard;
return FilterResult::Use;
}
FilterResult::Use
FilterResult::Discard
}
}

Expand Down Expand Up @@ -417,3 +420,30 @@ impl Filter {
self.prompt.borrow().render(prompt_area, buf, render_cursor);
}
}

#[cfg(test)]
mod tests {
use fake::{Fake, Faker};

use crate::types::Feed;

use super::*;

#[test]
fn filter_match_feed_url() {
let mut matcher = Matcher::new();
matcher.update_needle("ymgyt");
let filter = FeedFilter {
requirement: Requirement::May,
categories: HashMap::new(),
matcher,
};

let mut feed: Feed = Faker.fake();
// title does not match needle
feed.title = Some("ABC".into());
feed.website_url = Some("https://blog.ymgyt.io".into());

assert_eq!(filter.feed(&feed), FilterResult::Use);
}
}
2 changes: 1 addition & 1 deletion crates/synd_term/src/ui/components/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ impl Subscription {
)),
Cell::new(Line::from(vec![
Span::styled("󰈙 Type ", Style::default().add_modifier(Modifier::BOLD)),
Span::from(match feed.r#type {
Span::from(match feed.feed_type {
Some(FeedType::RSS0) => "RSS 0",
Some(FeedType::RSS1) => "RSS 1",
Some(FeedType::RSS2) => "RSS 2",
Expand Down

0 comments on commit d077a32

Please sign in to comment.