Skip to content

Commit

Permalink
Removed the logic of processing post attachments on receiving update …
Browse files Browse the repository at this point in the history
…activity from MS Teams (#318)

* [MI-3514] Removed the logic of processing post attachments on receiving update activity from MS Teams

* [MI-3521] Fixed the issue of emojis showing as html from Teams to MM
Modified the msgToPost function to add <p> tag if missing from message
Fixed the failing unit test of converters file
Modified the order of checking duplicate post in the handleCreatedActivity function

* [MI-3521] Fixed the failing unit tests

* [MI-3514] Fixed the failing unit tests by fixing a bug
  • Loading branch information
manojmalik20 authored Sep 21, 2023
1 parent 8c7e66b commit e1ed876
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
6 changes: 5 additions & 1 deletion server/handlers/attachments.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (ah *ActivityHandler) ProcessAndUploadFileToMM(attachmentData []byte, attac
return fileInfo.Id, false
}

func (ah *ActivityHandler) handleAttachments(channelID, userID, text string, msg *msteams.Message, chat *msteams.Chat) (string, model.StringArray, string, bool) {
func (ah *ActivityHandler) handleAttachments(channelID, userID, text string, msg *msteams.Message, chat *msteams.Chat, isUpdatedActivity bool) (string, model.StringArray, string, bool) {
attachments := []string{}
newText := text
parentID := ""
Expand Down Expand Up @@ -130,6 +130,10 @@ func (ah *ActivityHandler) handleAttachments(channelID, userID, text string, msg
continue
}

if isUpdatedActivity {
continue
}

// handle the download
var attachmentData []byte
var err error
Expand Down
2 changes: 1 addition & 1 deletion server/handlers/attachments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ func TestHandleAttachments(t *testing.T) {
ChannelID: testutils.GetChannelID(),
}

newText, attachmentIDs, parentID, errorsFound := ah.handleAttachments(testutils.GetChannelID(), testutils.GetUserID(), "mock-text", attachments, nil)
newText, attachmentIDs, parentID, errorsFound := ah.handleAttachments(testutils.GetChannelID(), testutils.GetUserID(), "mock-text", attachments, nil, false)
assert.Equal(t, testCase.expectedParentID, parentID)
assert.Equal(t, testCase.expectedAttachmentIDsCount, len(attachmentIDs))
assert.Equal(t, testCase.expectedText, newText)
Expand Down
9 changes: 6 additions & 3 deletions server/handlers/converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (ah *ActivityHandler) GetAvatarURL(userID string) string {
return defaultAvatarURL
}

func (ah *ActivityHandler) msgToPost(channelID, senderID string, msg *msteams.Message, chat *msteams.Chat) (*model.Post, bool) {
func (ah *ActivityHandler) msgToPost(channelID, senderID string, msg *msteams.Message, chat *msteams.Chat, isUpdatedActivity bool) (*model.Post, bool) {
text := ah.handleMentions(msg)
text = ah.handleEmojis(text)
var embeddedImages []msteams.Attachment
Expand All @@ -52,7 +52,7 @@ func (ah *ActivityHandler) msgToPost(channelID, senderID string, msg *msteams.Me
}
}

newText, attachments, parentID, errorFound := ah.handleAttachments(channelID, senderID, text, msg, chat)
newText, attachments, parentID, errorFound := ah.handleAttachments(channelID, senderID, text, msg, chat, isUpdatedActivity)
text = newText
if parentID != "" {
rootID = parentID
Expand All @@ -62,7 +62,10 @@ func (ah *ActivityHandler) msgToPost(channelID, senderID string, msg *msteams.Me
text = "## " + msg.Subject + "\n" + text
}

post := &model.Post{UserId: senderID, ChannelId: channelID, Message: text, Props: props, RootId: rootID, FileIds: attachments}
post := &model.Post{UserId: senderID, ChannelId: channelID, Message: text, Props: props, RootId: rootID}
if !isUpdatedActivity {
post.FileIds = attachments
}
post.AddProp("msteams_sync_"+ah.plugin.GetBotUserID(), true)

if senderID == ah.plugin.GetBotUserID() {
Expand Down
2 changes: 1 addition & 1 deletion server/handlers/converters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestMsgToPost(t *testing.T) {

ah.plugin = p

post, _ := ah.msgToPost(testCase.channelID, testCase.senderID, testCase.message, nil)
post, _ := ah.msgToPost(testCase.channelID, testCase.senderID, testCase.message, nil, false)
assert.Equal(t, testCase.post, post)
})
}
Expand Down
4 changes: 2 additions & 2 deletions server/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func (ah *ActivityHandler) handleCreatedActivity(activityIds msteams.ActivityIds
return
}

post, errorFound := ah.msgToPost(channelID, senderID, msg, chat)
post, errorFound := ah.msgToPost(channelID, senderID, msg, chat, false)
ah.plugin.GetAPI().LogDebug("Post generated")

newPost, appErr := ah.plugin.GetAPI().CreatePost(post)
Expand Down Expand Up @@ -343,7 +343,7 @@ func (ah *ActivityHandler) handleUpdatedActivity(activityIds msteams.ActivityIds
return
}

post, _ := ah.msgToPost(channelID, senderID, msg, chat)
post, _ := ah.msgToPost(channelID, senderID, msg, chat, true)
post.Id = postInfo.MattermostID

if _, appErr := ah.plugin.GetAPI().UpdatePost(post); appErr != nil {
Expand Down

0 comments on commit e1ed876

Please sign in to comment.