Did cleanup on @42wim's comments.
This commit is contained in:
@@ -310,7 +310,13 @@ func (b *Bslack) prepareMessageParameters(msg *config.Message) *slack.PostMessag
|
|||||||
params.Username = msg.Username
|
params.Username = msg.Username
|
||||||
params.LinkNames = 1 // replace mentions
|
params.LinkNames = 1 // replace mentions
|
||||||
params.IconURL = config.GetIconURL(msg, b.GetString(iconURLConfig))
|
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 != "" {
|
if msg.Avatar != "" {
|
||||||
params.IconURL = msg.Avatar
|
params.IconURL = msg.Avatar
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -225,6 +225,20 @@ func (gw *Gateway) getDestChannel(msg *config.Message, dest bridge.Bridge) []con
|
|||||||
return channels
|
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 {
|
func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrMsgID {
|
||||||
var brMsgIDs []*BrMsgID
|
var brMsgIDs []*BrMsgID
|
||||||
|
|
||||||
@@ -291,37 +305,17 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
|
|||||||
msg.ID = ""
|
msg.ID = ""
|
||||||
msg.ParentID = ""
|
msg.ParentID = ""
|
||||||
|
|
||||||
if res, ok := gw.Messages.Get(origmsg.ID); ok {
|
msg.ID = gw.getDestMsgID(origmsg.ID, dest, channel)
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// for api we need originchannel as channel
|
// for api we need originchannel as channel
|
||||||
if dest.Protocol == "api" {
|
if dest.Protocol == "api" {
|
||||||
msg.Channel = originchannel
|
msg.Channel = originchannel
|
||||||
}
|
}
|
||||||
|
|
||||||
if canonicalParentMsgID != "" {
|
if canonicalParentMsgID != "" {
|
||||||
parentMsgID := ""
|
msg.ParentID = gw.getDestMsgID(canonicalParentMsgID, dest, channel)
|
||||||
if res, ok := gw.Messages.Get(canonicalParentMsgID); ok {
|
if msg.ParentID == "" {
|
||||||
IDs := res.([]*BrMsgID)
|
msg.ParentID = canonicalParentMsgID
|
||||||
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]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user