[Fix]: Fixed bug in adding replies on mattermost thread from slack

This commit is contained in:
Abhishek Verma
2021-08-24 12:25:51 +05:30
parent 400ecfb79c
commit 58f0bb65d7

View File

@@ -129,11 +129,19 @@ func (b *Bmattermost) Send(msg config.Message) (string, error) {
// we only can reply to the root of the thread, not to a specific ID (like discord for example does)
if msg.ParentID != "" {
post, res := b.mc.Client.GetPost(msg.ParentID, "")
if res.Error != nil {
b.Log.Errorf("getting post %s failed: %s", msg.ParentID, res.Error.DetailedError)
rootID := msg.ParentID
// If parentID/rootID exists it means message is of reply type, so add 'thread' in message text
msg.Text = fmt.Sprintf("[thread]: %s", msg.Text)
// if text "mattermost" is present in the parentID/rootID (present in case root message is started on mattermost)
// separate it from the ID and use correct ID as parentID/rootID
if len(rootID) > 10 && rootID[0:10] == "mattermost" {
rootID = rootID[11:]
}
msg.ParentID = post.RootId
// Set rootID of reply message
// here 'msg.ParentID' is used, but this is stored as 'RootId' at mattermost, refer to function 'PostMessage' below
msg.ParentID = rootID
}
// Upload a file if it exists