Adds Key()

This commit is contained in:
Harm Aarts 2013-12-05 16:04:00 +01:00
parent 3b336dc54b
commit 6b6086e389
3 changed files with 22 additions and 2 deletions

View File

@ -28,3 +28,12 @@ type Channel struct {
Author Author Author Author
SubTitle SubTitle SubTitle SubTitle
} }
func (c *Channel) Key() string {
switch {
case len(c.Id) != 0:
return c.Id
default:
return c.Title
}
}

View File

@ -171,13 +171,13 @@ func (this *Feed) makeFeed(doc *xmlx.Document) (err error) {
func (this *Feed) notifyListeners() { func (this *Feed) notifyListeners() {
var newchannels []*Channel var newchannels []*Channel
for _, channel := range this.Channels { 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) newchannels = append(newchannels, channel)
} }
var newitems []*Item var newitems []*Item
for _, item := range channel.Items { 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) newitems = append(newitems, item)
} }
} }

11
item.go
View File

@ -19,3 +19,14 @@ type Item struct {
Contributors []string Contributors []string
Content *Content 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
}
}