diff --git a/CHANGELOG.md b/CHANGELOG.md index deaa1efc..b5d9eea9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Russian translation for “Feels” - Calendar module: added `nextDaysRelative` config option - Add `broadcastPastEvents` config option for calendars to include events from the past `maximumNumberOfDays` in event broadcasts +- Added feature to broadcast news feed items `NEWS_FEED` and updated news items `NEWS_FEED_UPDATED` in default [newsfeed](https://github.com/MichMich/MagicMirror/tree/develop/modules/default/newsfeed) module (when news is updated) with documented default and `config.js` options in [README.md](https://github.com/MichMich/MagicMirror/blob/develop/modules/default/newsfeed/README.md) ### Updated - English translation for "Feels" to "Feels like" diff --git a/modules/default/newsfeed/README.md b/modules/default/newsfeed/README.md index 2cfc928d..c6c630e1 100644 --- a/modules/default/newsfeed/README.md +++ b/modules/default/newsfeed/README.md @@ -48,6 +48,14 @@ MagicMirror's [notification mechanism](https://github.com/MichMich/MagicMirror/t | `ARTICLE_TOGGLE_FULL` | Toggles article in fullscreen. | `ARTICLE_INFO_REQUEST` | Causes `newsfeed` to respond with the notification `ARTICLE_INFO_RESPONSE`, the payload of which provides the `title`, `source`, `date`, `desc` and `url` of the current news title. +#### Notifications sent by the module +MagicMirror's [notification mechanism](https://github.com/MichMich/MagicMirror/tree/master/modules#thissendnotificationnotification-payload) can also be used to send notifications from the current module to all other modules. The following notifications are broadcasted from this module: + +| Notification Identifier | Description +| ----------------------- | ----------- +| `NEWS_FEED` | Broadcast the current list of news items. +| `NEWS_FEED_UPDATE` | Broadcasts the list of updates news items. + Note the payload of the sent notification event is ignored. #### Example @@ -68,6 +76,8 @@ The following properties can be configured: | `feeds` | An array of feed urls that will be used as source.
More info about this object can be found below.
**Default value:** `[{ title: "New York Times", url: "http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml", encoding: "UTF-8" }]`
You can add `reloadInterval` option to set particular reloadInterval to a feed. | `showSourceTitle` | Display the title of the source.

**Possible values:** `true` or `false`
**Default value:** `true` | `showPublishDate` | Display the publish date of an headline.

**Possible values:** `true` or `false`
**Default value:** `true` +| `broadcastNewsFeeds` | Gives the ability to broadcast news feeds to all modules, by using ```sendNotification()``` when set to `true`, rather than ```sendSocketNotification()``` when `false`

**Possible values:** `true` or `false`
**Default value:** `true` +| `broadcastNewsUpdates` | Gives the ability to broadcast news feed updates to all modules

**Possible values:** `true` or `false`
**Default value:** `true` | `showDescription` | Display the description of an item.

**Possible values:** `true` or `false`
**Default value:** `false` | `wrapTitle` | Wrap the title of the item to multiple lines.

**Possible values:** `true` or `false`
**Default value:** `true` | `wrapDescription` | Wrap the description of the item to multiple lines.

**Possible values:** `true` or `false`
**Default value:** `true` diff --git a/modules/default/newsfeed/newsfeed.js b/modules/default/newsfeed/newsfeed.js index 3bb38d0a..5c048810 100644 --- a/modules/default/newsfeed/newsfeed.js +++ b/modules/default/newsfeed/newsfeed.js @@ -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); },