From 716ab0895586f46ee09864aea9dcbe0c1b51d9c9 Mon Sep 17 00:00:00 2001 From: Djorkaeff Alexandre Date: Fri, 24 Jul 2020 12:20:02 -0300 Subject: [PATCH 1/2] [IMPROVE] Provide a fallback text when push notification is idOnly --- app/push-notifications/server/lib/PushNotification.js | 3 ++- packages/rocketchat-i18n/i18n/en.i18n.json | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/push-notifications/server/lib/PushNotification.js b/app/push-notifications/server/lib/PushNotification.js index 5da6bbcc5314..4beb07bfe7f7 100644 --- a/app/push-notifications/server/lib/PushNotification.js +++ b/app/push-notifications/server/lib/PushNotification.js @@ -1,4 +1,5 @@ import { Meteor } from 'meteor/meteor'; +import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; import { Push } from '../../../push/server'; import { settings } from '../../../settings/server'; @@ -30,7 +31,7 @@ export class PushNotification { sound: 'default', priority: 10, title: idOnly ? '' : title, - text: idOnly ? ' ' : message, + text: idOnly ? TAPi18n.__('Someone_sent_you_a_message') : message, payload: { host: Meteor.absoluteUrl(), ...idOnly || { rid }, diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index 3cdc681e9878..3926771568ee 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -3319,6 +3319,7 @@ "Snippet_name": "Snippet name", "Snippeted_a_message": "Created a snippet __snippetLink__", "Social_Network": "Social Network", + "Someone_sent_you_a_message": "Someone sent you a message", "Sorry_page_you_requested_does_not_exist_or_was_deleted": "Sorry, page you requested does not exist or was deleted!", "Sort": "Sort", "Sort_By": "Sort by", From 759f97bb4bfa2fd40e5a6cc39706c0d66269cefe Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Fri, 24 Jul 2020 16:25:02 -0300 Subject: [PATCH 2/2] Redact message per user --- .../server/functions/notifications/index.js | 10 ++++++---- .../server/lib/PushNotification.js | 19 +++++++------------ packages/rocketchat-i18n/i18n/en.i18n.json | 2 +- packages/rocketchat-i18n/i18n/pt-BR.i18n.json | 1 + 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/app/lib/server/functions/notifications/index.js b/app/lib/server/functions/notifications/index.js index 8b247c8810a3..d76bb70eb486 100644 --- a/app/lib/server/functions/notifications/index.js +++ b/app/lib/server/functions/notifications/index.js @@ -11,15 +11,17 @@ import { settings } from '../../../../settings'; * @param {object} message the message to be parsed */ export function parseMessageTextPerUser(messageText, message, receiver) { - if (!message.msg && message.attachments && message.attachments[0]) { - const lng = receiver.language || settings.get('Language') || 'en'; + 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 }); } if (message.msg && message.t === 'e2e') { - const lng = receiver.language || settings.get('Language') || 'en'; - return TAPi18n.__('Encrypted_message', { lng }); } diff --git a/app/push-notifications/server/lib/PushNotification.js b/app/push-notifications/server/lib/PushNotification.js index 4beb07bfe7f7..dc97c7876e6b 100644 --- a/app/push-notifications/server/lib/PushNotification.js +++ b/app/push-notifications/server/lib/PushNotification.js @@ -1,5 +1,4 @@ import { Meteor } from 'meteor/meteor'; -import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; import { Push } from '../../../push/server'; import { settings } from '../../../settings/server'; @@ -17,27 +16,23 @@ export class PushNotification { } getNotificationConfig({ rid, uid: userId, mid: messageId, roomName, username, message, payload, badge = 1, category, idOnly = false }) { - let title; - if (roomName && roomName !== '') { - title = `${ roomName }`; - message = `${ username }: ${ message }`; - } else { - title = `${ username }`; - } + const title = idOnly ? '' : roomName || username; + + // message is being redacted already by 'parseMessageTextPerUser' if idOnly is true + const text = !idOnly && roomName !== '' ? `${ username }: ${ message }` : message; const config = { from: 'push', badge, sound: 'default', priority: 10, - title: idOnly ? '' : title, - text: idOnly ? TAPi18n.__('Someone_sent_you_a_message') : message, + title, + text, payload: { host: Meteor.absoluteUrl(), - ...idOnly || { rid }, messageId, notificationType: idOnly ? 'message-id-only' : 'message', - ...idOnly || payload, + ...idOnly || { rid, ...payload }, }, userId, notId: this.getNotificationId(rid), diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index 3926771568ee..74b5eb672cac 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -3319,7 +3319,6 @@ "Snippet_name": "Snippet name", "Snippeted_a_message": "Created a snippet __snippetLink__", "Social_Network": "Social Network", - "Someone_sent_you_a_message": "Someone sent you a message", "Sorry_page_you_requested_does_not_exist_or_was_deleted": "Sorry, page you requested does not exist or was deleted!", "Sort": "Sort", "Sort_By": "Sort by", @@ -3925,6 +3924,7 @@ "You_can_use_an_emoji_as_avatar": "You can also use an emoji as an avatar.", "You_can_use_webhooks_to_easily_integrate_livechat_with_your_CRM": "You can use webhooks to easily integrate Omnichannel with your CRM.", "You_cant_leave_a_livechat_room_Please_use_the_close_button": "You can't leave a omnichannel room. Please, use the close button.", + "You_have_a_new_message": "You have a new message", "You_have_been_muted": "You have been muted and cannot speak in this room", "You_have_n_codes_remaining": "You have __number__ codes remaining.", "You_have_not_verified_your_email": "You have not verified your email.", diff --git a/packages/rocketchat-i18n/i18n/pt-BR.i18n.json b/packages/rocketchat-i18n/i18n/pt-BR.i18n.json index e24ac6175463..bdd58b9d87e3 100644 --- a/packages/rocketchat-i18n/i18n/pt-BR.i18n.json +++ b/packages/rocketchat-i18n/i18n/pt-BR.i18n.json @@ -3447,6 +3447,7 @@ "You_can_use_an_emoji_as_avatar": "Você também pode usar um emoji como um avatar.", "You_can_use_webhooks_to_easily_integrate_livechat_with_your_CRM": "Você pode usar webhooks para integrar facilmente o Omnichannel com seu CRM.", "You_cant_leave_a_livechat_room_Please_use_the_close_button": "Você não pode sair de uma sala de omnichannel. Por favor, use o botão de fechar sala.", + "You_have_a_new_message": "Nova mensagem", "You_have_been_muted": "Você foi silenciado e não pode falar nesta sala", "You_have_n_codes_remaining": "Você tem __number__ codes restantes.", "You_have_not_verified_your_email": "Você ainda não verificou o seu e-mail.",