summaryrefslogtreecommitdiffstats
path: root/bridge
diff options
context:
space:
mode:
authorldruschk <14059613+ldruschk@users.noreply.github.com>2020-04-18 22:00:35 +0200
committerGitHub <noreply@github.com>2020-04-18 22:00:35 +0200
commit8e6ddadba20135d990046f05d1a5d2b64b019138 (patch)
treed032afc8fe104d3e635ece51d9e12b9efa771ce2 /bridge
parent8a87a71927d8560ccd993a986be4e7eb34ad46da (diff)
downloadmatterbridge-msglm-8e6ddadba20135d990046f05d1a5d2b64b019138.tar.gz
matterbridge-msglm-8e6ddadba20135d990046f05d1a5d2b64b019138.tar.bz2
matterbridge-msglm-8e6ddadba20135d990046f05d1a5d2b64b019138.zip
Relay Joins/Topic changes in RocketChat bridge (#1085)
This pull request properly sets the events EventJoinLeave and EventTopicChange for messages from the RocketChat bridge and drops messages which are neither one of those events nor plain messages.
Diffstat (limited to 'bridge')
-rw-r--r--bridge/rocketchat/handlers.go25
-rw-r--r--bridge/rocketchat/rocketchat.go6
2 files changed, 30 insertions, 1 deletions
diff --git a/bridge/rocketchat/handlers.go b/bridge/rocketchat/handlers.go
index a41004d4..80adb31e 100644
--- a/bridge/rocketchat/handlers.go
+++ b/bridge/rocketchat/handlers.go
@@ -2,6 +2,7 @@ package brocketchat
import (
"github.com/42wim/matterbridge/bridge/config"
+ "github.com/matterbridge/Rocket.Chat.Go.SDK/models"
)
func (b *Brocketchat) handleRocket() {
@@ -38,6 +39,23 @@ func (b *Brocketchat) handleRocketHook(messages chan *config.Message) {
}
}
+func (b *Brocketchat) handleStatusEvent(ev models.Message, rmsg *config.Message) bool {
+ switch ev.Type {
+ case "":
+ // this is a normal message, no processing needed
+ // return true so the message is not dropped
+ return true
+ case sUserJoined, sUserLeft:
+ rmsg.Event = config.EventJoinLeave
+ return true
+ case sRoomChangedTopic:
+ rmsg.Event = config.EventTopicChange
+ return true
+ }
+ b.Log.Debugf("Dropping message with unknown type: %s", ev.Type)
+ return false
+}
+
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
@@ -59,7 +77,12 @@ func (b *Brocketchat) handleRocketClient(messages chan *config.Message) {
UserID: message.User.ID,
ID: message.ID,
}
- messages <- rmsg
+
+ // handleStatusEvent returns false if the message should be dropped
+ // in that case it is probably some modification to the channel we do not want to relay
+ if b.handleStatusEvent(m, rmsg) {
+ messages <- rmsg
+ }
}
}
diff --git a/bridge/rocketchat/rocketchat.go b/bridge/rocketchat/rocketchat.go
index 59f0e99c..405beadc 100644
--- a/bridge/rocketchat/rocketchat.go
+++ b/bridge/rocketchat/rocketchat.go
@@ -29,6 +29,12 @@ type Brocketchat struct {
sync.RWMutex
}
+const (
+ sUserJoined = "uj"
+ sUserLeft = "ul"
+ sRoomChangedTopic = "room_changed_topic"
+)
+
func New(cfg *bridge.Config) bridge.Bridger {
newCache, err := lru.New(100)
if err != nil {