add newEntries event
This commit is contained in:
parent
dd4bf59e41
commit
01392a2c20
|
@ -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));
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user