summaryrefslogtreecommitdiffstats
path: root/bridge/mattermost/mattermost.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2022-02-06 18:26:30 +0100
committerGitHub <noreply@github.com>2022-02-06 18:26:30 +0100
commit9c43eff753ec4976f1bd879732915e29c933c5b9 (patch)
tree790f944b59a64bf664e45479899925e1f8aa1d42 /bridge/mattermost/mattermost.go
parentc8d7fdeedcc2fe596055da000bfa8c23c4ba5cab (diff)
downloadmatterbridge-msglm-9c43eff753ec4976f1bd879732915e29c933c5b9.tar.gz
matterbridge-msglm-9c43eff753ec4976f1bd879732915e29c933c5b9.tar.bz2
matterbridge-msglm-9c43eff753ec4976f1bd879732915e29c933c5b9.zip
Add support for using ID in channel config (mattermost) (#1715)
Diffstat (limited to 'bridge/mattermost/mattermost.go')
-rw-r--r--bridge/mattermost/mattermost.go32
1 files changed, 20 insertions, 12 deletions
diff --git a/bridge/mattermost/mattermost.go b/bridge/mattermost/mattermost.go
index f1d3db64..91324be1 100644
--- a/bridge/mattermost/mattermost.go
+++ b/bridge/mattermost/mattermost.go
@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"strings"
+ "sync"
"github.com/42wim/matterbridge/bridge"
"github.com/42wim/matterbridge/bridge/config"
@@ -22,13 +23,19 @@ type Bmattermost struct {
uuid string
TeamID string
*bridge.Config
- avatarMap map[string]string
+ avatarMap map[string]string
+ channelsMutex sync.RWMutex
+ channelInfoMap map[string]*config.ChannelInfo
}
const mattermostPlugin = "mattermost.plugin"
func New(cfg *bridge.Config) bridge.Bridger {
- b := &Bmattermost{Config: cfg, avatarMap: make(map[string]string)}
+ b := &Bmattermost{
+ Config: cfg,
+ avatarMap: make(map[string]string),
+ channelInfoMap: make(map[string]*config.ChannelInfo),
+ }
b.v6 = b.GetBool("v6")
b.uuid = xid.New().String()
@@ -113,14 +120,14 @@ func (b *Bmattermost) JoinChannel(channel config.ChannelInfo) error {
if b.Account == mattermostPlugin {
return nil
}
+
+ b.channelsMutex.Lock()
+ b.channelInfoMap[channel.ID] = &channel
+ b.channelsMutex.Unlock()
+
// we can only join channels using the API
if b.GetString("WebhookURL") == "" && b.GetString("WebhookBindAddress") == "" {
- var id string
- if b.mc6 != nil {
- id = b.mc6.GetChannelID(channel.Name, b.TeamID)
- } else {
- id = b.mc.GetChannelId(channel.Name, b.TeamID)
- }
+ id := b.getChannelID(channel.Name)
if id == "" {
return fmt.Errorf("Could not find channel ID for channel %s", channel.Name)
}
@@ -131,6 +138,7 @@ func (b *Bmattermost) JoinChannel(channel config.ChannelInfo) error {
return b.mc.JoinChannel(id)
}
+
return nil
}
@@ -198,11 +206,11 @@ func (b *Bmattermost) Send(msg config.Message) (string, error) {
if msg.Extra != nil {
for _, rmsg := range helper.HandleExtra(&msg, b.General) {
if b.mc6 != nil {
- if _, err := b.mc6.PostMessage(b.mc.GetChannelId(rmsg.Channel, b.TeamID), rmsg.Username+rmsg.Text, msg.ParentID); err != nil {
+ if _, err := b.mc6.PostMessage(b.getChannelID(rmsg.Channel), rmsg.Username+rmsg.Text, msg.ParentID); err != nil {
b.Log.Errorf("PostMessage failed: %s", err)
}
} else {
- if _, err := b.mc.PostMessage(b.mc.GetChannelId(rmsg.Channel, b.TeamID), rmsg.Username+rmsg.Text, msg.ParentID); err != nil {
+ if _, err := b.mc.PostMessage(b.getChannelID(rmsg.Channel), rmsg.Username+rmsg.Text, msg.ParentID); err != nil {
b.Log.Errorf("PostMessage failed: %s", err)
}
}
@@ -228,8 +236,8 @@ func (b *Bmattermost) Send(msg config.Message) (string, error) {
// Post normal message
if b.mc6 != nil {
- return b.mc6.PostMessage(b.mc6.GetChannelID(msg.Channel, b.TeamID), msg.Text, msg.ParentID) // nolint:wrapcheck
+ return b.mc6.PostMessage(b.getChannelID(msg.Channel), msg.Text, msg.ParentID) // nolint:wrapcheck
}
- return b.mc.PostMessage(b.mc.GetChannelId(msg.Channel, b.TeamID), msg.Text, msg.ParentID)
+ return b.mc.PostMessage(b.getChannelID(msg.Channel), msg.Text, msg.ParentID)
}