summaryrefslogtreecommitdiffstats
path: root/bridge/zulip/zulip.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2019-02-17 21:50:05 +0100
committerGitHub <noreply@github.com>2019-02-17 21:50:05 +0100
commita8fe54a78d869ce4185ff8f25e90fd87035002ec (patch)
tree2b81715b61c61ff3e7a3b6ff19d378741a28d0f0 /bridge/zulip/zulip.go
parent0bcb0b882f8f49d9ae889165dc4478d1168e1f25 (diff)
downloadmatterbridge-msglm-a8fe54a78d869ce4185ff8f25e90fd87035002ec.tar.gz
matterbridge-msglm-a8fe54a78d869ce4185ff8f25e90fd87035002ec.tar.bz2
matterbridge-msglm-a8fe54a78d869ce4185ff8f25e90fd87035002ec.zip
Allow zulip bridge to specify topic per channel. Closes #701 (#723)
Diffstat (limited to 'bridge/zulip/zulip.go')
-rw-r--r--bridge/zulip/zulip.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/bridge/zulip/zulip.go b/bridge/zulip/zulip.go
index 3c6c7ec6..89c3b059 100644
--- a/bridge/zulip/zulip.go
+++ b/bridge/zulip/zulip.go
@@ -4,6 +4,7 @@ import (
"encoding/json"
"io/ioutil"
"strconv"
+ "sync"
"time"
"github.com/42wim/matterbridge/bridge"
@@ -17,10 +18,12 @@ type Bzulip struct {
bot *gzb.Bot
streams map[int]string
*bridge.Config
+ channelToTopic map[string]string
+ sync.RWMutex
}
func New(cfg *bridge.Config) bridge.Bridger {
- return &Bzulip{Config: cfg, streams: make(map[int]string)}
+ return &Bzulip{Config: cfg, streams: make(map[int]string), channelToTopic: make(map[string]string)}
}
func (b *Bzulip) Connect() error {
@@ -45,6 +48,9 @@ func (b *Bzulip) Disconnect() error {
}
func (b *Bzulip) JoinChannel(channel config.ChannelInfo) error {
+ b.Lock()
+ defer b.Unlock()
+ b.channelToTopic[channel.Name] = channel.Options.Topic
return nil
}
@@ -145,6 +151,9 @@ func (b *Bzulip) sendMessage(msg config.Message) (string, error) {
if b.GetString("topic") != "" {
topic = b.GetString("topic")
}
+ if res := b.getTopic(msg.Channel); res != "" {
+ topic = res
+ }
m := gzb.Message{
Stream: msg.Channel,
Topic: topic,
@@ -191,3 +200,9 @@ func (b *Bzulip) handleUploadFile(msg *config.Message) (string, error) {
}
return "", nil
}
+
+func (b *Bzulip) getTopic(channel string) string {
+ b.RLock()
+ defer b.RUnlock()
+ return b.channelToTopic[channel]
+}