diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go index 28e63640..23b3adce 100644 --- a/bridge/slack/slack.go +++ b/bridge/slack/slack.go @@ -310,7 +310,13 @@ func (b *Bslack) prepareMessageParameters(msg *config.Message) *slack.PostMessag params.Username = msg.Username params.LinkNames = 1 // replace mentions params.IconURL = config.GetIconURL(msg, b.GetString(iconURLConfig)) - params.ThreadTimestamp = msg.ParentID + msgFields := strings.Fields(msg.ParentID) + if len(msgFields) >= 2 { + msgProtocol, msgID := msgFields[0], msgFields[1] + if msgProtocol == "slack" { + params.ThreadTimestamp = msgID + } + } if msg.Avatar != "" { params.IconURL = msg.Avatar } diff --git a/gateway/gateway.go b/gateway/gateway.go index 32c28617..8cc4fdc4 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -225,6 +225,20 @@ func (gw *Gateway) getDestChannel(msg *config.Message, dest bridge.Bridge) []con return channels } +func (gw *Gateway) getDestMsgID(msgID string, dest *bridge.Bridge, channel config.ChannelInfo) string { + if res, ok := gw.Messages.Get(msgID); ok { + IDs := res.([]*BrMsgID) + for _, id := range IDs { + // 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 "" +} + func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrMsgID { var brMsgIDs []*BrMsgID @@ -291,37 +305,17 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM msg.ID = "" msg.ParentID = "" - if res, ok := gw.Messages.Get(origmsg.ID); ok { - IDs := res.([]*BrMsgID) - for _, id := range IDs { - // 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 { - msg.ID = id.ID - } - } - } + msg.ID = gw.getDestMsgID(origmsg.ID, dest, channel) + // for api we need originchannel as channel if dest.Protocol == "api" { msg.Channel = originchannel } if canonicalParentMsgID != "" { - parentMsgID := "" - if res, ok := gw.Messages.Get(canonicalParentMsgID); ok { - IDs := res.([]*BrMsgID) - for i, id := range IDs { - // 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 { - parentMsgID = IDs[i].ID - break - } - } - if parentMsgID == "" { - parentMsgID = canonicalParentMsgID - } - msg.ParentID = strings.Fields(parentMsgID)[1] + msg.ParentID = gw.getDestMsgID(canonicalParentMsgID, dest, channel) + if msg.ParentID == "" { + msg.ParentID = canonicalParentMsgID } }