snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
import PushNotification from './lib/PushNotification';
|
||||
|
||||
export { PushNotification };
|
||||
@@ -0,0 +1,156 @@
|
||||
import type { IMessage, IPushNotificationConfig, IRoom, IUser } from '@rocket.chat/core-typings';
|
||||
import { Users } from '@rocket.chat/models';
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
|
||||
import { settings } from '../../../../settings';
|
||||
import { callbacks } from '../../../callbacks';
|
||||
import { RocketChatAssets } from '../../../media/assets';
|
||||
import { metrics } from '../../../metrics';
|
||||
import { replaceMentionedUsernamesWithFullNames, parseMessageTextPerUser } from '../../message';
|
||||
import { getPushData } from '../../message/mobile';
|
||||
import { Push } from '../../push';
|
||||
|
||||
type PushNotificationData = {
|
||||
rid: string;
|
||||
uid: string;
|
||||
mid: string;
|
||||
roomName: string;
|
||||
username: string;
|
||||
message: string;
|
||||
payload: Record<string, any>;
|
||||
badge: number;
|
||||
category: string;
|
||||
};
|
||||
|
||||
type GetNotificationConfigParam = PushNotificationData & {
|
||||
idOnly: boolean;
|
||||
};
|
||||
|
||||
type NotificationPayload = {
|
||||
message: IMessage;
|
||||
notification: IPushNotificationConfig;
|
||||
};
|
||||
|
||||
function hash(str: string): number {
|
||||
let hash = 0;
|
||||
let i = str.length;
|
||||
|
||||
while (i) {
|
||||
hash = (hash << 5) - hash + str.charCodeAt(--i);
|
||||
hash &= hash; // Convert to 32bit integer
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
class PushNotification {
|
||||
getNotificationId(roomId: string): number {
|
||||
const serverId = settings.get('uniqueID');
|
||||
return hash(`${serverId}|${roomId}`); // hash
|
||||
}
|
||||
|
||||
private getNotificationConfig({
|
||||
rid,
|
||||
uid: userId,
|
||||
mid: messageId,
|
||||
roomName,
|
||||
username,
|
||||
message,
|
||||
payload,
|
||||
badge = 1,
|
||||
category,
|
||||
idOnly = false,
|
||||
}: GetNotificationConfigParam): IPushNotificationConfig {
|
||||
const title = idOnly ? '' : roomName || username;
|
||||
|
||||
// message is being redacted already by 'getPushData' if idOnly is true
|
||||
const text = !idOnly && roomName !== '' ? `${username}: ${message}` : message;
|
||||
|
||||
return {
|
||||
from: 'push',
|
||||
badge,
|
||||
sound: 'default',
|
||||
priority: 10,
|
||||
title,
|
||||
text,
|
||||
payload: {
|
||||
host: Meteor.absoluteUrl(),
|
||||
messageId,
|
||||
notificationType: idOnly ? 'message-id-only' : 'message',
|
||||
...(!idOnly && { rid, ...payload }),
|
||||
},
|
||||
userId,
|
||||
notId: this.getNotificationId(rid),
|
||||
gcm: {
|
||||
style: 'inbox',
|
||||
image: RocketChatAssets.getURL('Assets_favicon_192'),
|
||||
},
|
||||
...(category !== '' ? { apn: { category } } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
async send({ rid, uid, mid, roomName, username, message, payload, badge = 1, category }: PushNotificationData): Promise<void> {
|
||||
const idOnly = settings.get<boolean>('Push_request_content_from_server');
|
||||
const config = this.getNotificationConfig({
|
||||
rid,
|
||||
uid,
|
||||
mid,
|
||||
roomName,
|
||||
username,
|
||||
message,
|
||||
payload,
|
||||
badge,
|
||||
category,
|
||||
idOnly,
|
||||
});
|
||||
|
||||
await Push.send(config);
|
||||
|
||||
metrics.notificationsSent.inc({ notification_type: 'mobile' });
|
||||
metrics.notificationsSentTotal.inc({ notification_type: 'mobile' });
|
||||
}
|
||||
|
||||
async getNotificationForMessageId({
|
||||
receiver,
|
||||
message,
|
||||
room,
|
||||
}: {
|
||||
receiver: IUser;
|
||||
message: IMessage;
|
||||
room: IRoom;
|
||||
}): Promise<NotificationPayload> {
|
||||
const sender = await Users.findOneById(message.u._id, { projection: { username: 1, name: 1 } });
|
||||
if (!sender) {
|
||||
throw new Error('Message sender not found');
|
||||
}
|
||||
|
||||
let notificationMessage = await callbacks.run('beforeSendMessageNotifications', message.msg);
|
||||
if (message.mentions && Object.keys(message.mentions).length > 0 && settings.get('UI_Use_Real_Name')) {
|
||||
notificationMessage = replaceMentionedUsernamesWithFullNames(message.msg, message.mentions);
|
||||
}
|
||||
notificationMessage = await parseMessageTextPerUser(notificationMessage, message, receiver);
|
||||
|
||||
const pushData = await getPushData({
|
||||
room,
|
||||
message,
|
||||
userId: receiver._id,
|
||||
receiver,
|
||||
senderUsername: sender.username,
|
||||
senderName: sender.name,
|
||||
notificationMessage,
|
||||
shouldOmitMessage: false,
|
||||
});
|
||||
|
||||
return {
|
||||
message,
|
||||
notification: this.getNotificationConfig({
|
||||
...pushData,
|
||||
rid: message.rid,
|
||||
uid: message.u._id,
|
||||
mid: message._id,
|
||||
idOnly: false,
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default new PushNotification();
|
||||
Reference in New Issue
Block a user