Skip to content

Commit

Permalink
set rmsg.Event in RocketChat bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
ldruschk committed Apr 17, 2020
1 parent 7183095 commit 7290177
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
25 changes: 24 additions & 1 deletion bridge/rocketchat/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -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
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions bridge/rocketchat/rocketchat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7290177

Please sign in to comment.