[MM-16232] ID loaded push notifications (#13137)
* Update BuildPushNotificationMessage (#12974) * Update BuildPushNotificationMessage * Included Category, Version, and Type * Remove unnecessary function args * [MM-16232] Build and return fetched notification (#13085) * Build and return fetched notification * Remove check on PushNotificationContents * Ran i18n-extract * Get UserId from session * Re-add ReturnStatusOK * Remove UserId from PushNotificationAck * Always include channel name * [MM-16232] Return after writing response and add default message (#13127) * Return after writing response and add default message * Include channel ID as well * Localize default message * Fix i18n
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
2571d97723
Коммит
d44d563ef3
@@ -102,7 +102,7 @@ func (a *App) sendPushNotificationSync(post *model.Post, user *model.User, chann
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) sendPushNotification(notification *postNotification, user *model.User, explicitMention, channelWideMention bool, replyToThreadType string) {
|
||||
func (a *App) sendPushNotification(notification *PostNotification, user *model.User, explicitMention, channelWideMention bool, replyToThreadType string) {
|
||||
cfg := a.Config()
|
||||
channel := notification.channel
|
||||
post := notification.post
|
||||
@@ -126,6 +126,22 @@ func (a *App) sendPushNotification(notification *postNotification, user *model.U
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) getFetchedPushNotificationMessage(postMessage, senderName, channelType string, hasFiles bool, userLocale i18n.TranslateFunc) string {
|
||||
// If the post only has images then push an appropriate message
|
||||
if len(postMessage) == 0 && hasFiles {
|
||||
if channelType == model.CHANNEL_DIRECT {
|
||||
return strings.Trim(userLocale("api.post.send_notifications_and_forget.push_image_only"), " ")
|
||||
}
|
||||
return senderName + userLocale("api.post.send_notifications_and_forget.push_image_only")
|
||||
}
|
||||
|
||||
if channelType == model.CHANNEL_DIRECT {
|
||||
return model.ClearMentionTags(postMessage)
|
||||
}
|
||||
|
||||
return senderName + ": " + model.ClearMentionTags(postMessage)
|
||||
}
|
||||
|
||||
func (a *App) getPushNotificationMessage(postMessage string, explicitMention, channelWideMention, hasFiles bool,
|
||||
senderName, channelName, channelType, replyToThreadType string, userLocale i18n.TranslateFunc) string {
|
||||
|
||||
@@ -427,9 +443,109 @@ func DoesStatusAllowPushNotification(userNotifyProps model.StringMap, status *mo
|
||||
return false
|
||||
}
|
||||
|
||||
func (a *App) BuildFetchedPushNotificationMessage(postId string, userId string) (model.PushNotification, *model.AppError) {
|
||||
msg := model.PushNotification{
|
||||
Type: model.PUSH_TYPE_ID_LOADED,
|
||||
Category: model.CATEGORY_CAN_REPLY,
|
||||
Version: model.PUSH_MESSAGE_V2,
|
||||
}
|
||||
|
||||
post, err := a.GetSinglePost(postId)
|
||||
if err != nil {
|
||||
return msg, err
|
||||
}
|
||||
|
||||
channel, err := a.GetChannel(post.ChannelId)
|
||||
if err != nil {
|
||||
return msg, err
|
||||
}
|
||||
|
||||
user, err := a.GetUser(userId)
|
||||
if err != nil {
|
||||
return msg, err
|
||||
}
|
||||
|
||||
sender, err := a.GetUser(post.UserId)
|
||||
if err != nil {
|
||||
return msg, err
|
||||
}
|
||||
|
||||
msg.PostId = post.Id
|
||||
msg.RootId = post.RootId
|
||||
msg.SenderId = post.UserId
|
||||
msg.ChannelId = channel.Id
|
||||
msg.TeamId = channel.TeamId
|
||||
|
||||
notification := &PostNotification{
|
||||
post: post,
|
||||
channel: channel,
|
||||
sender: sender,
|
||||
}
|
||||
|
||||
cfg := a.Config()
|
||||
nameFormat := a.GetNotificationNameFormat(user)
|
||||
channelName := notification.GetChannelName(nameFormat, user.Id)
|
||||
senderName := notification.GetSenderName(nameFormat, *cfg.ServiceSettings.EnablePostUsernameOverride)
|
||||
|
||||
msg.ChannelName = channelName
|
||||
|
||||
msg.SenderName = senderName
|
||||
if ou, ok := post.Props["override_username"].(string); ok && *cfg.ServiceSettings.EnablePostUsernameOverride {
|
||||
msg.OverrideUsername = ou
|
||||
msg.SenderName = ou
|
||||
}
|
||||
|
||||
if oi, ok := post.Props["override_icon_url"].(string); ok && *cfg.ServiceSettings.EnablePostIconOverride {
|
||||
msg.OverrideIconUrl = oi
|
||||
}
|
||||
|
||||
if fw, ok := post.Props["from_webhook"].(string); ok {
|
||||
msg.FromWebhook = fw
|
||||
}
|
||||
|
||||
userLocale := utils.GetUserTranslations(user.Locale)
|
||||
hasFiles := post.FileIds != nil && len(post.FileIds) > 0
|
||||
|
||||
msg.Message = a.getFetchedPushNotificationMessage(post.Message, msg.SenderName, channel.Type, hasFiles, userLocale)
|
||||
|
||||
return msg, nil
|
||||
}
|
||||
|
||||
func (a *App) BuildPushNotificationMessage(post *model.Post, user *model.User, channel *model.Channel, channelName string, senderName string,
|
||||
explicitMention bool, channelWideMention bool, replyToThreadType string) model.PushNotification {
|
||||
|
||||
var msg model.PushNotification
|
||||
|
||||
cfg := a.Config()
|
||||
contentsConfig := *cfg.EmailSettings.PushNotificationContents
|
||||
if contentsConfig == model.ID_LOADED_NOTIFICATION {
|
||||
msg = a.buildIdLoadedPushNotificationMessage(post, user)
|
||||
} else {
|
||||
msg = a.buildFullPushNotificationMessage(post, user, channel, channelName, senderName, explicitMention, channelWideMention, replyToThreadType)
|
||||
}
|
||||
|
||||
msg.Badge = a.getPushNotificationBadge(user, channel)
|
||||
|
||||
return msg
|
||||
}
|
||||
|
||||
func (a *App) buildIdLoadedPushNotificationMessage(post *model.Post, user *model.User) model.PushNotification {
|
||||
userLocale := utils.GetUserTranslations(user.Locale)
|
||||
msg := model.PushNotification{
|
||||
PostId: post.Id,
|
||||
ChannelId: post.ChannelId,
|
||||
Category: model.CATEGORY_CAN_REPLY,
|
||||
Version: model.PUSH_MESSAGE_V2,
|
||||
Type: model.PUSH_TYPE_ID_LOADED,
|
||||
Message: userLocale("api.push_notification.id_loaded.default_message"),
|
||||
}
|
||||
|
||||
return msg
|
||||
}
|
||||
|
||||
func (a *App) buildFullPushNotificationMessage(post *model.Post, user *model.User, channel *model.Channel, channelName string, senderName string,
|
||||
explicitMention bool, channelWideMention bool, replyToThreadType string) model.PushNotification {
|
||||
|
||||
msg := model.PushNotification{
|
||||
Category: model.CATEGORY_CAN_REPLY,
|
||||
Version: model.PUSH_MESSAGE_V2,
|
||||
@@ -441,22 +557,6 @@ func (a *App) BuildPushNotificationMessage(post *model.Post, user *model.User, c
|
||||
SenderId: post.UserId,
|
||||
}
|
||||
|
||||
if user.NotifyProps["push"] == "all" {
|
||||
if unreadCount, err := a.Srv.Store.User().GetAnyUnreadPostCountForChannel(user.Id, channel.Id); err != nil {
|
||||
msg.Badge = 1
|
||||
mlog.Error("We could not get the unread message count for the user", mlog.String("user_id", user.Id), mlog.Err(err))
|
||||
} else {
|
||||
msg.Badge = int(unreadCount)
|
||||
}
|
||||
} else {
|
||||
if unreadCount, err := a.Srv.Store.User().GetUnreadCount(user.Id); err != nil {
|
||||
msg.Badge = 1
|
||||
mlog.Error("We could not get the unread message count for the user", mlog.String("user_id", user.Id), mlog.Err(err))
|
||||
} else {
|
||||
msg.Badge = int(unreadCount)
|
||||
}
|
||||
}
|
||||
|
||||
cfg := a.Config()
|
||||
contentsConfig := *cfg.EmailSettings.PushNotificationContents
|
||||
if contentsConfig != model.GENERIC_NO_CHANNEL_NOTIFICATION || channel.Type == model.CHANNEL_DIRECT {
|
||||
@@ -484,3 +584,25 @@ func (a *App) BuildPushNotificationMessage(post *model.Post, user *model.User, c
|
||||
|
||||
return msg
|
||||
}
|
||||
|
||||
func (a *App) getPushNotificationBadge(user *model.User, channel *model.Channel) int {
|
||||
var badge int
|
||||
|
||||
if user.NotifyProps["push"] == "all" {
|
||||
if unreadCount, err := a.Srv.Store.User().GetAnyUnreadPostCountForChannel(user.Id, channel.Id); err != nil {
|
||||
badge = 1
|
||||
mlog.Error("We could not get the unread message count for the user", mlog.String("user_id", user.Id), mlog.Err(err))
|
||||
} else {
|
||||
badge = int(unreadCount)
|
||||
}
|
||||
} else {
|
||||
if unreadCount, err := a.Srv.Store.User().GetUnreadCount(user.Id); err != nil {
|
||||
badge = 1
|
||||
mlog.Error("We could not get the unread message count for the user", mlog.String("user_id", user.Id), mlog.Err(err))
|
||||
} else {
|
||||
badge = int(unreadCount)
|
||||
}
|
||||
}
|
||||
|
||||
return badge
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user