mirror of
https://github.com/42wim/matterbridge.git
synced 2024-12-12 04:02:09 -08:00
Need to specify /topic:mytopic for channel configuration (zulip). (#751)
Breaking change for zulip channel configuration. For zulip the channel configuration will now need to specify also the topic with /topic:yourtopic. Example: [[gateway.inout]] account="zulip.streamchat" channel="general/topic:mytopic" This fixes the incorrect PR #701 which didn't work with multiple gateways.
This commit is contained in:
parent
df3fdc26a0
commit
c557d51b6f
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -18,12 +19,11 @@ type Bzulip struct {
|
|||||||
bot *gzb.Bot
|
bot *gzb.Bot
|
||||||
streams map[int]string
|
streams map[int]string
|
||||||
*bridge.Config
|
*bridge.Config
|
||||||
channelToTopic map[string]string
|
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(cfg *bridge.Config) bridge.Bridger {
|
func New(cfg *bridge.Config) bridge.Bridger {
|
||||||
return &Bzulip{Config: cfg, streams: make(map[int]string), channelToTopic: make(map[string]string)}
|
return &Bzulip{Config: cfg, streams: make(map[int]string)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bzulip) Connect() error {
|
func (b *Bzulip) Connect() error {
|
||||||
@ -48,9 +48,6 @@ func (b *Bzulip) Disconnect() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bzulip) JoinChannel(channel config.ChannelInfo) error {
|
func (b *Bzulip) JoinChannel(channel config.ChannelInfo) error {
|
||||||
b.Lock()
|
|
||||||
defer b.Unlock()
|
|
||||||
b.channelToTopic[channel.Name] = channel.Options.Topic
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +135,14 @@ func (b *Bzulip) handleQueue() error {
|
|||||||
if m.SenderEmail == b.GetString("login") {
|
if m.SenderEmail == b.GetString("login") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
rmsg := config.Message{Username: m.SenderFullName, Text: m.Content, Channel: b.getChannel(m.StreamID), Account: b.Account, UserID: strconv.Itoa(m.SenderID), Avatar: m.AvatarURL}
|
rmsg := config.Message{
|
||||||
|
Username: m.SenderFullName,
|
||||||
|
Text: m.Content,
|
||||||
|
Channel: b.getChannel(m.StreamID) + "/topic:" + m.Subject,
|
||||||
|
Account: b.Account,
|
||||||
|
UserID: strconv.Itoa(m.SenderID),
|
||||||
|
Avatar: m.AvatarURL,
|
||||||
|
}
|
||||||
b.Log.Debugf("<= Sending message from %s on %s to gateway", rmsg.Username, b.Account)
|
b.Log.Debugf("<= Sending message from %s on %s to gateway", rmsg.Username, b.Account)
|
||||||
b.Log.Debugf("<= Message is %#v", rmsg)
|
b.Log.Debugf("<= Message is %#v", rmsg)
|
||||||
b.Remote <- rmsg
|
b.Remote <- rmsg
|
||||||
@ -149,12 +153,11 @@ func (b *Bzulip) handleQueue() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bzulip) sendMessage(msg config.Message) (string, error) {
|
func (b *Bzulip) sendMessage(msg config.Message) (string, error) {
|
||||||
topic := "matterbridge"
|
topic := ""
|
||||||
if b.GetString("topic") != "" {
|
if strings.Contains(msg.Channel, "/topic:") {
|
||||||
topic = b.GetString("topic")
|
res := strings.Split(msg.Channel, "/topic:")
|
||||||
}
|
topic = res[1]
|
||||||
if res := b.getTopic(msg.Channel); res != "" {
|
msg.Channel = res[0]
|
||||||
topic = res
|
|
||||||
}
|
}
|
||||||
m := gzb.Message{
|
m := gzb.Message{
|
||||||
Stream: msg.Channel,
|
Stream: msg.Channel,
|
||||||
@ -202,9 +205,3 @@ func (b *Bzulip) handleUploadFile(msg *config.Message) (string, error) {
|
|||||||
}
|
}
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bzulip) getTopic(channel string) string {
|
|
||||||
b.RLock()
|
|
||||||
defer b.RUnlock()
|
|
||||||
return b.channelToTopic[channel]
|
|
||||||
}
|
|
||||||
|
@ -159,6 +159,10 @@ func (gw *Gateway) mapChannelConfig(cfg []config.Bridge, direction string) {
|
|||||||
gw.logger.Errorf("Mattermost channels do not start with a #: remove the # in %s", br.Channel)
|
gw.logger.Errorf("Mattermost channels do not start with a #: remove the # in %s", br.Channel)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
if strings.HasPrefix(br.Account, "zulip.") && !strings.Contains(br.Channel, "/topic:") {
|
||||||
|
gw.logger.Errorf("Breaking change, since matterbridge 1.14.0 zulip channels need to specify the topic with channel/topic:mytopic in %s of %s", br.Channel, br.Account)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
ID := br.Channel + br.Account
|
ID := br.Channel + br.Account
|
||||||
if _, ok := gw.Channels[ID]; !ok {
|
if _, ok := gw.Channels[ID]; !ok {
|
||||||
channel := &config.ChannelInfo{
|
channel := &config.ChannelInfo{
|
||||||
|
@ -1363,12 +1363,6 @@ Login="yourbot-bot@yourserver.zulipchat.com"
|
|||||||
#REQUIRED
|
#REQUIRED
|
||||||
Server="https://yourserver.zulipchat.com"
|
Server="https://yourserver.zulipchat.com"
|
||||||
|
|
||||||
#Topic of the messages matterbridge will use
|
|
||||||
#OPTIONAL (default "matterbridge")
|
|
||||||
#You can specify a specific topic for each channel using [gateway.inout.options]
|
|
||||||
#See more information below at the gateway configuration
|
|
||||||
Topic="matterbridge"
|
|
||||||
|
|
||||||
## RELOADABLE SETTINGS
|
## RELOADABLE SETTINGS
|
||||||
## Settings below can be reloaded by editing the file
|
## Settings below can be reloaded by editing the file
|
||||||
|
|
||||||
@ -1608,7 +1602,7 @@ enable=true
|
|||||||
# if you specify an empty string bridge will list all the possibilities
|
# if you specify an empty string bridge will list all the possibilities
|
||||||
# - "Group Name" if you specify a group name the bridge will hint its JID to specify
|
# - "Group Name" if you specify a group name the bridge will hint its JID to specify
|
||||||
# as group names might change in time and contain weird emoticons
|
# as group names might change in time and contain weird emoticons
|
||||||
# zulip - stream (without the #)
|
# zulip - stream/topic:topicname (without the #)
|
||||||
#
|
#
|
||||||
# REQUIRED
|
# REQUIRED
|
||||||
channel="#testing"
|
channel="#testing"
|
||||||
@ -1650,10 +1644,7 @@ enable=true
|
|||||||
|
|
||||||
[[gateway.inout]]
|
[[gateway.inout]]
|
||||||
account="zulip.streamchat"
|
account="zulip.streamchat"
|
||||||
channel="general"
|
channel="general/topic:mytopic"
|
||||||
#OPTIONAL - topic only works for zulip
|
|
||||||
[gateway.inout.options]
|
|
||||||
topic="topic1"
|
|
||||||
|
|
||||||
#API example
|
#API example
|
||||||
#[[gateway.inout]]
|
#[[gateway.inout]]
|
||||||
|
Loading…
Reference in New Issue
Block a user