diff options
author | Wim <wim@42.be> | 2019-02-15 18:20:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-15 18:20:32 +0100 |
commit | 716751cf7685471bbc969e19fe26f23e66f3c0b4 (patch) | |
tree | 6db2350f28a76ae6e1cf7c3cea7263503057d82f /bridge/rocketchat/handlers.go | |
parent | 077b818d82a98855d5577f4f9de5d2b2d2cc6a50 (diff) | |
parent | 6ebd5cbbd8a941e0bc5f99f0d8e99cfd1d8ac0d7 (diff) | |
download | matterbridge-msglm-716751cf7685471bbc969e19fe26f23e66f3c0b4.tar.gz matterbridge-msglm-716751cf7685471bbc969e19fe26f23e66f3c0b4.tar.bz2 matterbridge-msglm-716751cf7685471bbc969e19fe26f23e66f3c0b4.zip |
Refactor and update RocketChat bridge (#707)
* Add support for editing/deleting messages
* Add support for uploading files
* Add support for avatars
* Use the Rocket.Chat.Go.SDK
* Use the rest and streaming api
Diffstat (limited to 'bridge/rocketchat/handlers.go')
-rw-r--r-- | bridge/rocketchat/handlers.go | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/bridge/rocketchat/handlers.go b/bridge/rocketchat/handlers.go new file mode 100644 index 00000000..b44ea46f --- /dev/null +++ b/bridge/rocketchat/handlers.go @@ -0,0 +1,69 @@ +package brocketchat + +import ( + "github.com/42wim/matterbridge/bridge/config" +) + +func (b *Brocketchat) handleRocket() { + messages := make(chan *config.Message) + if b.GetString("WebhookBindAddress") != "" { + b.Log.Debugf("Choosing webhooks based receiving") + go b.handleRocketHook(messages) + } else { + b.Log.Debugf("Choosing login/password based receiving") + go b.handleRocketClient(messages) + } + for message := range messages { + message.Account = b.Account + b.Log.Debugf("<= Sending message from %s on %s to gateway", message.Username, b.Account) + b.Log.Debugf("<= Message is %#v", message) + b.Remote <- *message + } +} + +func (b *Brocketchat) handleRocketHook(messages chan *config.Message) { + for { + message := b.rh.Receive() + b.Log.Debugf("Receiving from rockethook %#v", message) + // do not loop + if message.UserName == b.GetString("Nick") { + continue + } + messages <- &config.Message{ + UserID: message.UserID, + Username: message.UserName, + Text: message.Text, + Channel: message.ChannelName, + } + } +} + +func (b *Brocketchat) handleRocketClient(messages chan *config.Message) { + for message := range b.messageChan { + b.Log.Debugf("message %#v", message) + m := message + if b.skipMessage(&m) { + b.Log.Debugf("Skipped message: %#v", message) + continue + } + + rmsg := &config.Message{Text: message.Msg, + Username: message.User.UserName, + Channel: b.getChannelName(message.RoomID), + Account: b.Account, + UserID: message.User.ID, + ID: message.ID, + } + messages <- rmsg + } +} + +func (b *Brocketchat) handleUploadFile(msg *config.Message) error { + for _, f := range msg.Extra["file"] { + fi := f.(config.FileInfo) + if err := b.uploadFile(&fi, b.getChannelID(msg.Channel)); err != nil { + return err + } + } + return nil +} |