diff options
Diffstat (limited to 'gateway')
-rw-r--r-- | gateway/gateway.go | 20 | ||||
-rw-r--r-- | gateway/router.go | 4 |
2 files changed, 12 insertions, 12 deletions
diff --git a/gateway/gateway.go b/gateway/gateway.go index d723d854..72a0f6a6 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -85,8 +85,9 @@ func New(cfg config.Gateway, r *Router) *Gateway { } // Find the canonical ID that the message is keyed under in cache -func (gw *Gateway) FindCanonicalMsgID(mID string) string { - if gw.Messages.Contains(mID) { +func (gw *Gateway) FindCanonicalMsgID(protocol string, mID string) string { + ID := protocol + " " + mID + if gw.Messages.Contains(ID) { return mID } @@ -95,8 +96,8 @@ func (gw *Gateway) FindCanonicalMsgID(mID string) string { v, _ := gw.Messages.Peek(mid) ids := v.([]*BrMsgID) for _, downstreamMsgObj := range ids { - if mID == downstreamMsgObj.ID { - return mid.(string) + if ID == downstreamMsgObj.ID { + return strings.Replace(mid.(string), protocol+" ", "", 1) } } } @@ -234,7 +235,7 @@ func (gw *Gateway) getDestMsgID(msgID string, dest *bridge.Bridge, channel confi // check protocol, bridge name and channelname // for people that reuse the same bridge multiple times. see #342 if dest.Protocol == id.br.Protocol && dest.Name == id.br.Name && channel.ID == id.ChannelID { - return id.ID + return strings.Replace(id.ID, dest.Protocol+" ", "", 1) } } } @@ -280,8 +281,7 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM // Get the ID of the parent message in thread var canonicalParentMsgID string if msg.ParentID != "" && (gw.BridgeValues().General.PreserveThreading || dest.GetBool("PreserveThreading")) { - thisParentMsgID := dest.Protocol + " " + msg.ParentID - canonicalParentMsgID = gw.FindCanonicalMsgID(thisParentMsgID) + canonicalParentMsgID = gw.FindCanonicalMsgID(msg.Protocol, msg.ParentID) } originchannel := msg.Channel @@ -309,14 +309,14 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM msg.Avatar = gw.modifyAvatar(origmsg, dest) msg.Username = gw.modifyUsername(origmsg, dest) - msg.ID = gw.getDestMsgID(origmsg.ID, dest, channel) + msg.ID = gw.getDestMsgID(origmsg.Protocol+" "+origmsg.ID, dest, channel) // for api we need originchannel as channel if dest.Protocol == apiProtocol { msg.Channel = originchannel } - msg.ParentID = gw.getDestMsgID(canonicalParentMsgID, dest, channel) + msg.ParentID = gw.getDestMsgID(origmsg.Protocol+" "+canonicalParentMsgID, dest, channel) if msg.ParentID == "" { msg.ParentID = canonicalParentMsgID } @@ -335,7 +335,7 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM // append the message ID (mID) from this bridge (dest) to our brMsgIDs slice if mID != "" { flog.Debugf("mID %s: %s", dest.Account, mID) - brMsgIDs = append(brMsgIDs, &BrMsgID{dest, mID, channel.ID}) + brMsgIDs = append(brMsgIDs, &BrMsgID{dest, dest.Protocol + " " + mID, channel.ID}) } } return brMsgIDs diff --git a/gateway/router.go b/gateway/router.go index e62df205..99b34378 100644 --- a/gateway/router.go +++ b/gateway/router.go @@ -109,8 +109,8 @@ func (r *Router) handleReceive() { msgIDs = append(msgIDs, gw.handleMessage(msg, br)...) } // only add the message ID if it doesn't already exists - if _, ok := gw.Messages.Get(msg.ID); !ok && msg.ID != "" { - gw.Messages.Add(msg.ID, msgIDs) + if _, ok := gw.Messages.Get(msg.Protocol + " " + msg.ID); !ok && msg.ID != "" { + gw.Messages.Add(msg.Protocol+" "+msg.ID, msgIDs) } } } |