summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWim <wim@42.be>2019-03-02 22:58:14 +0100
committerGitHub <noreply@github.com>2019-03-02 22:58:14 +0100
commit53aa0765554a899ba57acd4cb7086b4e69fe8ac8 (patch)
tree5ce268731c5e8476612f1d348c24e56d0592dd17
parentf57370f33abf7e2d61d39f4867c9c95f9fc6cd8c (diff)
downloadmatterbridge-msglm-53aa0765554a899ba57acd4cb7086b4e69fe8ac8.tar.gz
matterbridge-msglm-53aa0765554a899ba57acd4cb7086b4e69fe8ac8.tar.bz2
matterbridge-msglm-53aa0765554a899ba57acd4cb7086b4e69fe8ac8.zip
Do not send duplicate messages (rocketchat). Fixes #745 (#752)
For an unknown reason we get duplicate messages (from the same channel) using the realtime API when we have > 1 channel subscribed on. Solution for now is caching the message ID in a LRU cache and ignoring the duplicates. This should be reviewed when we have actual editing support from the realtime API
-rw-r--r--bridge/rocketchat/handlers.go5
-rw-r--r--bridge/rocketchat/rocketchat.go23
2 files changed, 21 insertions, 7 deletions
diff --git a/bridge/rocketchat/handlers.go b/bridge/rocketchat/handlers.go
index b44ea46f..a41004d4 100644
--- a/bridge/rocketchat/handlers.go
+++ b/bridge/rocketchat/handlers.go
@@ -40,6 +40,11 @@ func (b *Brocketchat) handleRocketHook(messages chan *config.Message) {
func (b *Brocketchat) handleRocketClient(messages chan *config.Message) {
for message := range b.messageChan {
+ // skip messages with same ID, apparently messages get duplicated for an unknown reason
+ if _, ok := b.cache.Get(message.ID); ok {
+ continue
+ }
+ b.cache.Add(message.ID, true)
b.Log.Debugf("message %#v", message)
m := message
if b.skipMessage(&m) {
diff --git a/bridge/rocketchat/rocketchat.go b/bridge/rocketchat/rocketchat.go
index 82b6627d..dac05644 100644
--- a/bridge/rocketchat/rocketchat.go
+++ b/bridge/rocketchat/rocketchat.go
@@ -9,16 +9,18 @@ import (
"github.com/42wim/matterbridge/bridge/helper"
"github.com/42wim/matterbridge/hook/rockethook"
"github.com/42wim/matterbridge/matterhook"
+ lru "github.com/hashicorp/golang-lru"
"github.com/matterbridge/Rocket.Chat.Go.SDK/models"
"github.com/matterbridge/Rocket.Chat.Go.SDK/realtime"
"github.com/matterbridge/Rocket.Chat.Go.SDK/rest"
)
type Brocketchat struct {
- mh *matterhook.Client
- rh *rockethook.Client
- c *realtime.Client
- r *rest.Client
+ mh *matterhook.Client
+ rh *rockethook.Client
+ c *realtime.Client
+ r *rest.Client
+ cache *lru.Cache
*bridge.Config
messageChan chan models.Message
channelMap map[string]string
@@ -27,9 +29,16 @@ type Brocketchat struct {
}
func New(cfg *bridge.Config) bridge.Bridger {
- b := &Brocketchat{Config: cfg}
- b.messageChan = make(chan models.Message)
- b.channelMap = make(map[string]string)
+ newCache, err := lru.New(100)
+ if err != nil {
+ cfg.Log.Fatalf("Could not create LRU cache for rocketchat bridge: %v", err)
+ }
+ b := &Brocketchat{
+ Config: cfg,
+ messageChan: make(chan models.Message),
+ channelMap: make(map[string]string),
+ cache: newCache,
+ }
b.Log.Debugf("enabling rocketchat")
return b
}