5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-22 09:20:27 +00:00

Allow the # in rocketchat channels (backward compatible) (#769)

This commit is contained in:
Wim 2019-03-20 23:19:27 +01:00 committed by GitHub
parent cba01f0865
commit 77516c97db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@ package brocketchat
import ( import (
"errors" "errors"
"strings"
"sync" "sync"
"github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge"
@ -85,14 +86,14 @@ func (b *Brocketchat) JoinChannel(channel config.ChannelInfo) error {
if b.c == nil { if b.c == nil {
return nil return nil
} }
id, err := b.c.GetChannelId(channel.Name) id, err := b.c.GetChannelId(strings.TrimPrefix(channel.Name, "#"))
if err != nil { if err != nil {
return err return err
} }
b.Lock() b.Lock()
b.channelMap[id] = channel.Name b.channelMap[id] = channel.Name
b.Unlock() b.Unlock()
mychannel := &models.Channel{ID: id, Name: channel.Name} mychannel := &models.Channel{ID: id, Name: strings.TrimPrefix(channel.Name, "#")}
if err := b.c.JoinChannel(id); err != nil { if err := b.c.JoinChannel(id); err != nil {
return err return err
} }
@ -103,6 +104,8 @@ func (b *Brocketchat) JoinChannel(channel config.ChannelInfo) error {
} }
func (b *Brocketchat) Send(msg config.Message) (string, error) { func (b *Brocketchat) Send(msg config.Message) (string, error) {
// strip the # if people has set this
msg.Channel = strings.TrimPrefix(msg.Channel, "#")
channel := &models.Channel{ID: b.getChannelID(msg.Channel), Name: msg.Channel} channel := &models.Channel{ID: b.getChannelID(msg.Channel), Name: msg.Channel}
// Delete message // Delete message
@ -131,6 +134,8 @@ func (b *Brocketchat) Send(msg config.Message) (string, error) {
// Upload a file if it exists // Upload a file if it exists
if msg.Extra != nil { if msg.Extra != nil {
for _, rmsg := range helper.HandleExtra(&msg, b.General) { for _, rmsg := range helper.HandleExtra(&msg, b.General) {
// strip the # if people has set this
rmsg.Channel = strings.TrimPrefix(rmsg.Channel, "#")
smsg := &models.Message{ smsg := &models.Message{
RoomID: b.getChannelID(rmsg.Channel), RoomID: b.getChannelID(rmsg.Channel),
Msg: rmsg.Username + rmsg.Text, Msg: rmsg.Username + rmsg.Text,