Fixed threading bug on complex slack and slack-legacy gateways.

This commit is contained in:
Patrick Connolly
2018-11-30 20:10:56 +08:00
parent d4a3d96f00
commit 18618ec487

View File

@@ -66,7 +66,7 @@ func (gw *Gateway) FindCanonicalMsgID(protocol string, mID string) string {
v, _ := gw.Messages.Peek(mid)
ids := v.([]*BrMsgID)
for _, downstreamMsgObj := range ids {
if ID == downstreamMsgObj.ID {
if normalizeID(ID) == normalizeID(downstreamMsgObj.ID) {
return strings.Replace(mid.(string), protocol+" ", "", 1)
}
}
@@ -74,6 +74,18 @@ func (gw *Gateway) FindCanonicalMsgID(protocol string, mID string) string {
return ""
}
// Allows matches independant of protocol,
// eg: slack vs slack-legacy
func normalizeID(id string) string {
fields := strings.Fields(id)
if len(fields) != 2 {
return id
}
protocol, mID := fields[0], fields[1]
baseProtocol := strings.Split(protocol, "-")[0]
return baseProtocol+" "+mID
}
func (gw *Gateway) AddBridge(cfg *config.Bridge) error {
br := gw.Router.getBridge(cfg.Account)
if br == nil {