From 58f0bb65d734a85f4c5b0be484b0db39f6190978 Mon Sep 17 00:00:00 2001 From: Abhishek Verma Date: Tue, 24 Aug 2021 12:25:51 +0530 Subject: [PATCH 1/3] [Fix]: Fixed bug in adding replies on mattermost thread from slack --- bridge/mattermost/mattermost.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/bridge/mattermost/mattermost.go b/bridge/mattermost/mattermost.go index bb44c48a..eb58fb2b 100644 --- a/bridge/mattermost/mattermost.go +++ b/bridge/mattermost/mattermost.go @@ -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 From 1b0897edb92281d05c0df8be89f1f7159fc7d022 Mon Sep 17 00:00:00 2001 From: Abhishek Verma Date: Wed, 25 Aug 2021 11:38:33 +0530 Subject: [PATCH 2/3] [Fix]: used hasPrefix function --- bridge/mattermost/mattermost.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bridge/mattermost/mattermost.go b/bridge/mattermost/mattermost.go index eb58fb2b..097c5c89 100644 --- a/bridge/mattermost/mattermost.go +++ b/bridge/mattermost/mattermost.go @@ -3,6 +3,7 @@ package bmattermost import ( "errors" "fmt" + "strings" "github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge/config" @@ -134,8 +135,8 @@ func (b *Bmattermost) Send(msg config.Message) (string, error) { 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:] + if strings.HasPrefix(rootID, "mattermost") { + rootID = rootID[len("mattermost")+1:] // remove the text 'mattermost' and space followed by it from ID } // Set rootID of reply message From e9a71ae2d6a63493f6849d0dc3e015a878edb5fe Mon Sep 17 00:00:00 2001 From: Abhishek Verma Date: Tue, 31 Aug 2021 12:19:54 +0530 Subject: [PATCH 3/3] [Fix]: Fixed lint error --- bridge/mattermost/mattermost.go | 1 - 1 file changed, 1 deletion(-) diff --git a/bridge/mattermost/mattermost.go b/bridge/mattermost/mattermost.go index 097c5c89..e7dba319 100644 --- a/bridge/mattermost/mattermost.go +++ b/bridge/mattermost/mattermost.go @@ -142,7 +142,6 @@ func (b *Bmattermost) Send(msg config.Message) (string, error) { // 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