Skip to content

Commit

Permalink
Merge pull request #19053 from hoangzinh/df/16583
Browse files Browse the repository at this point in the history
Show Room name in Desktop notification title if message is come from a chat room
  • Loading branch information
Julesssss authored May 18, 2023
2 parents 2b4603c + 33e560c commit 3b49ca5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
22 changes: 19 additions & 3 deletions src/libs/Notification/LocalNotification/BrowserNotifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import _ from 'underscore';
import focusApp from './focusApp';
import * as AppUpdate from '../../actions/AppUpdate';
import EXPENSIFY_ICON_URL from '../../../../assets/images/expensify-logo-round-clearspace.png';
import * as ReportUtils from '../../ReportUtils';

const DEFAULT_DELAY = 4000;

Expand Down Expand Up @@ -92,20 +93,35 @@ export default {
* Create a report comment notification
*
* @param {Object} params
* @param {Object} params.report
* @param {Object} params.reportAction
* @param {Function} params.onClick
* @param {Boolean} usesIcon true if notification uses right circular icon
*/
pushReportCommentNotification({reportAction, onClick}, usesIcon = false) {
pushReportCommentNotification({report, reportAction, onClick}, usesIcon = false) {
let title;
let body;

const isChatRoom = ReportUtils.isChatRoom(report);

const {person, message} = reportAction;
const plainTextPerson = _.map(person, (f) => f.text).join();

// Specifically target the comment part of the message
const plainTextMessage = (_.find(message, (f) => f.type === 'COMMENT') || {}).text;

if (isChatRoom) {
const roomName = _.get(report, 'displayName', '');
title = roomName;
body = `${plainTextPerson}: ${plainTextMessage}`;
} else {
title = plainTextPerson;
body = plainTextMessage;
}

push({
title: plainTextPerson,
body: plainTextMessage,
title,
body,
delay: 0,
onClick,
icon: usesIcon ? EXPENSIFY_ICON_URL : '',
Expand Down
4 changes: 2 additions & 2 deletions src/libs/Notification/LocalNotification/index.desktop.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BrowserNotifications from './BrowserNotifications';

function showCommentNotification({reportAction, onClick}) {
BrowserNotifications.pushReportCommentNotification({reportAction, onClick});
function showCommentNotification({report, reportAction, onClick}) {
BrowserNotifications.pushReportCommentNotification({report, reportAction, onClick});
}

function showUpdateAvailableNotification() {
Expand Down
4 changes: 2 additions & 2 deletions src/libs/Notification/LocalNotification/index.website.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BrowserNotifications from './BrowserNotifications';

function showCommentNotification({reportAction, onClick}) {
BrowserNotifications.pushReportCommentNotification({reportAction, onClick}, true);
function showCommentNotification({report, reportAction, onClick}) {
BrowserNotifications.pushReportCommentNotification({report, reportAction, onClick}, true);
}

function showUpdateAvailableNotification() {
Expand Down
1 change: 1 addition & 0 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,7 @@ function showReportActionNotification(reportID, action) {

Log.info('[LocalNotification] Creating notification');
LocalNotification.showCommentNotification({
report: allReports[reportID],
reportAction: action,
onClick: () => {
// Navigate to this report onClick
Expand Down

0 comments on commit 3b49ca5

Please sign in to comment.