diff --git a/app/lib/server/functions/notifications/index.js b/app/lib/server/functions/notifications/index.js index d76bb70eb48..f3f21638bcc 100644 --- a/app/lib/server/functions/notifications/index.js +++ b/app/lib/server/functions/notifications/index.js @@ -13,10 +13,6 @@ import { settings } from '../../../../settings'; export function parseMessageTextPerUser(messageText, message, receiver) { const lng = receiver.language || settings.get('Language') || 'en'; - if (settings.get('Push_request_content_from_server')) { - return TAPi18n.__('You_have_a_new_message', { lng }); - } - if (!message.msg && message.attachments && message.attachments[0]) { return message.attachments[0].image_type ? TAPi18n.__('User_uploaded_image', { lng }) : TAPi18n.__('User_uploaded_file', { lng }); } diff --git a/app/lib/server/functions/notifications/mobile.js b/app/lib/server/functions/notifications/mobile.js index 5853ba21dc0..02e5cb4d4f8 100644 --- a/app/lib/server/functions/notifications/mobile.js +++ b/app/lib/server/functions/notifications/mobile.js @@ -1,4 +1,5 @@ import { Meteor } from 'meteor/meteor'; +import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; import { settings } from '../../../../settings'; import { Subscriptions } from '../../../../models'; @@ -40,12 +41,23 @@ function enableNotificationReplyButton(room, username) { return !room.muted.includes(username); } -export async function getPushData({ room, message, userId, receiverUsername, senderUsername, senderName, notificationMessage }) { +export async function getPushData({ room, message, userId, senderUsername, senderName, notificationMessage, receiver, shouldOmitMessage = true }) { let username = ''; if (settings.get('Push_show_username_room')) { username = settings.get('UI_Use_Real_Name') === true ? senderName : senderUsername; } + const lng = receiver.language || settings.get('Language') || 'en'; + + let messageText; + if (shouldOmitMessage && settings.get('Push_request_content_from_server')) { + messageText = TAPi18n.__('You_have_a_new_message', { lng }); + } else if (!settings.get('Push_show_message')) { + messageText = ' '; + } else { + messageText = notificationMessage; + } + return { payload: { sender: message.u, @@ -56,9 +68,9 @@ export async function getPushData({ room, message, userId, receiverUsername, sen }, roomName: settings.get('Push_show_username_room') && roomTypes.getConfig(room.t).isGroupChat(room) ? `#${ roomTypes.getRoomName(room.t, room) }` : '', username, - message: settings.get('Push_show_message') ? notificationMessage : ' ', + message: messageText, badge: await getBadgeCount(userId), - category: enableNotificationReplyButton(room, receiverUsername) ? CATEGORY_MESSAGE : CATEGORY_MESSAGE_NOREPLY, + category: enableNotificationReplyButton(room, receiver.username) ? CATEGORY_MESSAGE : CATEGORY_MESSAGE_NOREPLY, }; } diff --git a/app/lib/server/lib/sendNotificationsOnMessage.js b/app/lib/server/lib/sendNotificationsOnMessage.js index 52b69b341d7..cec7d55150c 100644 --- a/app/lib/server/lib/sendNotificationsOnMessage.js +++ b/app/lib/server/lib/sendNotificationsOnMessage.js @@ -140,7 +140,7 @@ export const sendNotification = async ({ userId: subscription.u._id, senderUsername: sender.username, senderName: sender.name, - receiverUsername: receiver.username, + receiver, }), }); } diff --git a/app/push-notifications/server/lib/PushNotification.js b/app/push-notifications/server/lib/PushNotification.js index dc97c7876e6..115dc029405 100644 --- a/app/push-notifications/server/lib/PushNotification.js +++ b/app/push-notifications/server/lib/PushNotification.js @@ -18,7 +18,7 @@ export class PushNotification { getNotificationConfig({ rid, uid: userId, mid: messageId, roomName, username, message, payload, badge = 1, category, idOnly = false }) { const title = idOnly ? '' : roomName || username; - // message is being redacted already by 'parseMessageTextPerUser' if idOnly is true + // message is being redacted already by 'getPushData' if idOnly is true const text = !idOnly && roomName !== '' ? `${ username }: ${ message }` : message; const config = { @@ -86,10 +86,11 @@ export class PushNotification { room, message, userId: receiver._id, - receiverUsername: receiver.username, + receiver, senderUsername: sender.username, senderName: sender.name, notificationMessage, + shouldOmitMessage: false, })); return {