Removed slack-specific processing from gateway.
This commit is contained in:
@@ -35,7 +35,7 @@ type Message struct {
|
|||||||
Event string `json:"event"`
|
Event string `json:"event"`
|
||||||
Protocol string `json:"protocol"`
|
Protocol string `json:"protocol"`
|
||||||
Gateway string `json:"gateway"`
|
Gateway string `json:"gateway"`
|
||||||
ThreadTs string `json:"thread_timestamp"`
|
ParentID string `json:"parent_id"`
|
||||||
Timestamp time.Time `json:"timestamp"`
|
Timestamp time.Time `json:"timestamp"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Extra map[string][]interface{}
|
Extra map[string][]interface{}
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ func (b *Bslack) handleMessageEvent(ev *slack.MessageEvent) (*config.Message, er
|
|||||||
Account: b.Account,
|
Account: b.Account,
|
||||||
ID: "slack " + ev.Timestamp,
|
ID: "slack " + ev.Timestamp,
|
||||||
Extra: map[string][]interface{}{},
|
Extra: map[string][]interface{}{},
|
||||||
ThreadTs: ev.ThreadTimestamp,
|
ParentID: ev.ThreadTimestamp,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -310,7 +310,7 @@ 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.ThreadTs
|
params.ThreadTimestamp = msg.ParentID
|
||||||
if msg.Avatar != "" {
|
if msg.Avatar != "" {
|
||||||
params.IconURL = msg.Avatar
|
params.IconURL = msg.Avatar
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,20 +83,19 @@ func New(cfg config.Gateway, r *Router) *Gateway {
|
|||||||
return gw
|
return gw
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the timestamp that the message is keyed under in cache
|
// Find the canonical ID that the message is keyed under in cache
|
||||||
func (gw *Gateway) FindUpstreamTimestamp(timestamp string) string {
|
func (gw *Gateway) FindCanonicalMsgID(mID string) string {
|
||||||
if gw.Messages.Contains("slack "+timestamp) {
|
if gw.Messages.Contains(mID) {
|
||||||
return timestamp
|
return mID
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, k := range gw.Messages.Keys() {
|
// If not keyed, iterate through cache for downstream, and infer upstream.
|
||||||
upstreamMsgID := k.(string)
|
for _, mid := range gw.Messages.Keys() {
|
||||||
v, _ := gw.Messages.Peek(k)
|
v, _ := gw.Messages.Peek(mid)
|
||||||
ids := v.([]*BrMsgID)
|
ids := v.([]*BrMsgID)
|
||||||
for _, downstreamMsgObj := range ids {
|
for _, downstreamMsgObj := range ids {
|
||||||
downstreamTimestamp := strings.Fields(downstreamMsgObj.ID)[1]
|
if mID == downstreamMsgObj.ID {
|
||||||
if downstreamTimestamp == timestamp {
|
return mid.(string)
|
||||||
return strings.Fields(upstreamMsgID)[1]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -262,10 +261,11 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
|
|||||||
return brMsgIDs
|
return brMsgIDs
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the upstreamTimestamp of the thread_ts
|
// Get the ID of the parent message in thread
|
||||||
var upstreamTimestamp string
|
var canonicalParentMsgID string
|
||||||
if msg.ThreadTs != "" {
|
if msg.ParentID != "" {
|
||||||
upstreamTimestamp = gw.FindUpstreamTimestamp(msg.ThreadTs)
|
thisParentMsgID := dest.Protocol + " " + msg.ParentID
|
||||||
|
canonicalParentMsgID = gw.FindCanonicalMsgID(thisParentMsgID)
|
||||||
}
|
}
|
||||||
|
|
||||||
originchannel := msg.Channel
|
originchannel := msg.Channel
|
||||||
@@ -284,11 +284,13 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
flog.Debugf("=> Sending %#v from %s (%s) to %s (%s)", msg, msg.Account, originchannel, dest.Account, channel.Name)
|
flog.Debugf("=> Sending %#v from %s (%s) to %s (%s)", msg, msg.Account, originchannel, dest.Account, channel.Name)
|
||||||
|
|
||||||
msg.Channel = channel.Name
|
msg.Channel = channel.Name
|
||||||
msg.Avatar = gw.modifyAvatar(origmsg, dest)
|
msg.Avatar = gw.modifyAvatar(origmsg, dest)
|
||||||
msg.Username = gw.modifyUsername(origmsg, dest)
|
msg.Username = gw.modifyUsername(origmsg, dest)
|
||||||
msg.ID = ""
|
msg.ID = ""
|
||||||
msg.ThreadTs = ""
|
msg.ParentID = ""
|
||||||
|
|
||||||
if res, ok := gw.Messages.Get(origmsg.ID); ok {
|
if res, ok := gw.Messages.Get(origmsg.ID); ok {
|
||||||
IDs := res.([]*BrMsgID)
|
IDs := res.([]*BrMsgID)
|
||||||
for _, id := range IDs {
|
for _, id := range IDs {
|
||||||
@@ -304,17 +306,22 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
|
|||||||
msg.Channel = originchannel
|
msg.Channel = originchannel
|
||||||
}
|
}
|
||||||
|
|
||||||
if upstreamTimestamp != "" {
|
if canonicalParentMsgID != "" {
|
||||||
if res, ok := gw.Messages.Get("slack "+upstreamTimestamp); ok {
|
parentMsgID := ""
|
||||||
|
if res, ok := gw.Messages.Get(canonicalParentMsgID); ok {
|
||||||
IDs := res.([]*BrMsgID)
|
IDs := res.([]*BrMsgID)
|
||||||
for _, id := range IDs {
|
for i, id := range IDs {
|
||||||
// check protocol, bridge name and channelname
|
// check protocol, bridge name and channelname
|
||||||
// for people that reuse the same bridge multiple times. see #342
|
// 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 {
|
if dest.Protocol == id.br.Protocol && dest.Name == id.br.Name && channel.ID == id.ChannelID {
|
||||||
msg.ThreadTs = strings.Fields(id.ID)[1]
|
parentMsgID = IDs[i].ID
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if msg.ThreadTs == "" { msg.ThreadTs = upstreamTimestamp }
|
if parentMsgID == "" {
|
||||||
|
parentMsgID = canonicalParentMsgID
|
||||||
|
}
|
||||||
|
msg.ParentID = strings.Fields(parentMsgID)[1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user