Skip to content

Commit

Permalink
Updated rss compares to use new and old function. Added ShowDescripti…
Browse files Browse the repository at this point in the history
…on flag to remove it if is not need.
  • Loading branch information
Billy Ernest committed May 1, 2019
1 parent a97f77b commit 82c1fe3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
9 changes: 8 additions & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "rssfeed",
"name": "RSSFeed",
"description": "This plugin serves as an rss subscription service for Mattermost.",
"version": "0.0.3",
"version": "0.0.4",
"server": {
"executables": {
"linux-amd64": "server/dist/plugin-linux-amd64",
Expand All @@ -25,7 +25,14 @@
"display_name": "User",
"type": "username",
"help_text": "Select the username of the user that the plugin will post with. This can be any user, the name and icon will be overridden when posting."
},
{
"key": "ShowDescription",
"display_name": "Show Description in RSS post.",
"type": "bool",
"help_text": "(Optional) Use this field to hide the description in rss post (Useful if link already returns a valid link back to post)."
}

]
}
}
4 changes: 1 addition & 3 deletions server/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import (
"context"
"fmt"
"github.com/mattermost/mattermost-server/mlog"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/plugin"
//"net/http"
"strings"

"github.com/mattermost/mattermost-server/model"
)

// COMMAND_HELP is the text you see when you type /feed help
Expand Down
5 changes: 3 additions & 2 deletions server/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import (
// If you add non-reference types to your configuration struct, be sure to rewrite Clone as a deep
// copy appropriate for your types.
type configuration struct {
Heartbeat string
Username string
Heartbeat string
Username string
ShowDescription bool
}

// Clone shallow copies the configuration. Your implementation may require a deep copy if
Expand Down
2 changes: 1 addition & 1 deletion server/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ var manifest = struct {
Version string
}{
Id: "rssfeed",
Version: "0.0.3",
Version: "0.0.4",
}
13 changes: 8 additions & 5 deletions server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"github.com/mattermost/mattermost-server/mlog"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/plugin"
"github.com/wbernest/rss-v2-parser"
"io/ioutil"
"net/http"
"strconv"
"sync"
"time"
"github.com/wbernest/rss-v2-parser"
)

const RSSFEED_ICON_URL = "https://mattermost.gridprotectionalliance.org/plugins/rssfeed/images/rss.png"
Expand Down Expand Up @@ -104,12 +104,12 @@ func (p *RSSFeedPlugin) getHeartbeatTime() (int, error) {
}

func (p *RSSFeedPlugin) processSubscription(subscription *Subscription) error {
config := p.getConfiguration()

if len(subscription.URL) == 0 {
return errors.New("no url supplied")
}



// get new rss feed string from url
newRssFeed, newRssFeedString, err := rssv2parser.RssParseURL(subscription.URL)
if err != nil {
Expand All @@ -122,10 +122,13 @@ func (p *RSSFeedPlugin) processSubscription(subscription *Subscription) error {
return err
}

items := rssv2parser.CompareItems(oldRssFeed, newRssFeed)
items := rssv2parser.CompareItemsBetweenOldAndNew(oldRssFeed, newRssFeed)

for _, item := range items {
post := item.Title + "\n" + item.Link + "\n" + html2md.Convert(item.Description) + "\n"
post := item.Title + "\n" + item.Link + "\n"
if config.ShowDescription {
post = post + html2md.Convert(item.Description) + "\n"
}
p.createBotPost(subscription.ChannelID, post, model.POST_DEFAULT)
}

Expand Down

0 comments on commit 82c1fe3

Please sign in to comment.