4
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2025-06-26 12:09:22 +00:00

Allow zulip bridge to specify topic per channel. Closes #701 (#723)

This commit is contained in:
Wim
2019-02-17 21:50:05 +01:00
committed by GitHub
parent 0bcb0b882f
commit a8fe54a78d
3 changed files with 26 additions and 1 deletions

View File

@ -146,6 +146,7 @@ type Protocol struct {
type ChannelOptions struct {
Key string // irc, xmpp
WebhookURL string // discord
Topic string // zulip
}
type Bridge struct {

View File

@ -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]
}