Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/selfish-students-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rocket.chat/meteor': patch
---

Fixes missing message text in desktop notifications by ensuring the "Show Message in Notification" setting only affects mobile push notifications.

1 change: 0 additions & 1 deletion apps/meteor/.mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,5 @@ module.exports = {
'tests/unit/server/**/*.spec.ts',
'app/api/server/lib/**/*.spec.ts',
'app/file-upload/server/**/*.spec.ts',
'app/lib/server/functions/notifications/**/*.spec.ts',
],
};
231 changes: 0 additions & 231 deletions apps/meteor/app/lib/server/functions/notifications/desktop.spec.ts

This file was deleted.

9 changes: 2 additions & 7 deletions apps/meteor/app/lib/server/functions/notifications/desktop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type { IMessage, IRoom, IUser, AtLeast } from '@rocket.chat/core-typings'
import { roomCoordinator } from '../../../../../server/lib/rooms/roomCoordinator';
import { metrics } from '../../../../metrics/server';
import { settings } from '../../../../settings/server';
import type { SubscriptionAggregation } from '../../lib/sendNotificationsOnMessage';

/**
* Send notification to user
Expand All @@ -23,21 +22,17 @@ export async function notifyDesktopUser({
room,
duration,
notificationMessage,
receiver,
}: {
userId: string;
user: AtLeast<IUser, '_id' | 'name' | 'username'>;
message: IMessage | Pick<IMessage, 'u'>;
room: IRoom;
duration?: number;
notificationMessage: string;
receiver?: SubscriptionAggregation['receiver'][number];
}): Promise<void> {
const { title, text, name } = await roomCoordinator
.getRoomDirectives(room.t)
.getNotificationDetails(room, user, notificationMessage, userId, receiver?.language);

const showPushMessage = settings.get<boolean>('Push_show_message');
.getNotificationDetails(room, user, notificationMessage, userId);

const payload = {
title: title || '',
Expand All @@ -56,7 +51,7 @@ export async function notifyDesktopUser({
sender: message.u,
type: room.t,
message: {
msg: 'msg' in message && showPushMessage ? message.msg : '',
msg: 'msg' in message ? message.msg : '',
...('t' in message && {
t: message.t,
}),
Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { getEmailData, shouldNotifyEmail } from '../functions/notifications/emai
import { messageContainsHighlight } from '../functions/notifications/messageContainsHighlight';
import { getPushData, shouldNotifyMobile } from '../functions/notifications/mobile';

export type SubscriptionAggregation = {
type SubscriptionAggregation = {
receiver: [Pick<IUser, 'active' | 'emails' | 'language' | 'status' | 'statusConnection' | 'username' | 'settings'> | null];
} & Pick<
ISubscription,
Expand Down Expand Up @@ -134,7 +134,6 @@ export const sendNotification = async ({
user: sender,
message,
room,
receiver,
});
}

Expand Down
20 changes: 11 additions & 9 deletions apps/meteor/client/hooks/notification/useNotification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const useNotification = () => {
return;
}

const { rid, name, _id: msgId } = notification.payload;
const { rid, name: roomName, _id: msgId } = notification.payload;
if (!rid) {
return;
}
Expand All @@ -35,7 +35,7 @@ export const useNotification = () => {
const n = new Notification(notification.title, {
icon: notification.icon || getUserAvatarURL(notification.payload.sender?.username as string),
body: stripTags(message?.msg),
tag: notification.payload._id,
tag: msgId,
canReply: true,
silent: true,
requireInteraction,
Expand Down Expand Up @@ -63,7 +63,9 @@ export const useNotification = () => {
n.close();
window.focus();

const jump = msgId && { jump: msgId };
if (!msgId || !rid || !roomName) {
return;
}

switch (notification.payload?.type) {
case 'd':
Expand All @@ -76,32 +78,32 @@ export const useNotification = () => {
context: notification.payload.tmid,
}),
},
search: { ...router.getSearchParameters(), ...jump },
search: { ...router.getSearchParameters(), jump: msgId },
});
break;
case 'c':
return router.navigate({
pattern: '/channel/:name/:tab?/:context?',
params: {
name: name || rid,
name: roomName,
...(notification.payload.tmid && {
tab: 'thread',
context: notification.payload.tmid,
}),
},
search: { ...router.getSearchParameters(), ...jump },
search: { ...router.getSearchParameters(), jump: msgId },
});
case 'p':
return router.navigate({
pattern: '/group/:name/:tab?/:context?',
params: {
name: name || rid,
name: roomName,
...(notification.payload.tmid && {
tab: 'thread',
context: notification.payload.tmid,
}),
},
search: { ...router.getSearchParameters(), ...jump },
search: { ...router.getSearchParameters(), jump: msgId },
});
case 'l':
return router.navigate({
Expand All @@ -110,7 +112,7 @@ export const useNotification = () => {
id: rid,
tab: 'room-info',
},
search: { ...router.getSearchParameters(), ...jump },
search: { ...router.getSearchParameters(), jump: msgId },
});
}
};
Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/definition/IRoomTypeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ export interface IRoomTypeServerDirectives {
sender: AtLeast<IUser, '_id' | 'name' | 'username'>,
notificationMessage: string,
userId: string,
language?: string,
) => Promise<{ title?: string; text: string; name?: string }>;
) => Promise<{ title: string | undefined; text: string; name: string | undefined }>;
getMsgSender: (message: IMessage) => Promise<IUser | null>;
includeInRoomSearch: () => boolean;
getReadReceiptsExtraData: (message: IMessage) => Partial<ReadReceipt>;
Expand Down
Loading
Loading