mirror of
https://github.com/cwinfo/matterbridge.git
synced 2024-11-22 14:00:27 +00:00
Add protocol to msg.ID in cache (#596)
This commit is contained in:
parent
57eba77561
commit
ae32bae791
@ -205,7 +205,7 @@ func (b *Bslack) handleStatusEvent(ev *slack.MessageEvent, rmsg *config.Message)
|
|||||||
case sMessageDeleted:
|
case sMessageDeleted:
|
||||||
rmsg.Text = config.EventMsgDelete
|
rmsg.Text = config.EventMsgDelete
|
||||||
rmsg.Event = config.EventMsgDelete
|
rmsg.Event = config.EventMsgDelete
|
||||||
rmsg.ID = "slack " + ev.DeletedTimestamp
|
rmsg.ID = ev.DeletedTimestamp
|
||||||
// If a message is being deleted we do not need to process
|
// If a message is being deleted we do not need to process
|
||||||
// the event any further so we return 'true'.
|
// the event any further so we return 'true'.
|
||||||
return true
|
return true
|
||||||
|
@ -173,9 +173,10 @@ func (b *Bslack) populateReceivedMessage(ev *slack.MessageEvent) (*config.Messag
|
|||||||
Text: ev.Text,
|
Text: ev.Text,
|
||||||
Channel: channel.Name,
|
Channel: channel.Name,
|
||||||
Account: b.Account,
|
Account: b.Account,
|
||||||
ID: "slack " + ev.Timestamp,
|
ID: ev.Timestamp,
|
||||||
Extra: make(map[string][]interface{}),
|
Extra: make(map[string][]interface{}),
|
||||||
ParentID: ev.ThreadTimestamp,
|
ParentID: ev.ThreadTimestamp,
|
||||||
|
Protocol: b.Protocol,
|
||||||
}
|
}
|
||||||
if b.useChannelID {
|
if b.useChannelID {
|
||||||
rmsg.Channel = "ID:" + channel.ID
|
rmsg.Channel = "ID:" + channel.ID
|
||||||
@ -183,7 +184,7 @@ func (b *Bslack) populateReceivedMessage(ev *slack.MessageEvent) (*config.Messag
|
|||||||
|
|
||||||
// Handle 'edit' messages.
|
// Handle 'edit' messages.
|
||||||
if ev.SubMessage != nil && !b.GetBool(editDisableConfig) {
|
if ev.SubMessage != nil && !b.GetBool(editDisableConfig) {
|
||||||
rmsg.ID = "slack " + ev.SubMessage.Timestamp
|
rmsg.ID = ev.SubMessage.Timestamp
|
||||||
if ev.SubMessage.ThreadTimestamp != ev.SubMessage.Timestamp {
|
if ev.SubMessage.ThreadTimestamp != ev.SubMessage.Timestamp {
|
||||||
b.Log.Debugf("SubMessage %#v", ev.SubMessage)
|
b.Log.Debugf("SubMessage %#v", ev.SubMessage)
|
||||||
rmsg.Text = ev.SubMessage.Text + b.GetString(editSuffixConfig)
|
rmsg.Text = ev.SubMessage.Text + b.GetString(editSuffixConfig)
|
||||||
|
@ -324,10 +324,8 @@ func (b *Bslack) deleteMessage(msg *config.Message, channelInfo *slack.Channel)
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we get a "slack <ID>", split it.
|
|
||||||
ts := strings.Fields(msg.ID)
|
|
||||||
for {
|
for {
|
||||||
_, _, err := b.rtm.DeleteMessage(channelInfo.ID, ts[1])
|
_, _, err := b.rtm.DeleteMessage(channelInfo.ID, msg.ID)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
@ -344,9 +342,8 @@ func (b *Bslack) editMessage(msg *config.Message, channelInfo *slack.Channel) (b
|
|||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ts := strings.Fields(msg.ID)
|
|
||||||
for {
|
for {
|
||||||
_, _, _, err := b.rtm.UpdateMessage(channelInfo.ID, ts[1], msg.Text)
|
_, _, _, err := b.rtm.UpdateMessage(channelInfo.ID, msg.ID, msg.Text)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
@ -362,7 +359,7 @@ func (b *Bslack) postMessage(msg *config.Message, messageParameters *slack.PostM
|
|||||||
for {
|
for {
|
||||||
_, id, err := b.rtm.PostMessage(channelInfo.ID, msg.Text, *messageParameters)
|
_, id, err := b.rtm.PostMessage(channelInfo.ID, msg.Text, *messageParameters)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return "slack " + id, nil
|
return id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = b.handleRateLimit(err); err != nil {
|
if err = b.handleRateLimit(err); err != nil {
|
||||||
@ -413,10 +410,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))
|
||||||
msgFields := strings.Fields(msg.ParentID)
|
params.ThreadTimestamp = msg.ParentID
|
||||||
if len(msgFields) >= 2 {
|
|
||||||
params.ThreadTimestamp = msgFields[1]
|
|
||||||
}
|
|
||||||
if msg.Avatar != "" {
|
if msg.Avatar != "" {
|
||||||
params.IconURL = msg.Avatar
|
params.IconURL = msg.Avatar
|
||||||
}
|
}
|
||||||
|
@ -85,8 +85,9 @@ func New(cfg config.Gateway, r *Router) *Gateway {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find the canonical ID that the message is keyed under in cache
|
// Find the canonical ID that the message is keyed under in cache
|
||||||
func (gw *Gateway) FindCanonicalMsgID(mID string) string {
|
func (gw *Gateway) FindCanonicalMsgID(protocol string, mID string) string {
|
||||||
if gw.Messages.Contains(mID) {
|
ID := protocol + " " + mID
|
||||||
|
if gw.Messages.Contains(ID) {
|
||||||
return mID
|
return mID
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,8 +96,8 @@ func (gw *Gateway) FindCanonicalMsgID(mID string) string {
|
|||||||
v, _ := gw.Messages.Peek(mid)
|
v, _ := gw.Messages.Peek(mid)
|
||||||
ids := v.([]*BrMsgID)
|
ids := v.([]*BrMsgID)
|
||||||
for _, downstreamMsgObj := range ids {
|
for _, downstreamMsgObj := range ids {
|
||||||
if mID == downstreamMsgObj.ID {
|
if ID == downstreamMsgObj.ID {
|
||||||
return mid.(string)
|
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
|
// 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 {
|
||||||
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
|
// Get the ID of the parent message in thread
|
||||||
var canonicalParentMsgID string
|
var canonicalParentMsgID string
|
||||||
if msg.ParentID != "" && (gw.BridgeValues().General.PreserveThreading || dest.GetBool("PreserveThreading")) {
|
if msg.ParentID != "" && (gw.BridgeValues().General.PreserveThreading || dest.GetBool("PreserveThreading")) {
|
||||||
thisParentMsgID := dest.Protocol + " " + msg.ParentID
|
canonicalParentMsgID = gw.FindCanonicalMsgID(msg.Protocol, msg.ParentID)
|
||||||
canonicalParentMsgID = gw.FindCanonicalMsgID(thisParentMsgID)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
originchannel := msg.Channel
|
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.Avatar = gw.modifyAvatar(origmsg, dest)
|
||||||
msg.Username = gw.modifyUsername(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
|
// for api we need originchannel as channel
|
||||||
if dest.Protocol == apiProtocol {
|
if dest.Protocol == apiProtocol {
|
||||||
msg.Channel = originchannel
|
msg.Channel = originchannel
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.ParentID = gw.getDestMsgID(canonicalParentMsgID, dest, channel)
|
msg.ParentID = gw.getDestMsgID(origmsg.Protocol+" "+canonicalParentMsgID, dest, channel)
|
||||||
if msg.ParentID == "" {
|
if msg.ParentID == "" {
|
||||||
msg.ParentID = canonicalParentMsgID
|
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
|
// append the message ID (mID) from this bridge (dest) to our brMsgIDs slice
|
||||||
if mID != "" {
|
if mID != "" {
|
||||||
flog.Debugf("mID %s: %s", dest.Account, 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
|
return brMsgIDs
|
||||||
|
@ -109,8 +109,8 @@ func (r *Router) handleReceive() {
|
|||||||
msgIDs = append(msgIDs, gw.handleMessage(msg, br)...)
|
msgIDs = append(msgIDs, gw.handleMessage(msg, br)...)
|
||||||
}
|
}
|
||||||
// only add the message ID if it doesn't already exists
|
// only add the message ID if it doesn't already exists
|
||||||
if _, ok := gw.Messages.Get(msg.ID); !ok && msg.ID != "" {
|
if _, ok := gw.Messages.Get(msg.Protocol + " " + msg.ID); !ok && msg.ID != "" {
|
||||||
gw.Messages.Add(msg.ID, msgIDs)
|
gw.Messages.Add(msg.Protocol+" "+msg.ID, msgIDs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user