Skip to content

Commit

Permalink
[MI-3201] Fix issue 171 of punctuation marks not working from MM to T…
Browse files Browse the repository at this point in the history
…eams (#200)

* [MI-3201] Fix issue 171 of punctuation marks not working from MM to Teams

* [MI-3201] Fix issue in DMs and GMs

* [MI-3201] Update test cases to include puntuation in messages
  • Loading branch information
ayusht2810 authored Jul 10, 2023
1 parent 29a8be7 commit fd25cbc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
8 changes: 4 additions & 4 deletions server/message_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ func (p *Plugin) SendChat(srcUser string, usersIDs []string, post *model.Post) (
attachments = append(attachments, attachment)
}

md := markdown.New(markdown.XHTMLOutput(true))
md := markdown.New(markdown.XHTMLOutput(true), markdown.Typographer(false))
content := md.RenderToString([]byte(emoji.Parse(text)))

content, mentions := p.getMentionsData(content, "", "", chatID, client)
Expand Down Expand Up @@ -519,7 +519,7 @@ func (p *Plugin) Send(teamID, channelID string, user *model.User, post *model.Po
attachments = append(attachments, attachment)
}

md := markdown.New(markdown.XHTMLOutput(true))
md := markdown.New(markdown.XHTMLOutput(true), markdown.Typographer(false))
content := md.RenderToString([]byte(emoji.Parse(text)))

content, mentions := p.getMentionsData(content, teamID, channelID, "", client)
Expand Down Expand Up @@ -638,7 +638,7 @@ func (p *Plugin) Update(teamID, channelID string, user *model.User, newPost, old

// 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-"))
md := markdown.New(markdown.XHTMLOutput(true), markdown.Typographer(false), markdown.LangPrefix("CodeMirror language-"))
content := md.RenderToString([]byte(emoji.Parse(text)))

content, mentions := p.getMentionsData(content, teamID, channelID, "", client)
Expand Down Expand Up @@ -691,7 +691,7 @@ func (p *Plugin) UpdateChat(chatID string, user *model.User, newPost, oldPost *m
return err
}

md := markdown.New(markdown.XHTMLOutput(true), markdown.LangPrefix("CodeMirror language-"))
md := markdown.New(markdown.XHTMLOutput(true), markdown.Typographer(false), markdown.LangPrefix("CodeMirror language-"))
content := md.RenderToString([]byte(emoji.Parse(text)))

content, mentions := p.getMentionsData(content, "", "", chatID, client)
Expand Down
48 changes: 24 additions & 24 deletions server/message_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ func TestSendChat(t *testing.T) {
uclient.On("UploadFile", "", "", "mockFile.Name"+"_"+testutils.GetID()+".txt", 1, "mockMimeType", bytes.NewReader([]byte("mockData"))).Return(&msteams.Attachment{
ID: testutils.GetID(),
}, nil).Times(1)
uclient.On("SendChat", "mockChatID", "<p>mockMessage</p>\n", (*msteams.Message)(nil), []*msteams.Attachment{{
uclient.On("SendChat", "mockChatID", "<p>mockMessage??????????</p>\n", (*msteams.Message)(nil), []*msteams.Attachment{{
ID: testutils.GetID(),
}}, []models.ChatMessageMentionable{}).Return(nil, errors.New("unable to send the chat")).Times(1)
},
Expand All @@ -1076,7 +1076,7 @@ func TestSendChat(t *testing.T) {
},
SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) {
uclient.On("CreateOrGetChatForUsers", mock.Anything).Return("mockChatID", nil).Times(1)
uclient.On("SendChat", "mockChatID", "<p>mockMessage</p>\n", (*msteams.Message)(nil), []*msteams.Attachment{{
uclient.On("SendChat", "mockChatID", "<p>mockMessage??????????</p>\n", (*msteams.Message)(nil), []*msteams.Attachment{{
ID: testutils.GetID(),
}}, []models.ChatMessageMentionable{}).Return(&msteams.Message{
ID: "mockMessageID",
Expand Down Expand Up @@ -1108,7 +1108,7 @@ func TestSendChat(t *testing.T) {
},
SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) {
uclient.On("CreateOrGetChatForUsers", mock.Anything).Return("mockChatID", nil).Once()
uclient.On("SendChat", "mockChatID", "<p>mockMessage</p>\n", (*msteams.Message)(nil), []*msteams.Attachment{{
uclient.On("SendChat", "mockChatID", "<p>mockMessage??????????</p>\n", (*msteams.Message)(nil), []*msteams.Attachment{{
ID: testutils.GetID(),
}}, []models.ChatMessageMentionable{}).Return(&msteams.Message{
ID: "mockMessageID",
Expand Down Expand Up @@ -1138,7 +1138,7 @@ func TestSendChat(t *testing.T) {
},
SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) {
uclient.On("CreateOrGetChatForUsers", mock.Anything).Return("mockChatID", nil).Times(1)
uclient.On("SendChat", "mockChatID", "<p>mockMessage</p>\n", (*msteams.Message)(nil), ([]*msteams.Attachment)(nil), []models.ChatMessageMentionable{}).Return(&msteams.Message{
uclient.On("SendChat", "mockChatID", "<p>mockMessage??????????</p>\n", (*msteams.Message)(nil), ([]*msteams.Attachment)(nil), []models.ChatMessageMentionable{}).Return(&msteams.Message{
ID: "mockMessageID",
}, nil).Times(1)
},
Expand All @@ -1163,7 +1163,7 @@ func TestSendChat(t *testing.T) {
},
SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) {
uclient.On("CreateOrGetChatForUsers", mock.Anything).Return("mockChatID", nil).Times(1)
uclient.On("SendChat", "mockChatID", "<p>mockMessage</p>\n", (*msteams.Message)(nil), ([]*msteams.Attachment)(nil), []models.ChatMessageMentionable{}).Return(&msteams.Message{
uclient.On("SendChat", "mockChatID", "<p>mockMessage??????????</p>\n", (*msteams.Message)(nil), ([]*msteams.Attachment)(nil), []models.ChatMessageMentionable{}).Return(&msteams.Message{
ID: "mockMessageID",
}, nil).Times(1)
},
Expand Down Expand Up @@ -1197,7 +1197,7 @@ func TestSendChat(t *testing.T) {
Text: "mockText",
UserDisplayName: "mockUserDisplayName",
}, nil).Once()
uclient.On("SendChat", "mockChatID", "<p>mockMessage</p>\n", &msteams.Message{
uclient.On("SendChat", "mockChatID", "<p>mockMessage??????????</p>\n", &msteams.Message{
ID: "mockParentMessageID",
UserID: "mockUserID",
Text: "mockText",
Expand Down Expand Up @@ -1229,7 +1229,7 @@ func TestSendChat(t *testing.T) {
uclient.On("UploadFile", "", "", "mockFile.Name"+"_"+testutils.GetID()+".txt", 1, "mockMimeType", bytes.NewReader([]byte("mockData"))).Return(&msteams.Attachment{
ID: testutils.GetID(),
}, nil).Times(1)
uclient.On("SendChat", "mockChatID", "<p>mockMessage</p>\n", (*msteams.Message)(nil), []*msteams.Attachment{{
uclient.On("SendChat", "mockChatID", "<p>mockMessage??????????</p>\n", (*msteams.Message)(nil), []*msteams.Attachment{{
ID: testutils.GetID(),
}}, []models.ChatMessageMentionable{}).Return(&msteams.Message{
ID: "mockMessageID",
Expand All @@ -1245,7 +1245,7 @@ func TestSendChat(t *testing.T) {
test.SetupStore(p.store.(*storemocks.Store))
test.SetupClient(p.msteamsAppClient.(*clientmocks.Client), p.clientBuilderWithToken("", "", "", "", nil, nil).(*clientmocks.Client))
mockPost := testutils.GetPost(testutils.GetChannelID(), testutils.GetUserID())
mockPost.Message = "mockMessage"
mockPost.Message = "mockMessage??????????"
mockPost.RootId = "mockRootID"
resp, err := p.SendChat(testutils.GetID(), []string{testutils.GetID(), testutils.GetID()}, mockPost)
if test.ExpectedError != "" {
Expand Down Expand Up @@ -1293,7 +1293,7 @@ func TestSend(t *testing.T) {
}).Return(nil).Times(1)
},
SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) {
uclient.On("SendMessageWithAttachments", testutils.GetID(), testutils.GetChannelID(), "", "<p>mockMessage</p>\n", ([]*msteams.Attachment)(nil), []models.ChatMessageMentionable{}).Return(&msteams.Message{
uclient.On("SendMessageWithAttachments", testutils.GetID(), testutils.GetChannelID(), "", "<p>mockMessage??????????</p>\n", ([]*msteams.Attachment)(nil), []models.ChatMessageMentionable{}).Return(&msteams.Message{
ID: "mockMessageID",
}, nil).Times(1)
},
Expand All @@ -1315,7 +1315,7 @@ func TestSend(t *testing.T) {
}).Return(nil).Times(1)
},
SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) {
uclient.On("SendMessageWithAttachments", testutils.GetID(), testutils.GetChannelID(), "", "<p>mockMessage</p>\n", ([]*msteams.Attachment)(nil), []models.ChatMessageMentionable{}).Return(&msteams.Message{
uclient.On("SendMessageWithAttachments", testutils.GetID(), testutils.GetChannelID(), "", "<p>mockMessage??????????</p>\n", ([]*msteams.Attachment)(nil), []models.ChatMessageMentionable{}).Return(&msteams.Message{
ID: "mockMessageID",
}, nil).Times(1)
},
Expand All @@ -1335,7 +1335,7 @@ func TestSend(t *testing.T) {
uclient.On("UploadFile", testutils.GetID(), testutils.GetChannelID(), "mockFile.Name"+"_"+testutils.GetID()+".txt", 1, "mockMimeType", bytes.NewReader([]byte("mockData"))).Return(&msteams.Attachment{
ID: testutils.GetID(),
}, nil).Times(1)
uclient.On("SendMessageWithAttachments", testutils.GetID(), testutils.GetChannelID(), "", "<p>mockMessage</p>\n", []*msteams.Attachment{
uclient.On("SendMessageWithAttachments", testutils.GetID(), testutils.GetChannelID(), "", "<p>mockMessage??????????</p>\n", []*msteams.Attachment{
{
ID: testutils.GetID(),
},
Expand All @@ -1362,7 +1362,7 @@ func TestSend(t *testing.T) {
uclient.On("UploadFile", testutils.GetID(), testutils.GetChannelID(), "mockFile.Name"+"_"+testutils.GetID()+".txt", 1, "mockMimeType", bytes.NewReader([]byte("mockData"))).Return(&msteams.Attachment{
ID: testutils.GetID(),
}, nil).Times(1)
uclient.On("SendMessageWithAttachments", testutils.GetID(), testutils.GetChannelID(), "", "<p>mockMessage</p>\n", []*msteams.Attachment{
uclient.On("SendMessageWithAttachments", testutils.GetID(), testutils.GetChannelID(), "", "<p>mockMessage??????????</p>\n", []*msteams.Attachment{
{
ID: testutils.GetID(),
},
Expand Down Expand Up @@ -1390,7 +1390,7 @@ func TestSend(t *testing.T) {
uclient.On("UploadFile", testutils.GetID(), testutils.GetChannelID(), "mockFile.Name"+"_"+testutils.GetID()+".txt", 1, "mockMimeType", bytes.NewReader([]byte("mockData"))).Return(&msteams.Attachment{
ID: testutils.GetID(),
}, nil).Times(1)
uclient.On("SendMessageWithAttachments", testutils.GetID(), testutils.GetChannelID(), "", "<p>mockMessage</p>\n", []*msteams.Attachment{
uclient.On("SendMessageWithAttachments", testutils.GetID(), testutils.GetChannelID(), "", "<p>mockMessage??????????</p>\n", []*msteams.Attachment{
{
ID: testutils.GetID(),
},
Expand All @@ -1408,7 +1408,7 @@ func TestSend(t *testing.T) {
test.SetupStore(p.store.(*storemocks.Store))
test.SetupClient(p.msteamsAppClient.(*clientmocks.Client), p.clientBuilderWithToken("", "", "", "", nil, nil).(*clientmocks.Client))
mockPost := testutils.GetPost(testutils.GetChannelID(), testutils.GetUserID())
mockPost.Message = "mockMessage"
mockPost.Message = "mockMessage??????????"
resp, err := p.Send(testutils.GetID(), testutils.GetChannelID(), testutils.GetUser(model.SystemAdminRoleId, "[email protected]"), mockPost)
if test.ExpectedError != "" {
assert.Contains(err.Error(), test.ExpectedError)
Expand Down Expand Up @@ -1659,7 +1659,7 @@ func TestUpdate(t *testing.T) {
}, nil).Times(1)
},
SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) {
uclient.On("UpdateMessage", "mockTeamsTeamID", testutils.GetChannelID(), "", "mockMSTeamsID", "<p>mockMessage</p>\n", []models.ChatMessageMentionable{}).Return(errors.New("unable to update the message")).Times(1)
uclient.On("UpdateMessage", "mockTeamsTeamID", testutils.GetChannelID(), "", "mockMSTeamsID", "<p>mockMessage??????????</p>\n", []models.ChatMessageMentionable{}).Return(errors.New("unable to update the message")).Times(1)
},
ExpectedError: "unable to update the message",
},
Expand All @@ -1676,7 +1676,7 @@ func TestUpdate(t *testing.T) {
}, nil).Times(1)
},
SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) {
uclient.On("UpdateMessage", "mockTeamsTeamID", testutils.GetChannelID(), "", "mockMSTeamsID", "<p>mockMessage</p>\n", []models.ChatMessageMentionable{}).Return(nil).Times(1)
uclient.On("UpdateMessage", "mockTeamsTeamID", testutils.GetChannelID(), "", "mockMSTeamsID", "<p>mockMessage??????????</p>\n", []models.ChatMessageMentionable{}).Return(nil).Times(1)
uclient.On("GetMessage", "mockTeamsTeamID", testutils.GetChannelID(), "mockMSTeamsID").Return(nil, errors.New("unable to get the updated message")).Times(1)
},
},
Expand All @@ -1698,7 +1698,7 @@ func TestUpdate(t *testing.T) {
}).Return(errors.New("unable to store the link posts")).Times(1)
},
SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) {
uclient.On("UpdateMessage", "mockTeamsTeamID", testutils.GetChannelID(), "", "mockMSTeamsID", "<p>mockMessage</p>\n", []models.ChatMessageMentionable{}).Return(nil).Times(1)
uclient.On("UpdateMessage", "mockTeamsTeamID", testutils.GetChannelID(), "", "mockMSTeamsID", "<p>mockMessage??????????</p>\n", []models.ChatMessageMentionable{}).Return(nil).Times(1)
uclient.On("GetMessage", "mockTeamsTeamID", testutils.GetChannelID(), "mockMSTeamsID").Return(&msteams.Message{
ID: testutils.GetID(),
}, nil).Times(1)
Expand All @@ -1722,7 +1722,7 @@ func TestUpdate(t *testing.T) {
}).Return(nil).Times(1)
},
SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) {
uclient.On("UpdateMessage", "mockTeamsTeamID", testutils.GetChannelID(), "", "mockMSTeamsID", "<p>mockMessage</p>\n", []models.ChatMessageMentionable{}).Return(nil).Times(1)
uclient.On("UpdateMessage", "mockTeamsTeamID", testutils.GetChannelID(), "", "mockMSTeamsID", "<p>mockMessage??????????</p>\n", []models.ChatMessageMentionable{}).Return(nil).Times(1)
uclient.On("GetMessage", "mockTeamsTeamID", testutils.GetChannelID(), "mockMSTeamsID").Return(&msteams.Message{
ID: testutils.GetID(),
}, nil).Times(1)
Expand All @@ -1736,7 +1736,7 @@ func TestUpdate(t *testing.T) {
test.SetupStore(p.store.(*storemocks.Store))
test.SetupClient(p.msteamsAppClient.(*clientmocks.Client), p.clientBuilderWithToken("", "", "", "", nil, nil).(*clientmocks.Client))
mockPost := testutils.GetPost(testutils.GetChannelID(), testutils.GetUserID())
mockPost.Message = "mockMessage"
mockPost.Message = "mockMessage??????????"
err := p.Update("mockTeamsTeamID", testutils.GetChannelID(), testutils.GetUser(model.ChannelAdminRoleId, "[email protected]"), mockPost, testutils.GetPost(testutils.GetChannelID(), testutils.GetUserID()))
if test.ExpectedError != "" {
assert.Contains(err.Error(), test.ExpectedError)
Expand Down Expand Up @@ -1805,7 +1805,7 @@ func TestUpdateChat(t *testing.T) {
}, nil).Times(1)
},
SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) {
uclient.On("UpdateChatMessage", "mockChatID", "mockTeamsTeamID", "<p>mockMessage</p>\n", []models.ChatMessageMentionable{}).Return(errors.New("unable to update the message")).Times(1)
uclient.On("UpdateChatMessage", "mockChatID", "mockTeamsTeamID", "<p>mockMessage??????????</p>\n", []models.ChatMessageMentionable{}).Return(errors.New("unable to update the message")).Times(1)
},
ExpectedError: "unable to update the message",
},
Expand All @@ -1822,7 +1822,7 @@ func TestUpdateChat(t *testing.T) {
}, nil).Times(1)
},
SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) {
uclient.On("UpdateChatMessage", "mockChatID", "mockTeamsTeamID", "<p>mockMessage</p>\n", []models.ChatMessageMentionable{}).Return(nil).Times(1)
uclient.On("UpdateChatMessage", "mockChatID", "mockTeamsTeamID", "<p>mockMessage??????????</p>\n", []models.ChatMessageMentionable{}).Return(nil).Times(1)
uclient.On("GetChatMessage", "mockChatID", "mockTeamsTeamID").Return(nil, errors.New("unable to get the updated message")).Times(1)
},
},
Expand All @@ -1844,7 +1844,7 @@ func TestUpdateChat(t *testing.T) {
}).Return(errors.New("unable to store the link posts")).Times(1)
},
SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) {
uclient.On("UpdateChatMessage", "mockChatID", "mockTeamsTeamID", "<p>mockMessage</p>\n", []models.ChatMessageMentionable{}).Return(nil).Times(1)
uclient.On("UpdateChatMessage", "mockChatID", "mockTeamsTeamID", "<p>mockMessage??????????</p>\n", []models.ChatMessageMentionable{}).Return(nil).Times(1)
uclient.On("GetChatMessage", "mockChatID", "mockTeamsTeamID").Return(&msteams.Message{
ID: testutils.GetID(),
}, nil).Times(1)
Expand All @@ -1868,7 +1868,7 @@ func TestUpdateChat(t *testing.T) {
}).Return(nil).Times(1)
},
SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) {
uclient.On("UpdateChatMessage", "mockChatID", "mockTeamsTeamID", "<p>mockMessage</p>\n", []models.ChatMessageMentionable{}).Return(nil).Times(1)
uclient.On("UpdateChatMessage", "mockChatID", "mockTeamsTeamID", "<p>mockMessage??????????</p>\n", []models.ChatMessageMentionable{}).Return(nil).Times(1)
uclient.On("GetChatMessage", "mockChatID", "mockTeamsTeamID").Return(&msteams.Message{
ID: testutils.GetID(),
}, nil).Times(1)
Expand All @@ -1882,7 +1882,7 @@ func TestUpdateChat(t *testing.T) {
test.SetupStore(p.store.(*storemocks.Store))
test.SetupClient(p.msteamsAppClient.(*clientmocks.Client), p.clientBuilderWithToken("", "", "", "", nil, nil).(*clientmocks.Client))
mockPost := testutils.GetPost(testutils.GetChannelID(), testutils.GetUserID())
mockPost.Message = "mockMessage"
mockPost.Message = "mockMessage??????????"
err := p.UpdateChat("mockChatID", testutils.GetUser(model.ChannelAdminRoleId, "[email protected]"), mockPost, testutils.GetPost(testutils.GetChannelID(), testutils.GetUserID()))
if test.ExpectedError != "" {
assert.Contains(err.Error(), test.ExpectedError)
Expand Down

0 comments on commit fd25cbc

Please sign in to comment.