MM-56629 Render Markdown in batched email notifications (#26217)

* [MM-56629] rendered markdown in batched email (#26116)

* [MM-56629] added unit test for GenerateHyperlinkForChannels (#26116)

* [MM-56629] refactored code to remove duplicates, updated test (#26116)

* [MM-56629] updated landing url and cleared check-style (#26116)

* [MM-56629] added app-layesrs and mocks (#26116)

* [MM-56629] updated unit tests (#26116)

* [MM-56629] reverted changes of removing unused context parameter (#26116)

* [MM-56629] removed unused method generateHyperlinkForChannels (#26116)

* [MM-56629] fixed check-style error (#26116)

* [MM-56629] refactored (#26116)

---------

Co-authored-by: Sazzad Hossain <sazzad.hossain@marginedge.com>
Co-authored-by: Harrison Healey <harrisonmhealey@gmail.com>
Этот коммит содержится в:
sazzad hossain
2024-03-07 22:27:08 +06:00
коммит произвёл GitHub
родитель ab029105fd
Коммит bc887441d0
8 изменённых файлов: 122 добавлений и 65 удалений

Просмотреть файл

@@ -9,7 +9,6 @@ import (
"html"
"html/template"
"io"
"strings"
"github.com/pkg/errors"
@@ -232,20 +231,8 @@ func (a *App) getNotificationEmailBody(c request.CTX, recipient *model.User, pos
}
if emailNotificationContentsType == model.EmailNotificationContentsFull {
postMessage := a.GetMessageForNotification(post, translateFunc)
postMessage = html.EscapeString(postMessage)
mdPostMessage, mdErr := utils.MarkdownToHTML(postMessage, a.GetSiteURL())
if mdErr != nil {
c.Logger().Warn("Encountered error while converting markdown to HTML", mlog.Err(mdErr))
mdPostMessage = postMessage
}
normalizedPostMessage, err := a.generateHyperlinkForChannels(c, mdPostMessage, teamName, landingURL)
if err != nil {
c.Logger().Warn("Encountered error while generating hyperlink for channels", mlog.String("team_name", teamName), mlog.Err(err))
normalizedPostMessage = mdPostMessage
}
pData.Message = template.HTML(normalizedPostMessage)
postMessage := a.GetMessageForNotification(post, teamName, a.GetSiteURL(), translateFunc)
pData.Message = template.HTML(postMessage)
pData.Time = translateFunc("app.notification.body.dm.time", messageTime)
pData.MessageAttachments = email.ProcessMessageAttachments(post, a.GetSiteURL())
}
@@ -309,34 +296,6 @@ func (a *App) getNotificationEmailBody(c request.CTX, recipient *model.User, pos
return a.Srv().TemplatesContainer().RenderToString("messages_notification", data)
}
func (a *App) generateHyperlinkForChannels(c request.CTX, postMessage, teamName, teamURL string) (string, *model.AppError) {
team, err := a.GetTeamByName(teamName)
if err != nil {
return "", err
}
channelNames := model.ChannelMentions(postMessage)
if len(channelNames) == 0 {
return postMessage, nil
}
channels, err := a.GetChannelsByNames(c, channelNames, team.Id)
if err != nil {
return "", err
}
visited := make(map[string]bool)
for _, ch := range channels {
if !visited[ch.Id] && ch.Type == model.ChannelTypeOpen {
channelURL := teamURL + "/channels/" + ch.Name
channelHyperLink := fmt.Sprintf("<a href='%s'>%s</a>", channelURL, "~"+ch.Name)
postMessage = strings.Replace(postMessage, "~"+ch.Name, channelHyperLink, -1)
visited[ch.Id] = true
}
}
return postMessage, nil
}
func (a *App) GetMessageForNotification(post *model.Post, translateFunc i18n.TranslateFunc) string {
return a.Srv().EmailService.GetMessageForNotification(post, translateFunc)
func (a *App) GetMessageForNotification(post *model.Post, teamName, siteUrl string, translateFunc i18n.TranslateFunc) string {
return a.Srv().EmailService.GetMessageForNotification(post, teamName, siteUrl, translateFunc)
}