Added broadcasting of news feeds with incremental updates

Added ability to enable broadcasting of news feed items with `NEWS_FEED` notification and broadcasting updated news feed items with `NEWS_FEED_UPDATE` to other modules. This is merged into the default `newsfeed` module.

One can set ability to broadcast the whole news feed or broadcast only updated news feed items.
This commit is contained in:
Charles Dyason
2019-05-31 16:23:40 +02:00
parent 6008cba2db
commit aa80c468c4
3 changed files with 32 additions and 0 deletions

View File

@@ -20,6 +20,8 @@ Module.register("newsfeed",{
],
showSourceTitle: true,
showPublishDate: true,
broadcastNewsFeeds: true,
broadcastNewsUpdates: true,
showDescription: false,
wrapTitle: true,
wrapDescription: true,
@@ -266,6 +268,20 @@ Module.register("newsfeed",{
}, this);
}
// get updated news items and broadcast them
var updatedItems = [];
newsItems.forEach(value => {
if (this.newsItems.findIndex(value1 => value1 === value) === -1) {
// Add item to updated items list
updatedItems.push(value)
}
});
// check if updated items exist, if so and if we should broadcast these updates, then lets do so
if (this.config.broadcastNewsUpdates && updatedItems.length > 0) {
this.sendNotification("NEWS_FEED_UPDATE", {items: updatedItems})
}
this.newsItems = newsItems;
},
@@ -314,6 +330,11 @@ Module.register("newsfeed",{
timer = setInterval(function() {
self.activeItem++;
self.updateDom(self.config.animationSpeed);
// Broadcast NewsFeed if needed
if (self.config.broadcastNewsFeeds) {
self.sendNotification("NEWS_FEED", {items: self.newsItems});
}
}, this.config.updateInterval);
},