diff --git a/src/listener-rss.ts b/src/listener-rss.ts index 23f1c07..d2c1bca 100644 --- a/src/listener-rss.ts +++ b/src/listener-rss.ts @@ -17,6 +17,7 @@ export class ListenerRss extends EventEmitter { // private fields parser: Parser; loopRunning: boolean = false; + lastEntriesLinks: string[] = []; /** * @brief constructor @@ -66,7 +67,22 @@ export class ListenerRss extends EventEmitter { const fun: () => void = () => { this.fetchRSS() - .then((obj: { [key: string]: any }) => this.emit("update", obj)) + .then((obj: { [key: string]: any }) => { + this.emit("update", obj); + const updatedEntriesLinks = obj.items.map( + (item: { link: string }) => item.link + ); + + const newEntries = obj.items.filter( + (item: { link: string }) => + !this.lastEntriesLinks.includes(item.link) + ); + + if (this.lastEntriesLinks.length !== 0 && newEntries.length !== 0) { + this.emit("newEntries", newEntries); + } + this.lastEntriesLinks = updatedEntriesLinks; + }) .catch((err) => this.emit("error", err)); };