mirror of
https://github.com/cwinfo/matterbridge.git
synced 2024-11-14 03:50:26 +00:00
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
This commit is contained in:
parent
f57370f33a
commit
53aa076555
@ -40,6 +40,11 @@ func (b *Brocketchat) handleRocketHook(messages chan *config.Message) {
|
|||||||
|
|
||||||
func (b *Brocketchat) handleRocketClient(messages chan *config.Message) {
|
func (b *Brocketchat) handleRocketClient(messages chan *config.Message) {
|
||||||
for message := range b.messageChan {
|
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)
|
b.Log.Debugf("message %#v", message)
|
||||||
m := message
|
m := message
|
||||||
if b.skipMessage(&m) {
|
if b.skipMessage(&m) {
|
||||||
|
@ -9,16 +9,18 @@ import (
|
|||||||
"github.com/42wim/matterbridge/bridge/helper"
|
"github.com/42wim/matterbridge/bridge/helper"
|
||||||
"github.com/42wim/matterbridge/hook/rockethook"
|
"github.com/42wim/matterbridge/hook/rockethook"
|
||||||
"github.com/42wim/matterbridge/matterhook"
|
"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/models"
|
||||||
"github.com/matterbridge/Rocket.Chat.Go.SDK/realtime"
|
"github.com/matterbridge/Rocket.Chat.Go.SDK/realtime"
|
||||||
"github.com/matterbridge/Rocket.Chat.Go.SDK/rest"
|
"github.com/matterbridge/Rocket.Chat.Go.SDK/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Brocketchat struct {
|
type Brocketchat struct {
|
||||||
mh *matterhook.Client
|
mh *matterhook.Client
|
||||||
rh *rockethook.Client
|
rh *rockethook.Client
|
||||||
c *realtime.Client
|
c *realtime.Client
|
||||||
r *rest.Client
|
r *rest.Client
|
||||||
|
cache *lru.Cache
|
||||||
*bridge.Config
|
*bridge.Config
|
||||||
messageChan chan models.Message
|
messageChan chan models.Message
|
||||||
channelMap map[string]string
|
channelMap map[string]string
|
||||||
@ -27,9 +29,16 @@ type Brocketchat struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func New(cfg *bridge.Config) bridge.Bridger {
|
func New(cfg *bridge.Config) bridge.Bridger {
|
||||||
b := &Brocketchat{Config: cfg}
|
newCache, err := lru.New(100)
|
||||||
b.messageChan = make(chan models.Message)
|
if err != nil {
|
||||||
b.channelMap = make(map[string]string)
|
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")
|
b.Log.Debugf("enabling rocketchat")
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user