diff --git a/server/message_hooks.go b/server/message_hooks.go index fcd0bc953..b18022698 100644 --- a/server/message_hooks.go +++ b/server/message_hooks.go @@ -628,6 +628,8 @@ func (p *Plugin) Update(teamID, channelID string, user *model.User, newPost, old return errors.New("post not found") } + // TODO: Add the logic of processing the attachments and uploading new files to Teams + // once Mattermost comes up with the feature of editing attachments md := markdown.New(markdown.XHTMLOutput(true), markdown.LangPrefix("CodeMirror language-")) content := md.RenderToString([]byte(emoji.Parse(text))) diff --git a/server/msteams/client.go b/server/msteams/client.go index 2334e25ac..0c8d3d255 100644 --- a/server/msteams/client.go +++ b/server/msteams/client.go @@ -577,6 +577,25 @@ func (tc *ClientImpl) UpdateMessage(teamID, channelID, parentID, msgID, message contentType := models.HTML_BODYTYPE rmsg.SetMentions(mentions) + var originalMessage models.ChatMessageable + var err error + if parentID != "" { + originalMessage, err = tc.client.TeamsById(teamID).ChannelsById(channelID).MessagesById(parentID).RepliesById(msgID).Get(tc.ctx, nil) + } else { + originalMessage, err = tc.client.TeamsById(teamID).ChannelsById(channelID).MessagesById(msgID).Get(tc.ctx, nil) + } + if err != nil { + tc.logError("Error in getting original message from Teams", "error", NormalizeGraphAPIError(err)) + } + + if originalMessage != nil { + attachments := originalMessage.GetAttachments() + for _, a := range attachments { + message = fmt.Sprintf(" %s", *a.GetId(), message) + } + rmsg.SetAttachments(attachments) + } + body := models.NewItemBody() body.SetContentType(&contentType) body.SetContent(&message) @@ -597,6 +616,19 @@ func (tc *ClientImpl) UpdateMessage(teamID, channelID, parentID, msgID, message func (tc *ClientImpl) UpdateChatMessage(chatID, msgID, message string, mentions []models.ChatMessageMentionable) error { rmsg := models.NewChatMessage() + originalMessage, err := tc.client.ChatsById(chatID).MessagesById(msgID).Get(tc.ctx, nil) + if err != nil { + tc.logError("Error in getting original message from Teams", "error", NormalizeGraphAPIError(err)) + } + + if originalMessage != nil { + attachments := originalMessage.GetAttachments() + for _, a := range attachments { + message = fmt.Sprintf(" %s", *a.GetId(), message) + } + rmsg.SetAttachments(attachments) + } + contentType := models.HTML_BODYTYPE rmsg.SetMentions(mentions) @@ -605,10 +637,10 @@ func (tc *ClientImpl) UpdateChatMessage(chatID, msgID, message string, mentions body.SetContentType(&contentType) body.SetContent(&message) rmsg.SetBody(body) - if _, err := tc.client.ChatsById(chatID).MessagesById(msgID).Patch(tc.ctx, rmsg, nil); err != nil { return NormalizeGraphAPIError(err) } + return nil }