Handle same account in multiple gateways better

This commit is contained in:
Wim 2017-07-30 16:09:05 +02:00
parent 38d09dba2e
commit 12989bbd99
2 changed files with 12 additions and 12 deletions

View File

@ -170,7 +170,8 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) {
} }
func (gw *Gateway) ignoreMessage(msg *config.Message) bool { 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 return true
} }
if msg.Text == "" { 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) { func (gw *Gateway) modifyMessage(msg *config.Message) {
// replace :emoji: to unicode // replace :emoji: to unicode
msg.Text = emojilib.Replace(msg.Text) msg.Text = emojilib.Replace(msg.Text)
msg.Gateway = gw.Router.getGatewayName(getChannelID(*msg)) msg.Gateway = gw.Name
} }
func getChannelID(msg config.Message) string { func getChannelID(msg config.Message) string {

View File

@ -70,13 +70,14 @@ func (r *Router) getBridge(account string) *bridge.Bridge {
return nil return nil
} }
func (r *Router) getGatewayName(channelID string) string { func (r *Router) getGatewayName(channelID string) []string {
var names []string
for _, gw := range r.Gateways { for _, gw := range r.Gateways {
if _, ok := gw.Channels[channelID]; ok { if _, ok := gw.Channels[channelID]; ok {
return gw.Name names = append(names, gw.Name)
} }
} }
return "" return names
} }
func (r *Router) handleReceive() { func (r *Router) handleReceive() {
@ -103,7 +104,6 @@ func (r *Router) handleReceive() {
} }
} }
for _, gw := range r.Gateways { for _, gw := range r.Gateways {
if gw.Name == r.getGatewayName(getChannelID(msg)) {
if !gw.ignoreMessage(&msg) { if !gw.ignoreMessage(&msg) {
msg.Timestamp = time.Now() msg.Timestamp = time.Now()
gw.modifyMessage(&msg) gw.modifyMessage(&msg)
@ -114,4 +114,3 @@ func (r *Router) handleReceive() {
} }
} }
} }
}