From 6b6086e389ec379b665d08263c84b16a2bdfbb44 Mon Sep 17 00:00:00 2001 From: Harm Aarts Date: Thu, 5 Dec 2013 16:04:00 +0100 Subject: [PATCH] Adds Key() --- channel.go | 9 +++++++++ feed.go | 4 ++-- item.go | 11 +++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/channel.go b/channel.go index f602675..fe3318b 100644 --- a/channel.go +++ b/channel.go @@ -28,3 +28,12 @@ type Channel struct { Author Author SubTitle SubTitle } + +func (c *Channel) Key() string { + switch { + case len(c.Id) != 0: + return c.Id + default: + return c.Title + } +} diff --git a/feed.go b/feed.go index 05c6e52..c0db240 100644 --- a/feed.go +++ b/feed.go @@ -171,13 +171,13 @@ func (this *Feed) makeFeed(doc *xmlx.Document) (err error) { func (this *Feed) notifyListeners() { var newchannels []*Channel for _, channel := range this.Channels { - if this.database.request <- channel.Title; <-this.database.response { + if this.database.request <- channel.Key(); !<-this.database.response { newchannels = append(newchannels, channel) } var newitems []*Item for _, item := range channel.Items { - if this.database.request <- item.Title; <-this.database.response { + if this.database.request <- item.Key(); !<-this.database.response { newitems = append(newitems, item) } } diff --git a/item.go b/item.go index c5e65fb..86b1cad 100644 --- a/item.go +++ b/item.go @@ -19,3 +19,14 @@ type Item struct { Contributors []string Content *Content } + +func (i *Item) Key() string { + switch { + case i.Guid != nil && len(*i.Guid) != 0: + return *i.Guid + case len(i.Id) != 0: + return i.Id + default: + return i.Title + i.PubDate + } +}