Extract thread processing into func. Move message modification to slack bridge.
This commit is contained in:
@@ -288,6 +288,12 @@ func (b *Bslack) sendRTM(msg config.Message) (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle prefix hint for unthreaded messages.
|
||||||
|
if msg.ParentID == "unthreaded" {
|
||||||
|
msg.ParentID = ""
|
||||||
|
msg.Text = fmt.Sprintf("thread reply: %s", msg.Text)
|
||||||
|
}
|
||||||
|
|
||||||
// Handle message deletions.
|
// Handle message deletions.
|
||||||
if handled, err = b.deleteMessage(&msg, channelInfo); handled {
|
if handled, err = b.deleteMessage(&msg, channelInfo); handled {
|
||||||
return msg.ID, err
|
return msg.ID, err
|
||||||
|
|||||||
@@ -41,8 +41,7 @@ type BrMsgID struct {
|
|||||||
var flog *log.Entry
|
var flog *log.Entry
|
||||||
|
|
||||||
const (
|
const (
|
||||||
apiProtocol = "api"
|
apiProtocol = "api"
|
||||||
threadReplyPrefix = "thread reply"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func New(cfg config.Gateway, r *Router) *Gateway {
|
func New(cfg config.Gateway, r *Router) *Gateway {
|
||||||
@@ -251,16 +250,14 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
|
|||||||
return brMsgIDs
|
return brMsgIDs
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the ID of the parent message in thread
|
|
||||||
var canonicalParentMsgID string
|
|
||||||
if msg.ParentID != "" && dest.GetBool("PreserveThreading") {
|
|
||||||
canonicalParentMsgID = gw.FindCanonicalMsgID(msg.Protocol, msg.ParentID)
|
|
||||||
}
|
|
||||||
|
|
||||||
originchannel := msg.Channel
|
originchannel := msg.Channel
|
||||||
origmsg := msg
|
origmsg := msg
|
||||||
channels := gw.getDestChannel(&msg, *dest)
|
channels := gw.getDestChannel(&msg, *dest)
|
||||||
for _, channel := range channels {
|
for _, channel := range channels {
|
||||||
|
if parentID, isThreaded := gw.handleThreading(&msg, dest, channel); isThreaded {
|
||||||
|
msg.ParentID = parentID
|
||||||
|
}
|
||||||
|
|
||||||
// Only send the avatar download event to ourselves.
|
// Only send the avatar download event to ourselves.
|
||||||
if msg.Event == config.EventAvatarDownload {
|
if msg.Event == config.EventAvatarDownload {
|
||||||
if channel.ID != getChannelID(origmsg) {
|
if channel.ID != getChannelID(origmsg) {
|
||||||
@@ -289,16 +286,6 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
|
|||||||
msg.Channel = originchannel
|
msg.Channel = originchannel
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add prefix if reply message is being unthreaded.
|
|
||||||
if msg.ParentID != "" && canonicalParentMsgID == "" {
|
|
||||||
msg.Text = fmt.Sprintf("%s: %s", threadReplyPrefix, msg.Text)
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.ParentID = gw.getDestMsgID(origmsg.Protocol+" "+canonicalParentMsgID, dest, channel)
|
|
||||||
if msg.ParentID == "" {
|
|
||||||
msg.ParentID = canonicalParentMsgID
|
|
||||||
}
|
|
||||||
|
|
||||||
// if we are using mattermost plugin account, send messages to MattermostPlugin channel
|
// if we are using mattermost plugin account, send messages to MattermostPlugin channel
|
||||||
// that can be picked up by the mattermost matterbridge plugin
|
// that can be picked up by the mattermost matterbridge plugin
|
||||||
if dest.Account == "mattermost.plugin" {
|
if dest.Account == "mattermost.plugin" {
|
||||||
@@ -444,6 +431,24 @@ func (gw *Gateway) modifyMessage(msg *config.Message) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gw *Gateway) handleThreading(msg *config.Message, dest *bridge.Bridge, channel config.ChannelInfo) (string, bool) {
|
||||||
|
if msg.ParentID == "" {
|
||||||
|
// Message is not threaded.
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
|
||||||
|
canonicalParentMsgID := gw.FindCanonicalMsgID(msg.Protocol, msg.ParentID)
|
||||||
|
if !dest.GetBool("PreserveThreading") || canonicalParentMsgID == "" {
|
||||||
|
// Mark message as unthreaded, either because disabled or uncached.
|
||||||
|
return "unthreaded", true
|
||||||
|
}
|
||||||
|
|
||||||
|
if parentID := gw.getDestMsgID(msg.Protocol+" "+canonicalParentMsgID, dest, channel); parentID != "" {
|
||||||
|
return parentID, true
|
||||||
|
}
|
||||||
|
return canonicalParentMsgID, true
|
||||||
|
}
|
||||||
|
|
||||||
// handleFiles uploads or places all files on the given msg to the MediaServer and
|
// handleFiles uploads or places all files on the given msg to the MediaServer and
|
||||||
// adds the new URL of the file on the MediaServer onto the given msg.
|
// adds the new URL of the file on the MediaServer onto the given msg.
|
||||||
func (gw *Gateway) handleFiles(msg *config.Message) {
|
func (gw *Gateway) handleFiles(msg *config.Message) {
|
||||||
|
|||||||
Reference in New Issue
Block a user