[MM-11143] Strip markdown formatting characters from push notifications (#17775)
* WIP: trim markdown for push notification * fix: golangci * fix: table regex * fix: regex code block * doc: add license * WIP: custom renderer with goldmark * WIP: update goldmark version to 1.38 * fix: use goldmark as parser * fix: remove table extension * fix: change buf to `strings.Builder` * fix: return original string, log warning if error * refactor: change `WriteString` to `WriteByte` * refactor: change if condition * refactor: use assertion * refactor: move to inline * fix: remove handle multiline Already handled by mobile * refactor: wrap same function * refactor: move strip markdown to `sendPushNotificationSync` * refactor: renaming variable aren't used * fix: move log to func `sendPushNotificationSync` * docs: add comment to `StripMarkdown` * fix: move assign message to else * appErr to err rename Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in> Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
2d8857b72e
Коммит
081f4a5123
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/shared/i18n"
|
||||
"github.com/mattermost/mattermost-server/v5/shared/mlog"
|
||||
"github.com/mattermost/mattermost-server/v5/utils"
|
||||
)
|
||||
|
||||
type notificationType string
|
||||
@@ -55,7 +56,13 @@ type PushNotification struct {
|
||||
func (a *App) sendPushNotificationSync(post *model.Post, user *model.User, channel *model.Channel, channelName string, senderName string,
|
||||
explicitMention bool, channelWideMention bool, replyToThreadType string) *model.AppError {
|
||||
cfg := a.Config()
|
||||
msg, err := a.BuildPushNotificationMessage(
|
||||
message, err := utils.StripMarkdown(post.Message)
|
||||
if err != nil {
|
||||
mlog.Warn("Failed parse to markdown", mlog.String("post_id", post.Id), mlog.Err(err))
|
||||
} else {
|
||||
post.Message = message
|
||||
}
|
||||
msg, appErr := a.BuildPushNotificationMessage(
|
||||
*cfg.EmailSettings.PushNotificationContents,
|
||||
post,
|
||||
user,
|
||||
@@ -66,8 +73,8 @@ func (a *App) sendPushNotificationSync(post *model.Post, user *model.User, chann
|
||||
channelWideMention,
|
||||
replyToThreadType,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
|
||||
return a.sendPushNotificationToAllSessions(msg, user.Id, "")
|
||||
|
||||
Ссылка в новой задаче
Block a user