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" "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) { 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) pchan := a.Srv.Store.User().GetAllProfilesInChannel(channel.Id, true)
cmnchan := a.Srv.Store.Channel().GetAllChannelMembersNotifyPropsForChannel(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) mentionedUserIds := make(map[string]bool)
threadMentionedUserIds := make(map[string]string)
allActivityPushUserIds := []string{} allActivityPushUserIds := []string{}
hereNotification := false hereNotification := false
channelNotification := 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 { if len(post.RootId) > 0 && parentPostList != nil {
for _, threadPost := range parentPostList.Posts { for _, threadPost := range parentPostList.Posts {
profile := profileMap[threadPost.UserId] profile := profileMap[threadPost.UserId]
if profile != nil && (profile.NotifyProps["comments"] == "any" || (profile.NotifyProps["comments"] == "root" && threadPost.Id == parentPostList.Order[0])) { if profile != nil && (profile.NotifyProps["comments"] == THREAD_ANY || (profile.NotifyProps["comments"] == THREAD_ROOT && threadPost.Id == parentPostList.Order[0])) {
mentionedUserIds[threadPost.UserId] = true 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)) updateMentionChans = append(updateMentionChans, a.Srv.Store.Channel().IncrementMentionCount(post.ChannelId, id))
} }
var senderUsername string
senderName := "" senderName := ""
channelName := "" channelName := ""
if post.IsSystemMessage() { if post.IsSystemMessage() {
@@ -152,8 +167,10 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
} else { } else {
if value, ok := post.Props["override_username"]; ok && post.Props["from_webhook"] == "true" { if value, ok := post.Props["override_username"]; ok && post.Props["from_webhook"] == "true" {
senderName = value.(string) senderName = value.(string)
senderUsername = value.(string)
} else { } else {
senderName = sender.Username 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 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 { if a.Config().EmailSettings.SendEmailNotifications {
for _, id := range mentionedUsersList { for _, id := range mentionedUsersList {
if profileMap[id] == nil { 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) { 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) { 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) sessions, err := a.getMobileAppSessions(user.Id)
if err != nil { if err != nil {
return err return err
} }
if channel.Type == model.CHANNEL_DIRECT { 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{} msg := model.PushNotification{}
@@ -680,9 +727,12 @@ func (a *App) sendPushNotification(post *model.Post, user *model.User, channel *
msg.ChannelId = channel.Id msg.ChannelId = channel.Id
msg.PostId = post.Id msg.PostId = post.Id
msg.RootId = post.RootId msg.RootId = post.RootId
msg.ChannelName = channel.Name
msg.SenderId = post.UserId 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 { if ou, ok := post.Props["override_username"].(string); ok {
msg.OverrideUsername = ou msg.OverrideUsername = ou
} }
@@ -698,7 +748,7 @@ func (a *App) sendPushNotification(post *model.Post, user *model.User, channel *
userLocale := utils.GetUserTranslations(user.Locale) userLocale := utils.GetUserTranslations(user.Locale)
hasFiles := post.FileIds != nil && len(post.FileIds) > 0 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 { for _, session := range sessions {
tmpMessage := *model.PushNotificationFromJson(strings.NewReader(msg.ToJson())) tmpMessage := *model.PushNotificationFromJson(strings.NewReader(msg.ToJson()))
@@ -720,56 +770,44 @@ func (a *App) sendPushNotification(post *model.Post, user *model.User, channel *
return nil 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 := "" message := ""
category := ""
contentsConfig := *a.Config().EmailSettings.PushNotificationContents contentsConfig := *a.Config().EmailSettings.PushNotificationContents
if contentsConfig == model.FULL_NOTIFICATION { if contentsConfig == model.FULL_NOTIFICATION {
category = model.CATEGORY_CAN_REPLY
if channelType == model.CHANNEL_DIRECT { if channelType == model.CHANNEL_DIRECT {
message = senderName + ": " + model.ClearMentionTags(postMessage) message = model.ClearMentionTags(postMessage)
} else { } else {
message = senderName + userLocale("api.post.send_notifications_and_forget.push_in") + channelName + ": " + model.ClearMentionTags(postMessage) message = "@" + senderName + ": " + 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")
} }
} else { } else {
if channelType == model.CHANNEL_DIRECT { if channelType == model.CHANNEL_DIRECT {
category = model.CATEGORY_CAN_REPLY message = userLocale("api.post.send_notifications_and_forget.push_message")
} else if channelWideMention {
message = senderName + userLocale("api.post.send_notifications_and_forget.push_message") message = "@" + senderName + userLocale("api.post.send_notification_and_forget.push_channel_mention")
} else if wasMentioned { } else if explicitMention {
category = model.CATEGORY_CAN_REPLY message = "@" + senderName + userLocale("api.post.send_notifications_and_forget.push_explicit_mention")
} else if replyToThreadType == THREAD_ROOT {
message = senderName + userLocale("api.post.send_notifications_and_forget.push_mention") + channelName 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 { } 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 the post only has images then push an appropriate message
if len(postMessage) == 0 && hasFiles { if len(postMessage) == 0 && hasFiles {
if channelType == model.CHANNEL_DIRECT { if channelType == model.CHANNEL_DIRECT {
message = senderName + userLocale("api.post.send_notifications_and_forget.push_image_only_dm") message = strings.Trim(userLocale("api.post.send_notifications_and_forget.push_image_only"), " ")
} else if contentsConfig == model.GENERIC_NO_CHANNEL_NOTIFICATION {
message = senderName + userLocale("api.post.send_notifications_and_forget.push_image_only_no_channel")
} else { } 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) { func (a *App) ClearPushNotification(userId string, channelId string) {

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

@@ -1389,207 +1389,327 @@ func TestGetPushNotificationMessage(t *testing.T) {
for name, tc := range map[string]struct { for name, tc := range map[string]struct {
Message string Message string
WasMentioned bool explicitMention bool
channelWideMention bool
HasFiles bool HasFiles bool
replyToThreadType string
Locale string Locale string
PushNotificationContents string PushNotificationContents string
ChannelType string ChannelType string
ExpectedMessage string ExpectedMessage string
ExpectedCategory string
}{ }{
"full message, public channel, no mention": { "full message, public channel, no mention": {
Message: "this is a message", Message: "this is a message",
ChannelType: model.CHANNEL_OPEN, ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "user in channel: this is a message", ExpectedMessage: "@user: this is a message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
}, },
"full message, public channel, mention": { "full message, public channel, mention": {
Message: "this is a message", Message: "this is a message",
WasMentioned: true, explicitMention: true,
ChannelType: model.CHANNEL_OPEN, ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "user in channel: this is a message", ExpectedMessage: "@user: this is a message",
ExpectedCategory: model.CATEGORY_CAN_REPLY, },
"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": { "full message, private channel, no mention": {
Message: "this is a message", Message: "this is a message",
ChannelType: model.CHANNEL_PRIVATE, ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "user in channel: this is a message", ExpectedMessage: "@user: this is a message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
}, },
"full message, private channel, mention": { "full message, private channel, mention": {
Message: "this is a message", Message: "this is a message",
WasMentioned: true, explicitMention: true,
ChannelType: model.CHANNEL_PRIVATE, ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "user in channel: this is a message", ExpectedMessage: "@user: this is a message",
ExpectedCategory: model.CATEGORY_CAN_REPLY, },
"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": { "full message, group message channel, no mention": {
Message: "this is a message", Message: "this is a message",
ChannelType: model.CHANNEL_GROUP, ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "user in channel: this is a message", ExpectedMessage: "@user: this is a message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
}, },
"full message, group message channel, mention": { "full message, group message channel, mention": {
Message: "this is a message", Message: "this is a message",
WasMentioned: true, explicitMention: true,
ChannelType: model.CHANNEL_GROUP, ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "user in channel: this is a message", ExpectedMessage: "@user: this is a message",
ExpectedCategory: model.CATEGORY_CAN_REPLY, },
"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": { "full message, direct message channel, no mention": {
Message: "this is a message", Message: "this is a message",
ChannelType: model.CHANNEL_DIRECT, ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "user: this is a message", ExpectedMessage: "this is a message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
}, },
"full message, direct message channel, mention": { "full message, direct message channel, mention": {
Message: "this is a message", Message: "this is a message",
WasMentioned: true, explicitMention: true,
ChannelType: model.CHANNEL_DIRECT, ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "user: this is a message", ExpectedMessage: "this is a message",
ExpectedCategory: model.CATEGORY_CAN_REPLY, },
"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": { "generic message with channel, public channel, no mention": {
Message: "this is a message", Message: "this is a message",
PushNotificationContents: model.GENERIC_NOTIFICATION, PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_OPEN, ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "user posted in channel", ExpectedMessage: "@user posted a message.",
}, },
"generic message with channel, public channel, mention": { "generic message with channel, public channel, mention": {
Message: "this is a message", Message: "this is a message",
WasMentioned: true, explicitMention: true,
PushNotificationContents: model.GENERIC_NOTIFICATION, PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_OPEN, ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "user mentioned you in channel", ExpectedMessage: "@user mentioned you.",
ExpectedCategory: model.CATEGORY_CAN_REPLY, },
"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": { "generic message with channel, private channel, no mention": {
Message: "this is a message", Message: "this is a message",
PushNotificationContents: model.GENERIC_NOTIFICATION, PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_PRIVATE, ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "user posted in channel", ExpectedMessage: "@user posted a message.",
}, },
"generic message with channel, private channel, mention": { "generic message with channel, private channel, mention": {
Message: "this is a message", Message: "this is a message",
WasMentioned: true, explicitMention: true,
PushNotificationContents: model.GENERIC_NOTIFICATION, PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_PRIVATE, ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "user mentioned you in channel", ExpectedMessage: "@user mentioned you.",
ExpectedCategory: model.CATEGORY_CAN_REPLY, },
"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": { "generic message with channel, group message channel, no mention": {
Message: "this is a message", Message: "this is a message",
PushNotificationContents: model.GENERIC_NOTIFICATION, PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_GROUP, ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "user posted in channel", ExpectedMessage: "@user posted a message.",
}, },
"generic message with channel, group message channel, mention": { "generic message with channel, group message channel, mention": {
Message: "this is a message", Message: "this is a message",
WasMentioned: true, explicitMention: true,
PushNotificationContents: model.GENERIC_NOTIFICATION, PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_GROUP, ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "user mentioned you in channel", ExpectedMessage: "@user mentioned you.",
ExpectedCategory: model.CATEGORY_CAN_REPLY, },
"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": { "generic message with channel, direct message channel, no mention": {
Message: "this is a message", Message: "this is a message",
PushNotificationContents: model.GENERIC_NOTIFICATION, PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_DIRECT, ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "user sent you a direct message", ExpectedMessage: "sent you a message.",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
}, },
"generic message with channel, direct message channel, mention": { "generic message with channel, direct message channel, mention": {
Message: "this is a message", Message: "this is a message",
WasMentioned: true, explicitMention: true,
PushNotificationContents: model.GENERIC_NOTIFICATION, PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_DIRECT, ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "user sent you a direct message", ExpectedMessage: "sent you a message.",
ExpectedCategory: model.CATEGORY_CAN_REPLY, },
"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": { "generic message without channel, public channel, no mention": {
Message: "this is a message", Message: "this is a message",
PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION,
ChannelType: model.CHANNEL_OPEN, ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "user posted a message", ExpectedMessage: "@user posted a message.",
}, },
"generic message without channel, public channel, mention": { "generic message without channel, public channel, mention": {
Message: "this is a message", Message: "this is a message",
WasMentioned: true, explicitMention: true,
PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION,
ChannelType: model.CHANNEL_OPEN, ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "user mentioned you", ExpectedMessage: "@user mentioned you.",
}, },
"generic message without channel, private channel, no mention": { "generic message without channel, private channel, no mention": {
Message: "this is a message", Message: "this is a message",
PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION,
ChannelType: model.CHANNEL_PRIVATE, ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "user posted a message", ExpectedMessage: "@user posted a message.",
}, },
"generic message without channel, private channel, mention": { "generic message without channel, private channel, mention": {
Message: "this is a message", Message: "this is a message",
WasMentioned: true, explicitMention: true,
PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION,
ChannelType: model.CHANNEL_PRIVATE, ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "user mentioned you", ExpectedMessage: "@user mentioned you.",
}, },
"generic message without channel, group message channel, no mention": { "generic message without channel, group message channel, no mention": {
Message: "this is a message", Message: "this is a message",
PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION,
ChannelType: model.CHANNEL_GROUP, ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "user posted a message", ExpectedMessage: "@user posted a message.",
}, },
"generic message without channel, group message channel, mention": { "generic message without channel, group message channel, mention": {
Message: "this is a message", Message: "this is a message",
WasMentioned: true, explicitMention: true,
PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION,
ChannelType: model.CHANNEL_GROUP, ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "user mentioned you", ExpectedMessage: "@user mentioned you.",
}, },
"generic message without channel, direct message channel, no mention": { "generic message without channel, direct message channel, no mention": {
Message: "this is a message", Message: "this is a message",
PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION,
ChannelType: model.CHANNEL_DIRECT, ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "user sent you a direct message", ExpectedMessage: "sent you a message.",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
}, },
"generic message without channel, direct message channel, mention": { "generic message without channel, direct message channel, mention": {
Message: "this is a message", Message: "this is a message",
WasMentioned: true, explicitMention: true,
PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION,
ChannelType: model.CHANNEL_DIRECT, ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "user sent you a direct message", ExpectedMessage: "sent you a message.",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
}, },
"only files, public channel": { "only files, public channel": {
HasFiles: true, HasFiles: true,
ChannelType: model.CHANNEL_OPEN, ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "user uploaded one or more files in channel", ExpectedMessage: "@user attached a file.",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
}, },
"only files, private channel": { "only files, private channel": {
HasFiles: true, HasFiles: true,
ChannelType: model.CHANNEL_PRIVATE, ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "user uploaded one or more files in channel", ExpectedMessage: "@user attached a file.",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
}, },
"only files, group message channel": { "only files, group message channel": {
HasFiles: true, HasFiles: true,
ChannelType: model.CHANNEL_GROUP, ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "user uploaded one or more files in channel", ExpectedMessage: "@user attached a file.",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
}, },
"only files, direct message channel": { "only files, direct message channel": {
HasFiles: true, HasFiles: true,
ChannelType: model.CHANNEL_DIRECT, ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "user uploaded one or more files in a direct message", ExpectedMessage: "attached a file.",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
}, },
"only files without channel, public channel": { "only files without channel, public channel": {
HasFiles: true, HasFiles: true,
PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION,
ChannelType: model.CHANNEL_OPEN, ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "user uploaded one or more files", ExpectedMessage: "@user attached a file.",
}, },
} { } {
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
@@ -1607,18 +1727,18 @@ func TestGetPushNotificationMessage(t *testing.T) {
*cfg.EmailSettings.PushNotificationContents = pushNotificationContents *cfg.EmailSettings.PushNotificationContents = pushNotificationContents
}) })
if actualMessage, actualCategory := th.App.getPushNotificationMessage( if actualMessage := th.App.getPushNotificationMessage(
tc.Message, tc.Message,
tc.WasMentioned, tc.explicitMention,
tc.channelWideMention,
tc.HasFiles, tc.HasFiles,
"user", "user",
"channel", "channel",
tc.ChannelType, tc.ChannelType,
tc.replyToThreadType,
utils.GetUserTranslations(locale), utils.GetUserTranslations(locale),
); actualMessage != tc.ExpectedMessage { ); actualMessage != tc.ExpectedMessage {
t.Fatalf("Received incorrect push notification message `%v`, expected `%v`", 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", "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", "id": "api.post.send_notifications_and_forget.push_explicit_mention",
"translation": " uploaded one or more files in a direct message" "translation": " mentioned you."
}, },
{ {
"id": "api.post.send_notifications_and_forget.push_image_only_no_channel", "id": "api.post.send_notification_and_forget.push_channel_mention",
"translation": " uploaded one or more files" "translation": " notified the channel."
}, },
{ {
"id": "api.post.send_notifications_and_forget.push_in", "id": "api.post.send_notification_and_forget.push_comment_on_post",
"translation": " in " "translation": " commented on your post."
}, },
{ {
"id": "api.post.send_notifications_and_forget.push_mention", "id": "api.post.send_notification_and_forget.push_comment_on_thread",
"translation": " mentioned you in " "translation": " commented on a thread you participated in."
},
{
"id": "api.post.send_notifications_and_forget.push_mention_no_channel",
"translation": " mentioned you"
}, },
{ {
"id": "api.post.send_notifications_and_forget.push_message", "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", "id": "api.post.send_notifications_and_forget.push_general_message",
"translation": " posted in " "translation": " posted a message."
},
{
"id": "api.post.send_notifications_and_forget.push_non_mention_no_channel",
"translation": " posted a message"
}, },
{ {
"id": "api.post.send_notifications_and_forget.push_notification.error", "id": "api.post.send_notifications_and_forget.push_notification.error",