diff options
author | Wim <wim@42.be> | 2022-02-06 18:26:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-06 18:26:30 +0100 |
commit | 9c43eff753ec4976f1bd879732915e29c933c5b9 (patch) | |
tree | 790f944b59a64bf664e45479899925e1f8aa1d42 /bridge/mattermost/helpers.go | |
parent | c8d7fdeedcc2fe596055da000bfa8c23c4ba5cab (diff) | |
download | matterbridge-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/helpers.go')
-rw-r--r-- | bridge/mattermost/helpers.go | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/bridge/mattermost/helpers.go b/bridge/mattermost/helpers.go index 865b8722..7bd766b0 100644 --- a/bridge/mattermost/helpers.go +++ b/bridge/mattermost/helpers.go @@ -241,11 +241,17 @@ func (b *Bmattermost) skipMessage(message *matterclient.Message) bool { if b.GetBool("nosendjoinpart") { return true } + + channelName := b.getChannelName(message.Post.ChannelId) + if channelName == "" { + channelName = message.Channel + } + b.Log.Debugf("Sending JOIN_LEAVE event from %s to gateway", b.Account) b.Remote <- config.Message{ Username: "system", Text: message.Text, - Channel: message.Channel, + Channel: channelName, Account: b.Account, Event: config.EventJoinLeave, } @@ -304,11 +310,17 @@ func (b *Bmattermost) skipMessage6(message *matterclient6.Message) bool { if b.GetBool("nosendjoinpart") { return true } + + channelName := b.getChannelName(message.Post.ChannelId) + if channelName == "" { + channelName = message.Channel + } + b.Log.Debugf("Sending JOIN_LEAVE event from %s to gateway", b.Account) b.Remote <- config.Message{ Username: "system", Text: message.Text, - Channel: message.Channel, + Channel: channelName, Account: b.Account, Event: config.EventJoinLeave, } @@ -376,3 +388,30 @@ func (b *Bmattermost) getVersion() string { return resp.Header.Get("X-Version-Id") } + +func (b *Bmattermost) getChannelID(name string) string { + idcheck := strings.Split(name, "ID:") + if len(idcheck) > 1 { + return idcheck[1] + } + + if b.mc6 != nil { + return b.mc6.GetChannelID(name, b.TeamID) + } + + return b.mc.GetChannelId(name, b.TeamID) +} + +func (b *Bmattermost) getChannelName(id string) string { + b.channelsMutex.RLock() + defer b.channelsMutex.RUnlock() + + for _, c := range b.channelInfoMap { + if c.Name == "ID:"+id { + // if we have ID: specified in our gateway configuration return this + return c.Name + } + } + + return "" +} |