diff options
-rw-r--r-- | internal/feed/cache.go | 2 | ||||
-rw-r--r-- | internal/feed/cache_v1.go | 10 | ||||
-rw-r--r-- | internal/feed/feed.go | 9 | ||||
-rw-r--r-- | internal/feed/state.go | 2 | ||||
-rw-r--r-- | pkg/config/config.go | 5 |
5 files changed, 21 insertions, 7 deletions
diff --git a/internal/feed/cache.go b/internal/feed/cache.go index b92bfa7..df7559b 100644 --- a/internal/feed/cache.go +++ b/internal/feed/cache.go @@ -27,7 +27,7 @@ type CachedFeed interface { Checked(withFailure bool) Failures() uint Last() time.Time - filterItems([]feeditem, bool) []feeditem + filterItems(items []feeditem, ignoreHash bool, alwaysNew bool) []feeditem Commit() } diff --git a/internal/feed/cache_v1.go b/internal/feed/cache_v1.go index 45182dc..0e43eab 100644 --- a/internal/feed/cache_v1.go +++ b/internal/feed/cache_v1.go @@ -171,7 +171,7 @@ func (cf *cachedFeed) deleteItem(index int) { cf.Items = cf.Items[:len(cf.Items)-1] } -func (cf *cachedFeed) filterItems(items []feeditem, ignoreHash bool) []feeditem { +func (cf *cachedFeed) filterItems(items []feeditem, ignoreHash, alwaysNew bool) []feeditem { if len(items) == 0 { return items } @@ -200,7 +200,7 @@ CACHE_ITEMS: if cf.LastCheck.IsZero() || ci.PublishedDate.After(cf.LastCheck) { log.Debug("Newer than last check, including.") - item.addReason("newer") + item.addReason("time") app(item, ci, nil) continue } @@ -233,6 +233,11 @@ CACHE_ITEMS: } if oldItem.Link == ci.Link { + if alwaysNew { + log.Debugf("Link matches, but `always-new`.") + item.addReason("always-new") + continue + } log.Debugf("Link matches, updating: %s", oldItem) item.addReason("link (upd)") app(item, ci, &idx) @@ -242,6 +247,7 @@ CACHE_ITEMS: } log.Debugf("No match found, inserting.") + item.addReason("new") app(item, ci, nil) } diff --git a/internal/feed/feed.go b/internal/feed/feed.go index 433d080..0038335 100644 --- a/internal/feed/feed.go +++ b/internal/feed/feed.go @@ -7,6 +7,7 @@ import ( "github.com/Necoro/feed2imap-go/pkg/config" "github.com/Necoro/feed2imap-go/pkg/log" + "github.com/Necoro/feed2imap-go/pkg/util" ) type Feed struct { @@ -28,15 +29,17 @@ type feeditem struct { reasons []string } -func (item feeditem) Creator() string { +func (item *feeditem) Creator() string { if item.Item.Author != nil { return item.Item.Author.Name } return "" } -func (item feeditem) addReason(reason string) { - item.reasons = append(item.reasons, reason) +func (item *feeditem) addReason(reason string) { + if !util.StrContains(item.reasons, reason) { + item.reasons = append(item.reasons, reason) + } } func (feed *Feed) descriptor() feedDescriptor { diff --git a/internal/feed/state.go b/internal/feed/state.go index ea9239a..455602c 100644 --- a/internal/feed/state.go +++ b/internal/feed/state.go @@ -72,7 +72,7 @@ func filterFeed(feed *Feed) { origLen := len(feed.items) log.Debugf("Filtering %s. Starting with %d items", feed.Name, origLen) - items := feed.cached.filterItems(feed.items, *feed.Options.IgnHash) + items := feed.cached.filterItems(feed.items, *feed.Options.IgnHash, *feed.Options.AlwaysNew) feed.items = items newLen := len(feed.items) diff --git a/pkg/config/config.go b/pkg/config/config.go index b24a9e8..37dffcf 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -39,6 +39,7 @@ type Options struct { InclImages *bool `yaml:"include-images"` Disable *bool `yaml:"disable"` IgnHash *bool `yaml:"ignore-hash"` + AlwaysNew *bool `yaml:"always-new"` } func (opt *Options) mergeFrom(other Options) { @@ -51,6 +52,9 @@ func (opt *Options) mergeFrom(other Options) { if opt.IgnHash == nil { opt.IgnHash = other.IgnHash } + if opt.AlwaysNew == nil { + opt.AlwaysNew = other.AlwaysNew + } if opt.Disable == nil { opt.Disable = other.Disable } @@ -66,6 +70,7 @@ func init() { MinFreq: &one, InclImages: &fal, IgnHash: &fal, + AlwaysNew: &fal, Disable: &fal, } } |