5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-25 20:11:36 +00:00

Fix in/out logic. Closes #224

This commit is contained in:
Wim 2017-07-22 17:25:22 +02:00
parent d3eef051b1
commit c1c7961dd6

View File

@ -138,45 +138,48 @@ RECONNECT:
br.JoinChannels() br.JoinChannels()
} }
func (gw *Gateway) mapChannelConfig(cfg []config.Bridge, direction string) {
for _, br := range cfg {
if isApi(br.Account) {
br.Channel = "api"
}
ID := br.Channel + br.Account
if _, ok := gw.Channels[ID]; !ok {
channel := &config.ChannelInfo{Name: br.Channel, Direction: direction, ID: ID, Options: br.Options, Account: br.Account,
GID: make(map[string]bool), SameChannel: make(map[string]bool)}
channel.GID[gw.Name] = true
channel.SameChannel[gw.Name] = br.SameChannel
gw.Channels[channel.ID] = channel
} else {
// if we already have a key and it's not our current direction it means we have a bidirectional inout
if gw.Channels[ID].Direction != direction {
gw.Channels[ID].Direction = "inout"
}
}
gw.Channels[ID].GID[gw.Name] = true
gw.Channels[ID].SameChannel[gw.Name] = br.SameChannel
}
}
func (gw *Gateway) mapChannels() error { func (gw *Gateway) mapChannels() error {
for _, br := range append(gw.MyConfig.Out, gw.MyConfig.InOut...) { gw.mapChannelConfig(gw.MyConfig.In, "in")
if isApi(br.Account) { gw.mapChannelConfig(gw.MyConfig.Out, "out")
br.Channel = "api" gw.mapChannelConfig(gw.MyConfig.InOut, "inout")
}
ID := br.Channel + br.Account
_, ok := gw.Channels[ID]
if !ok {
channel := &config.ChannelInfo{Name: br.Channel, Direction: "out", ID: ID, Options: br.Options, Account: br.Account,
GID: make(map[string]bool), SameChannel: make(map[string]bool)}
channel.GID[gw.Name] = true
channel.SameChannel[gw.Name] = br.SameChannel
gw.Channels[channel.ID] = channel
}
gw.Channels[ID].GID[gw.Name] = true
gw.Channels[ID].SameChannel[gw.Name] = br.SameChannel
}
for _, br := range append(gw.MyConfig.In, gw.MyConfig.InOut...) {
if isApi(br.Account) {
br.Channel = "api"
}
ID := br.Channel + br.Account
_, ok := gw.Channels[ID]
if !ok {
channel := &config.ChannelInfo{Name: br.Channel, Direction: "in", ID: ID, Options: br.Options, Account: br.Account,
GID: make(map[string]bool), SameChannel: make(map[string]bool)}
channel.GID[gw.Name] = true
channel.SameChannel[gw.Name] = br.SameChannel
gw.Channels[channel.ID] = channel
}
gw.Channels[ID].GID[gw.Name] = true
gw.Channels[ID].SameChannel[gw.Name] = br.SameChannel
}
return nil return nil
} }
func (gw *Gateway) getDestChannel(msg *config.Message, dest bridge.Bridge) []config.ChannelInfo { func (gw *Gateway) getDestChannel(msg *config.Message, dest bridge.Bridge) []config.ChannelInfo {
var channels []config.ChannelInfo var channels []config.ChannelInfo
// if source channel is in only, do nothing
for _, channel := range gw.Channels {
// lookup the channel from the message
if channel.ID == getChannelID(*msg) {
// we only have destinations if the original message is from an "in" (sending) channel
if !strings.Contains(channel.Direction, "in") {
return channels
}
continue
}
}
for _, channel := range gw.Channels { for _, channel := range gw.Channels {
if _, ok := gw.Channels[getChannelID(*msg)]; !ok { if _, ok := gw.Channels[getChannelID(*msg)]; !ok {
continue continue
@ -191,8 +194,7 @@ func (gw *Gateway) getDestChannel(msg *config.Message, dest bridge.Bridge) []con
} }
continue continue
} }
if strings.Contains(channel.Direction, "out") && channel.Account == dest.Account && gw.validGatewayDest(msg, channel) {
if channel.Direction == "out" && channel.Account == dest.Account && gw.validGatewayDest(msg, channel) {
channels = append(channels, *channel) channels = append(channels, *channel)
} }
} }