From 3b336dc54bdd1c0b798a2e01fe21c29804fc5512 Mon Sep 17 00:00:00 2001 From: Harm Aarts Date: Thu, 5 Dec 2013 15:31:49 +0100 Subject: [PATCH] Adds the database for checking new channels/items. In this iteration the key passed to the database is the Title which is obviously silly. I'm still looking for a configurable way of generating the unique key. --- feed.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/feed.go b/feed.go index 6b9fe33..05c6e52 100644 --- a/feed.go +++ b/feed.go @@ -58,6 +58,9 @@ type Feed struct { // Url from which this feed was created. Url string + // Database containing a list of known Items and Channels for this instance + database *database + // A notification function, used to notify the host when a new channel // has been found. chanhandler ChannelHandler @@ -76,6 +79,7 @@ func New(cachetimeout int, enforcecachelimit bool, ch ChannelHandler, ih ItemHan v.CacheTimeout = cachetimeout v.EnforceCacheLimit = enforcecachelimit v.Type = "none" + v.database = NewDatabase() v.chanhandler = ch v.itemhandler = ih return v @@ -159,9 +163,34 @@ func (this *Feed) makeFeed(doc *xmlx.Document) (err error) { this.CacheTimeout = this.Channels[0].TTL } + this.notifyListeners() + return } +func (this *Feed) notifyListeners() { + var newchannels []*Channel + for _, channel := range this.Channels { + if this.database.request <- channel.Title; <-this.database.response { + newchannels = append(newchannels, channel) + } + + var newitems []*Item + for _, item := range channel.Items { + if this.database.request <- item.Title; <-this.database.response { + newitems = append(newitems, item) + } + } + if len(newitems) > 0 { + this.itemhandler(this, channel, newitems) + } + } + + if len(newchannels) > 0 { + this.chanhandler(this, newchannels) + } +} + // This function returns true or false, depending on whether the CacheTimeout // value has expired or not. Additionally, it will ensure that we adhere to the // RSS spec's SkipDays and SkipHours values (if Feed.EnforceCacheLimit is set to