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
5 changes: 5 additions & 0 deletions .changeset/sweet-timers-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Switches from GCM (unsupported) to FCM as the default push notification service for custom mobile apps
103 changes: 0 additions & 103 deletions apps/meteor/app/push/server/gcm.ts

This file was deleted.

53 changes: 18 additions & 35 deletions apps/meteor/app/push/server/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { Meteor } from 'meteor/meteor';
import { initAPN, sendAPN } from './apn';
import type { PushOptions, PendingPushNotification } from './definition';
import { sendFCM } from './fcm';
import { sendGCM } from './gcm';
import { logger } from './logger';
import { settings } from '../../settings/server';

Expand Down Expand Up @@ -197,40 +196,24 @@ class PushClass {
} else if ('gcm' in app.token && app.token.gcm) {
countGcm.push(app._id);

// Send to GCM
// We do support multiple here - so we should construct an array
// and send it bulk - Investigate limit count of id's
// TODO: Remove this after the legacy provider is removed
const useLegacyProvider = settings.get<boolean>('Push_UseLegacy');

if (!useLegacyProvider) {
// override this.options.gcm.apiKey with the oauth2 token
const { projectId, token } = await this.getNativeNotificationAuthorizationCredentials();
const sendGCMOptions = {
...this.options,
gcm: {
...this.options.gcm,
apiKey: token,
projectNumber: projectId,
},
};

sendFCM({
userTokens: app.token.gcm,
notification,
_replaceToken: this.replaceToken,
_removeToken: this.removeToken,
options: sendGCMOptions as RequiredField<PushOptions, 'gcm'>,
});
} else if (this.options.gcm?.apiKey) {
sendGCM({
userTokens: app.token.gcm,
notification,
_replaceToken: this.replaceToken,
_removeToken: this.removeToken,
options: this.options as RequiredField<PushOptions, 'gcm'>,
});
}
// override this.options.gcm.apiKey with the oauth2 token
const { projectId, token } = await this.getNativeNotificationAuthorizationCredentials();
const sendGCMOptions = {
...this.options,
gcm: {
...this.options.gcm,
apiKey: token,
projectNumber: projectId,
},
};

sendFCM({
userTokens: app.token.gcm,
notification,
_replaceToken: this.replaceToken,
_removeToken: this.removeToken,
options: sendGCMOptions as RequiredField<PushOptions, 'gcm'>,
});
} else {
throw new Error('send got a faulty query');
}
Expand Down
2 changes: 0 additions & 2 deletions apps/meteor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@
"@types/mkdirp": "^1.0.2",
"@types/mocha": "github:whitecolor/mocha-types",
"@types/node": "~20.17.8",
"@types/node-gcm": "^1.0.5",
"@types/node-rsa": "^1.1.4",
"@types/nodemailer": "^6.4.16",
"@types/oauth2-server": "^3.0.18",
Expand Down Expand Up @@ -390,7 +389,6 @@
"nats": "^2.28.2",
"node-dogstatsd": "^0.0.7",
"node-fetch": "2.7.0",
"node-gcm": "1.1.4",
"node-rsa": "^1.1.1",
"nodemailer": "^6.9.16",
"object-path": "^0.11.8",
Expand Down
5 changes: 3 additions & 2 deletions apps/meteor/server/configuration/pushNotification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ export async function configurePushNotifications(settings: ICachedSettings): Pro
}
| undefined;

// TODO: this part of the code should be refactored as the deprecated GCM methods are no longer being used and FCM is preferred.
if (!gateways) {
gcm = {
apiKey: settings.get('Push_gcm_api_key'),
projectNumber: settings.get('Push_gcm_project_number'),
apiKey: 'TO_BE_REFACTORED',
projectNumber: 'TO_BE_REFACTORED',
};

apn = {
Expand Down
5 changes: 4 additions & 1 deletion apps/meteor/server/settings/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ export const createPushSettings = () =>
alert: 'Push_Setting_Requires_Restart_Alert',
});

// TODO: Push_UseLegacy should be removed in 8.0.0, as well as Push_gcm_project_number and Push_gcm_api_key
await this.add('Push_UseLegacy', false, {
type: 'boolean',
hidden: true,
alert: 'Push_Setting_Legacy_Warning',
});

