Push notification styling improvements (#8818)

* Push notification styling improvements

* Fix unit tests
Этот коммит содержится в:
Elias Nahum
2018-05-30 13:11:19 -04:00
коммит произвёл Christopher Speller
родитель 2fe8878749
Коммит e39f5f46f3
3 изменённых файлов: 305 добавлений и 155 удалений

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

@@ -23,6 +23,11 @@ import (
"github.com/nicksnyder/go-i18n/i18n"
)
const (
THREAD_ANY = "any"
THREAD_ROOT = "root"
)
func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *model.Channel, sender *model.User, parentPostList *model.PostList) ([]string, *model.AppError) {
pchan := a.Srv.Store.User().GetAllProfilesInChannel(channel.Id, true)
cmnchan := a.Srv.Store.Channel().GetAllChannelMembersNotifyPropsForChannel(channel.Id, true)
@@ -47,6 +52,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
}
mentionedUserIds := make(map[string]bool)
threadMentionedUserIds := make(map[string]string)
allActivityPushUserIds := []string{}
hereNotification := false
channelNotification := false
@@ -106,8 +112,16 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
if len(post.RootId) > 0 && parentPostList != nil {
for _, threadPost := range parentPostList.Posts {
profile := profileMap[threadPost.UserId]
if profile != nil && (profile.NotifyProps["comments"] == "any" || (profile.NotifyProps["comments"] == "root" && threadPost.Id == parentPostList.Order[0])) {
mentionedUserIds[threadPost.UserId] = true
if profile != nil && (profile.NotifyProps["comments"] == THREAD_ANY || (profile.NotifyProps["comments"] == THREAD_ROOT && threadPost.Id == parentPostList.Order[0])) {
if threadPost.Id == parentPostList.Order[0] {
threadMentionedUserIds[threadPost.UserId] = THREAD_ROOT
} else {
threadMentionedUserIds[threadPost.UserId] = THREAD_ANY
}
if _, ok := mentionedUserIds[threadPost.UserId]; !ok {
mentionedUserIds[threadPost.UserId] = false
}
}
}
}
@@ -145,6 +159,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
updateMentionChans = append(updateMentionChans, a.Srv.Store.Channel().IncrementMentionCount(post.ChannelId, id))
}
var senderUsername string
senderName := ""
channelName := ""
if post.IsSystemMessage() {
@@ -152,8 +167,10 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
} else {
if value, ok := post.Props["override_username"]; ok && post.Props["from_webhook"] == "true" {
senderName = value.(string)
senderUsername = value.(string)
} else {
senderName = sender.Username
senderUsername = sender.Username
}
}
@@ -170,13 +187,6 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
channelName = channel.DisplayName
}
var senderUsername string
if value, ok := post.Props["override_username"]; ok && post.Props["from_webhook"] == "true" {
senderUsername = value.(string)
} else {
senderUsername = sender.Username
}
if a.Config().EmailSettings.SendEmailNotifications {
for _, id := range mentionedUsersList {
if profileMap[id] == nil {
@@ -296,7 +306,22 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
}
if ShouldSendPushNotification(profileMap[id], channelMemberNotifyPropsMap[id], true, status, post) {
a.sendPushNotification(post, profileMap[id], channel, senderName, channelName, true)
replyToThreadType := ""
if value, ok := threadMentionedUserIds[id]; ok {
replyToThreadType = value
}
a.sendPushNotification(
post,
profileMap[id],
channel,
channelName,
sender,
senderName,
mentionedUserIds[id],
(channelNotification || allNotification),
replyToThreadType,
)
}
}
@@ -313,7 +338,17 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
}
if ShouldSendPushNotification(profileMap[id], channelMemberNotifyPropsMap[id], false, status, post) {
a.sendPushNotification(post, profileMap[id], channel, senderName, channelName, false)
a.sendPushNotification(
post,
profileMap[id],
channel,
channelName,
sender,
senderName,
false,
false,
"",
)
}
}
}
@@ -657,14 +692,26 @@ func (a *App) GetMessageForNotification(post *model.Post, translateFunc i18n.Tra
}
}
func (a *App) sendPushNotification(post *model.Post, user *model.User, channel *model.Channel, senderName, channelName string, wasMentioned bool) *model.AppError {
func (a *App) sendPushNotification(post *model.Post, user *model.User, channel *model.Channel, channelName string, sender *model.User, senderName string,
explicitMention, channelWideMention bool, replyToThreadType string) *model.AppError {
contentsConfig := *a.Config().EmailSettings.PushNotificationContents
sessions, err := a.getMobileAppSessions(user.Id)
if err != nil {
return err
}
if channel.Type == model.CHANNEL_DIRECT {
channelName = senderName
if senderName == utils.T("system.message.name") {
channelName = senderName
} else {
preference, prefError := a.GetPreferenceByCategoryAndNameForUser(user.Id, model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS, "name_format")
if prefError != nil {
channelName = fmt.Sprintf("@%v", senderName)
} else {
channelName = fmt.Sprintf("@%v", sender.GetDisplayName(preference.Value))
senderName = channelName
}
}
}
msg := model.PushNotification{}
@@ -680,9 +727,12 @@ func (a *App) sendPushNotification(post *model.Post, user *model.User, channel *
msg.ChannelId = channel.Id
msg.PostId = post.Id
msg.RootId = post.RootId
msg.ChannelName = channel.Name
msg.SenderId = post.UserId
if contentsConfig != model.GENERIC_NO_CHANNEL_NOTIFICATION || channel.Type == model.CHANNEL_DIRECT {
msg.ChannelName = channelName
}
if ou, ok := post.Props["override_username"].(string); ok {
msg.OverrideUsername = ou
}
@@ -698,7 +748,7 @@ func (a *App) sendPushNotification(post *model.Post, user *model.User, channel *
userLocale := utils.GetUserTranslations(user.Locale)
hasFiles := post.FileIds != nil && len(post.FileIds) > 0
msg.Message, msg.Category = a.getPushNotificationMessage(post.Message, wasMentioned, hasFiles, senderName, channelName, channel.Type, userLocale)
msg.Message = a.getPushNotificationMessage(post.Message, explicitMention, channelWideMention, hasFiles, senderName, channelName, channel.Type, replyToThreadType, userLocale)
for _, session := range sessions {
tmpMessage := *model.PushNotificationFromJson(strings.NewReader(msg.ToJson()))
@@ -720,56 +770,44 @@ func (a *App) sendPushNotification(post *model.Post, user *model.User, channel *
return nil
}
func (a *App) getPushNotificationMessage(postMessage string, wasMentioned bool, hasFiles bool, senderName string, channelName string, channelType string, userLocale i18n.TranslateFunc) (string, string) {
func (a *App) getPushNotificationMessage(postMessage string, explicitMention, channelWideMention, hasFiles bool,
senderName, channelName, channelType, replyToThreadType string, userLocale i18n.TranslateFunc) string {
message := ""
category := ""
contentsConfig := *a.Config().EmailSettings.PushNotificationContents
if contentsConfig == model.FULL_NOTIFICATION {
category = model.CATEGORY_CAN_REPLY
if channelType == model.CHANNEL_DIRECT {
message = senderName + ": " + model.ClearMentionTags(postMessage)
message = model.ClearMentionTags(postMessage)
} else {
message = senderName + userLocale("api.post.send_notifications_and_forget.push_in") + channelName + ": " + model.ClearMentionTags(postMessage)
}
} else if contentsConfig == model.GENERIC_NO_CHANNEL_NOTIFICATION {
if channelType == model.CHANNEL_DIRECT {
category = model.CATEGORY_CAN_REPLY
message = senderName + userLocale("api.post.send_notifications_and_forget.push_message")
} else if wasMentioned {
message = senderName + userLocale("api.post.send_notifications_and_forget.push_mention_no_channel")
} else {
message = senderName + userLocale("api.post.send_notifications_and_forget.push_non_mention_no_channel")
message = "@" + senderName + ": " + model.ClearMentionTags(postMessage)
}
} else {
if channelType == model.CHANNEL_DIRECT {
category = model.CATEGORY_CAN_REPLY
message = senderName + userLocale("api.post.send_notifications_and_forget.push_message")
} else if wasMentioned {
category = model.CATEGORY_CAN_REPLY
message = senderName + userLocale("api.post.send_notifications_and_forget.push_mention") + channelName
message = userLocale("api.post.send_notifications_and_forget.push_message")
} else if channelWideMention {
message = "@" + senderName + userLocale("api.post.send_notification_and_forget.push_channel_mention")
} else if explicitMention {
message = "@" + senderName + userLocale("api.post.send_notifications_and_forget.push_explicit_mention")
} else if replyToThreadType == THREAD_ROOT {
message = "@" + senderName + userLocale("api.post.send_notification_and_forget.push_comment_on_post")
} else if replyToThreadType == THREAD_ANY {
message = "@" + senderName + userLocale("api.post.send_notification_and_forget.push_comment_on_thread")
} else {
message = senderName + userLocale("api.post.send_notifications_and_forget.push_non_mention") + channelName
message = "@" + senderName + userLocale("api.post.send_notifications_and_forget.push_general_message")
}
}
// If the post only has images then push an appropriate message
if len(postMessage) == 0 && hasFiles {
if channelType == model.CHANNEL_DIRECT {
message = senderName + userLocale("api.post.send_notifications_and_forget.push_image_only_dm")
} else if contentsConfig == model.GENERIC_NO_CHANNEL_NOTIFICATION {
message = senderName + userLocale("api.post.send_notifications_and_forget.push_image_only_no_channel")
message = strings.Trim(userLocale("api.post.send_notifications_and_forget.push_image_only"), " ")
} else {
message = senderName + userLocale("api.post.send_notifications_and_forget.push_image_only") + channelName
message = "@" + senderName + userLocale("api.post.send_notifications_and_forget.push_image_only")
}
}
return message, category
return message
}
func (a *App) ClearPushNotification(userId string, channelId string) {

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

@@ -1389,207 +1389,327 @@ func TestGetPushNotificationMessage(t *testing.T) {
for name, tc := range map[string]struct {
Message string
WasMentioned bool
explicitMention bool
channelWideMention bool
HasFiles bool
replyToThreadType string
Locale string
PushNotificationContents string
ChannelType string
ExpectedMessage string
ExpectedCategory string
ExpectedMessage string
}{
"full message, public channel, no mention": {
Message: "this is a message",
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "user in channel: this is a message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
Message: "this is a message",
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "@user: this is a message",
},
"full message, public channel, mention": {
Message: "this is a message",
WasMentioned: true,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "user in channel: this is a message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
Message: "this is a message",
explicitMention: true,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "@user: this is a message",
},
"full message, public channel, channel wide mention": {
Message: "this is a message",
channelWideMention: true,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "@user: this is a message",
},
"full message, public channel, commented on post": {
Message: "this is a message",
replyToThreadType: THREAD_ROOT,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "@user: this is a message",
},
"full message, public channel, commented on thread": {
Message: "this is a message",
replyToThreadType: THREAD_ANY,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "@user: this is a message",
},
"full message, private channel, no mention": {
Message: "this is a message",
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "user in channel: this is a message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
Message: "this is a message",
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "@user: this is a message",
},
"full message, private channel, mention": {
Message: "this is a message",
WasMentioned: true,
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "user in channel: this is a message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
Message: "this is a message",
explicitMention: true,
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "@user: this is a message",
},
"full message, private channel, commented on post": {
Message: "this is a message",
replyToThreadType: THREAD_ROOT,
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "@user: this is a message",
},
"full message, private channel, commented on thread": {
Message: "this is a message",
replyToThreadType: THREAD_ANY,
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "@user: this is a message",
},
"full message, group message channel, no mention": {
Message: "this is a message",
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "user in channel: this is a message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
Message: "this is a message",
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "@user: this is a message",
},
"full message, group message channel, mention": {
Message: "this is a message",
WasMentioned: true,
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "user in channel: this is a message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
Message: "this is a message",
explicitMention: true,
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "@user: this is a message",
},
"full message, group message channel, commented on post": {
Message: "this is a message",
replyToThreadType: THREAD_ROOT,
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "@user: this is a message",
},
"full message, group message channel, commented on thread": {
Message: "this is a message",
replyToThreadType: THREAD_ANY,
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "@user: this is a message",
},
"full message, direct message channel, no mention": {
Message: "this is a message",
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "user: this is a message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
Message: "this is a message",
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "this is a message",
},
"full message, direct message channel, mention": {
Message: "this is a message",
WasMentioned: true,
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "user: this is a message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
Message: "this is a message",
explicitMention: true,
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "this is a message",
},
"full message, direct message channel, commented on post": {
Message: "this is a message",
replyToThreadType: THREAD_ROOT,
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "this is a message",
},
"full message, direct message channel, commented on thread": {
Message: "this is a message",
replyToThreadType: THREAD_ANY,
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "this is a message",
},
"generic message with channel, public channel, no mention": {
Message: "this is a message",
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "user posted in channel",
ExpectedMessage: "@user posted a message.",
},
"generic message with channel, public channel, mention": {
Message: "this is a message",
WasMentioned: true,
explicitMention: true,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "user mentioned you in channel",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
ExpectedMessage: "@user mentioned you.",
},
"generic message with channel, public channel, channel wide mention": {
Message: "this is a message",
channelWideMention: true,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "@user notified the channel.",
},
"generic message, public channel, commented on post": {
Message: "this is a message",
replyToThreadType: THREAD_ROOT,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "@user commented on your post.",
},
"generic message, public channel, commented on thread": {
Message: "this is a message",
replyToThreadType: THREAD_ANY,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "@user commented on a thread you participated in.",
},
"generic message with channel, private channel, no mention": {
Message: "this is a message",
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "user posted in channel",
ExpectedMessage: "@user posted a message.",
},
"generic message with channel, private channel, mention": {
Message: "this is a message",
WasMentioned: true,
explicitMention: true,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "user mentioned you in channel",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
ExpectedMessage: "@user mentioned you.",
},
"generic message with channel, private channel, channel wide mention": {
Message: "this is a message",
channelWideMention: true,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "@user notified the channel.",
},
"generic message, public private, commented on post": {
Message: "this is a message",
replyToThreadType: THREAD_ROOT,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "@user commented on your post.",
},
"generic message, public private, commented on thread": {
Message: "this is a message",
replyToThreadType: THREAD_ANY,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "@user commented on a thread you participated in.",
},
"generic message with channel, group message channel, no mention": {
Message: "this is a message",
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "user posted in channel",
ExpectedMessage: "@user posted a message.",
},
"generic message with channel, group message channel, mention": {
Message: "this is a message",
WasMentioned: true,
explicitMention: true,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "user mentioned you in channel",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
ExpectedMessage: "@user mentioned you.",
},
"generic message with channel, group message channel, channel wide mention": {
Message: "this is a message",
channelWideMention: true,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "@user notified the channel.",
},
"generic message, group message channel, commented on post": {
Message: "this is a message",
replyToThreadType: THREAD_ROOT,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "@user commented on your post.",
},
"generic message, group message channel, commented on thread": {
Message: "this is a message",
replyToThreadType: THREAD_ANY,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "@user commented on a thread you participated in.",
},
"generic message with channel, direct message channel, no mention": {
Message: "this is a message",
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "user sent you a direct message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
ExpectedMessage: "sent you a message.",
},
"generic message with channel, direct message channel, mention": {
Message: "this is a message",
WasMentioned: true,
explicitMention: true,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "user sent you a direct message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
ExpectedMessage: "sent you a message.",
},
"generic message with channel, direct message channel, channel wide mention": {
Message: "this is a message",
channelWideMention: true,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "sent you a message.",
},
"generic message, direct message channel, commented on post": {
Message: "this is a message",
replyToThreadType: THREAD_ROOT,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "sent you a message.",
},
"generic message, direct message channel, commented on thread": {
Message: "this is a message",
replyToThreadType: THREAD_ANY,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "sent you a message.",
},
"generic message without channel, public channel, no mention": {
Message: "this is a message",
PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "user posted a message",
ExpectedMessage: "@user posted a message.",
},
"generic message without channel, public channel, mention": {
Message: "this is a message",
WasMentioned: true,
explicitMention: true,
PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "user mentioned you",
ExpectedMessage: "@user mentioned you.",
},
"generic message without channel, private channel, no mention": {
Message: "this is a message",
PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION,
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "user posted a message",
ExpectedMessage: "@user posted a message.",
},
"generic message without channel, private channel, mention": {
Message: "this is a message",
WasMentioned: true,
explicitMention: true,
PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION,
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "user mentioned you",
ExpectedMessage: "@user mentioned you.",
},
"generic message without channel, group message channel, no mention": {
Message: "this is a message",
PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION,
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "user posted a message",
ExpectedMessage: "@user posted a message.",
},
"generic message without channel, group message channel, mention": {
Message: "this is a message",
WasMentioned: true,
explicitMention: true,
PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION,
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "user mentioned you",
ExpectedMessage: "@user mentioned you.",
},
"generic message without channel, direct message channel, no mention": {
Message: "this is a message",
PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION,
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "user sent you a direct message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
ExpectedMessage: "sent you a message.",
},
"generic message without channel, direct message channel, mention": {
Message: "this is a message",
WasMentioned: true,
explicitMention: true,
PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION,
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "user sent you a direct message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
ExpectedMessage: "sent you a message.",
},
"only files, public channel": {
HasFiles: true,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "user uploaded one or more files in channel",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
HasFiles: true,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "@user attached a file.",
},
"only files, private channel": {
HasFiles: true,
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "user uploaded one or more files in channel",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
HasFiles: true,
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "@user attached a file.",
},
"only files, group message channel": {
HasFiles: true,
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "user uploaded one or more files in channel",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
HasFiles: true,
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "@user attached a file.",
},
"only files, direct message channel": {
HasFiles: true,
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "user uploaded one or more files in a direct message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
HasFiles: true,
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "attached a file.",
},
"only files without channel, public channel": {
HasFiles: true,
PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "user uploaded one or more files",
ExpectedMessage: "@user attached a file.",
},
} {
t.Run(name, func(t *testing.T) {
@@ -1607,18 +1727,18 @@ func TestGetPushNotificationMessage(t *testing.T) {
*cfg.EmailSettings.PushNotificationContents = pushNotificationContents
})
if actualMessage, actualCategory := th.App.getPushNotificationMessage(
if actualMessage := th.App.getPushNotificationMessage(
tc.Message,
tc.WasMentioned,
tc.explicitMention,
tc.channelWideMention,
tc.HasFiles,
"user",
"channel",
tc.ChannelType,
tc.replyToThreadType,
utils.GetUserTranslations(locale),
); actualMessage != tc.ExpectedMessage {
t.Fatalf("Received incorrect push notification message `%v`, expected `%v`", actualMessage, tc.ExpectedMessage)
} else if actualCategory != tc.ExpectedCategory {
t.Fatalf("Received incorrect push notification category `%v`, expected `%v`", actualCategory, tc.ExpectedCategory)
}
})
}

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

@@ -1916,39 +1916,31 @@
},
{
"id": "api.post.send_notifications_and_forget.push_image_only",
"translation": " uploaded one or more files in "
"translation": " attached a file."
},
{
"id": "api.post.send_notifications_and_forget.push_image_only_dm",
"translation": " uploaded one or more files in a direct message"
"id": "api.post.send_notifications_and_forget.push_explicit_mention",
"translation": " mentioned you."
},
{
"id": "api.post.send_notifications_and_forget.push_image_only_no_channel",
"translation": " uploaded one or more files"
"id": "api.post.send_notification_and_forget.push_channel_mention",
"translation": " notified the channel."
},
{
"id": "api.post.send_notifications_and_forget.push_in",
"translation": " in "
"id": "api.post.send_notification_and_forget.push_comment_on_post",
"translation": " commented on your post."
},
{
"id": "api.post.send_notifications_and_forget.push_mention",
"translation": " mentioned you in "
},
{
"id": "api.post.send_notifications_and_forget.push_mention_no_channel",
"translation": " mentioned you"
"id": "api.post.send_notification_and_forget.push_comment_on_thread",
"translation": " commented on a thread you participated in."
},
{
"id": "api.post.send_notifications_and_forget.push_message",
"translation": " sent you a direct message"
"translation": "sent you a message."
},
{
"id": "api.post.send_notifications_and_forget.push_non_mention",
"translation": " posted in "
},
{
"id": "api.post.send_notifications_and_forget.push_non_mention_no_channel",
"translation": " posted a message"
"id": "api.post.send_notifications_and_forget.push_general_message",
"translation": " posted a message."
},
{
"id": "api.post.send_notifications_and_forget.push_notification.error",