summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-07-30 16:09:05 +0200
committerWim <wim@42.be>2017-07-30 16:09:05 +0200
commit12989bbd99768facafe5d77dec98ff2908502499 (patch)
tree240bd84161474d023e7ff414de4b765e9ca180ca
parent38d09dba2e02a3136ea202cea8b6df58dea19d1d (diff)
downloadmatterbridge-msglm-12989bbd99768facafe5d77dec98ff2908502499.tar.gz
matterbridge-msglm-12989bbd99768facafe5d77dec98ff2908502499.tar.bz2
matterbridge-msglm-12989bbd99768facafe5d77dec98ff2908502499.zip
Handle same account in multiple gateways better
-rw-r--r--gateway/gateway.go5
-rw-r--r--gateway/router.go19
2 files changed, 12 insertions, 12 deletions
diff --git a/gateway/gateway.go b/gateway/gateway.go
index dfd0604a..86fa5723 100644
--- a/gateway/gateway.go
+++ b/gateway/gateway.go
@@ -170,7 +170,8 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) {
}
func (gw *Gateway) ignoreMessage(msg *config.Message) bool {
- if gw.Router.getGatewayName(getChannelID(*msg)) != gw.Name {
+ // if we don't have the bridge, ignore it
+ if _, ok := gw.Bridges[msg.Account]; !ok {
return true
}
if msg.Text == "" {
@@ -240,7 +241,7 @@ func (gw *Gateway) modifyAvatar(msg config.Message, dest *bridge.Bridge) string
func (gw *Gateway) modifyMessage(msg *config.Message) {
// replace :emoji: to unicode
msg.Text = emojilib.Replace(msg.Text)
- msg.Gateway = gw.Router.getGatewayName(getChannelID(*msg))
+ msg.Gateway = gw.Name
}
func getChannelID(msg config.Message) string {
diff --git a/gateway/router.go b/gateway/router.go
index 26c09968..eb8251ed 100644
--- a/gateway/router.go
+++ b/gateway/router.go
@@ -70,13 +70,14 @@ func (r *Router) getBridge(account string) *bridge.Bridge {
return nil
}
-func (r *Router) getGatewayName(channelID string) string {
+func (r *Router) getGatewayName(channelID string) []string {
+ var names []string
for _, gw := range r.Gateways {
if _, ok := gw.Channels[channelID]; ok {
- return gw.Name
+ names = append(names, gw.Name)
}
}
- return ""
+ return names
}
func (r *Router) handleReceive() {
@@ -103,13 +104,11 @@ func (r *Router) handleReceive() {
}
}
for _, gw := range r.Gateways {
- if gw.Name == r.getGatewayName(getChannelID(msg)) {
- if !gw.ignoreMessage(&msg) {
- msg.Timestamp = time.Now()
- gw.modifyMessage(&msg)
- for _, br := range gw.Bridges {
- gw.handleMessage(msg, br)
- }
+ if !gw.ignoreMessage(&msg) {
+ msg.Timestamp = time.Now()
+ gw.modifyMessage(&msg)
+ for _, br := range gw.Bridges {
+ gw.handleMessage(msg, br)
}
}
}