Expand Down Expand Up @@ -109,6 +111,7 @@ export const createPushSettings = () =>
});
await this.add('Push_gcm_api_key', '', {
type: 'string',
hidden: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both this setting and Push_gcm_project_number are still being used at:

gcm = {
apiKey: settings.get('Push_gcm_api_key'),
projectNumber: settings.get('Push_gcm_project_number'),
};

I suppose that part of the code should be refactored since this will be always empty from now on.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gustrb seems like we're no longer using this part of the code since we don't use these settings. Should the gcm config be removed? Would like your insight on this one since you worked on the push notifications before

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, it looks like they are not being used and could be removed, but since we check for the key's existence to see if we should call fcm or apn, I think we could keep it here (maybe empty object?) and we can remove it later on a larger refactoring.
I think this code can be improved by a lot, but I don't think we should be doing it in this PR (since it is a chore and it is supposed to just remove the dependency)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a TODO comment and removed settings.get, but feel free to suggest a different way of doing it. @sampaiodiego @Gustrb

enableQuery: [
{
_id: 'Push_UseLegacy',
Expand All @@ -132,7 +135,7 @@ export const createPushSettings = () =>

return this.add('Push_gcm_project_number', '', {
type: 'string',
public: true,
hidden: true,
enableQuery: [
{
_id: 'Push_UseLegacy',
Expand Down
4 changes: 2 additions & 2 deletions packages/i18n/src/locales/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -5747,7 +5747,7 @@
"Unmute_microphone": "Unmute Microphone",
"Update": "Update",
"Update_EnableChecker": "Enable the Update Checker",
"Update_EnableChecker_Description": "Checks automatically for new updates / important messages from the Rocket.Chat developers and receives notifications when available. The notification appears once per new version as a clickable banner and as a message from the Rocket.Cat bot, both visible only for administrators.",
"Update_EnableChecker_Description": "Checks automatically for new updates / important messages from the Rocket.Chat developers and receives notifications when available. The notification appears once per new version as a clickable banner and as a message from the Rocket.Cat bot, both visible only for administrators.",
"Update_every": "Update every",
"Update_LatestAvailableVersion": "Update Latest Available Version",
"Update_to_version": "Update to {{version}}",
Expand Down Expand Up @@ -6763,7 +6763,7 @@
"Show_channels_description": "Show team channels in second sidebar",
"Show_discussions_description": "Show team discussions in second sidebar",
"Block_channel": "Block channel",
"Block_channel_description": "Are you sure you want to block this channel? Messages from this conversation will no longer reach this workspace.",
"Block_channel_description": "Are you sure you want to block this channel? Messages from this conversation will no longer reach this workspace.",
"Contact_unblocked": "Contact unblocked",
"Contact_blocked": "Contact blocked",
"Contact_has_been_updated": "Contact has been updated",
Expand Down
2 changes: 1 addition & 1 deletion packages/i18n/src/locales/se.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -5581,7 +5581,7 @@
"Unmute_microphone": "Unmute Microphone",
"Update": "Update",
"Update_EnableChecker": "Enable the Update Checker",
"Update_EnableChecker_Description": "Checks automatically for new updates / important messages from the Rocket.Chat developers and receives notifications when available. The notification appears once per new version as a clickable banner and as a message from the Rocket.Cat bot, both visible only for administrators.",
"Update_EnableChecker_Description": "Checks automatically for new updates / important messages from the Rocket.Chat developers and receives notifications when available. The notification appears once per new version as a clickable banner and as a message from the Rocket.Cat bot, both visible only for administrators.",
"Update_every": "Update every",
"Update_LatestAvailableVersion": "Update Latest Available Version",
"Update_to_version": "Update to {{version}}",
Expand Down
33 changes: 1 addition & 32 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8609,7 +8609,6 @@ __metadata:
"@types/mkdirp": "npm:^1.0.2"
"@types/mocha": "github:whitecolor/mocha-types"
"@types/node": "npm:~20.17.8"
"@types/node-gcm": "npm:^1.0.5"
"@types/node-rsa": "npm:^1.1.4"
"@types/nodemailer": "npm:^6.4.16"
"@types/oauth2-server": "npm:^3.0.18"
Expand Down Expand Up @@ -8759,7 +8758,6 @@ __metadata:
nats: "npm:^2.28.2"
node-dogstatsd: "npm:^0.0.7"
node-fetch: "npm:2.7.0"
node-gcm: "npm:1.1.4"
node-rsa: "npm:^1.1.1"
nodemailer: "npm:^6.9.16"
nyc: "npm:^17.1.0"
Expand Down Expand Up @@ -12322,13 +12320,6 @@ __metadata:
languageName: node
linkType: hard

"@types/node-gcm@npm:^1.0.5":
version: 1.0.5
resolution: "@types/node-gcm@npm:1.0.5"
checksum: 10/5448aa9de99b23700a2cc243483ed08bffd988a91d7431ed193dfbb55fc5c087c58310f728992a83f0e653b9edf9220434b62a0fabc5c7f417067ca805c1f92c
languageName: node
linkType: hard

"@types/node-rsa@npm:^1.1.4":
version: 1.1.4
resolution: "@types/node-rsa@npm:1.1.4"
Expand Down Expand Up @@ -14955,17 +14946,6 @@ __metadata:
languageName: node
linkType: hard

"axios@npm:~1.6.8":
version: 1.6.8
resolution: "axios@npm:1.6.8"
dependencies:
follow-redirects: "npm:^1.15.6"
form-data: "npm:^4.0.0"
proxy-from-env: "npm:^1.1.0"
checksum: 10/3f9a79eaf1d159544fca9576261ff867cbbff64ed30017848e4210e49f3b01e97cf416390150e6fdf6633f336cd43dc1151f890bbd09c3c01ad60bb0891eee63
languageName: node
linkType: hard

"axobject-query@npm:^4.1.0":
version: 4.1.0
resolution: "axobject-query@npm:4.1.0"
Expand Down Expand Up @@ -18170,7 +18150,7 @@ __metadata:
languageName: node
linkType: hard

"debug@npm:^3.1.0, debug@npm:^3.2.7":
"debug@npm:^3.2.7":
version: 3.2.7
resolution: "debug@npm:3.2.7"
dependencies:
Expand Down Expand Up @@ -27904,17 +27884,6 @@ __metadata:
languageName: node
linkType: hard

"node-gcm@npm:1.1.4":
version: 1.1.4
resolution: "node-gcm@npm:1.1.4"
dependencies:
axios: "npm:~1.6.8"
debug: "npm:^3.1.0"
lodash: "npm:^4.17.21"
checksum: 10/4654838afd5ade1c5943bada8bc6208c4d2c27dd43c99efd68bb06ae8880cdc25bdb2ab457e381b85c2240daeb7b35fbd85351cccbcb0afe5b3f9d92c8a50572
languageName: node
linkType: hard

"node-gyp-build@npm:^4.8.0":
version: 4.8.2
resolution: "node-gyp-build@npm:4.8.2"
Expand Down
Loading