Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

commit 02829bd1e3d3bcead67b217cd5d108ad4be2ab67 Author: ldruschk <14059613+ldruschk@users.noreply.github.com> Date: Sat Apr 18 22:00:35 2020 +0000 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. diff --git a/bridge/rocketchat/handlers.go b/bridge/rocketchat/handlers.go index a41004d..80adb31 100644 --- a/bridge/rocketchat/handlers.go +++ b/bridge/rocketchat/handlers.go @@ -26 +27 @@ package brocketchat    import (   "github.com/42wim/matterbridge/bridge/config" + "github.com/matterbridge/Rocket.Chat.Go.SDK/models"  )    func (b *Brocketchat) handleRocket() { @@ -386 +3923 @@ 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 @@ -597 +7712 @@ 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 59f0e99..405bead 100644 --- a/bridge/rocketchat/rocketchat.go +++ b/bridge/rocketchat/rocketchat.go @@ -296 +2912 @@ 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 {