Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Migrate REST API - registerPushToken to Typescript #3902

Merged
merged 3 commits into from
Mar 16, 2022
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
2 changes: 2 additions & 0 deletions app/definitions/rest/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { E2eEndpoints } from './e2e';
import { SubscriptionsEndpoints } from './subscriptions';
import { VideoConferenceEndpoints } from './videoConference';
import { CommandsEndpoints } from './commands';
import { PushTokenEndpoints } from './pushToken';
import { DirectoryEndpoint } from './directory';

export type Endpoints = ChannelsEndpoints &
Expand All @@ -38,4 +39,5 @@ export type Endpoints = ChannelsEndpoints &
SubscriptionsEndpoints &
VideoConferenceEndpoints &
CommandsEndpoints &
PushTokenEndpoints &
DirectoryEndpoint;
12 changes: 12 additions & 0 deletions app/definitions/rest/v1/pushToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export type PushTokenEndpoints = {
'push.token': {
POST: (params: { value: string; type: string; appName: string }) => {
result: {
id: string;
token: string;
appName: string;
userId: string;
};
Comment on lines +4 to +9
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I get this from the Rocket.Chat repo at /app/api/server/v1/push.js in line 39

};
};
};
21 changes: 0 additions & 21 deletions app/lib/rocketchat/rocketchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { setUser } from '../../actions/login';
import { shareSelectServer, shareSetSettings, shareSetUser } from '../../actions/share';
import defaultSettings from '../../constants/settings';
import { getDeviceToken } from '../../notifications/push';
import { getBundleId, isIOS } from '../../utils/deviceInfo';
import log from '../../utils/log';
import SSLPinning from '../../utils/sslPinning';
import database from '../database';
Expand Down Expand Up @@ -207,26 +206,6 @@ const RocketChat = {
},
removeServer,
clearCache,
registerPushToken() {
return new Promise(async resolve => {
const token = getDeviceToken();
if (token) {
const type = isIOS ? 'apn' : 'gcm';
const data = {
value: token,
type,
appName: getBundleId
};
try {
// RC 0.60.0
await this.post('push.token', data);
} catch (error) {
console.log(error);
}
}
return resolve();
});
},
loadMissedMessages,
loadMessagesForRoom,
loadSurroundingMessages,
Expand Down
21 changes: 21 additions & 0 deletions app/lib/rocketchat/services/restApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Encryption } from '../../encryption';
import { TParams } from '../../../definitions/ILivechatEditView';
import { store as reduxStore } from '../../auxStore';
import { getDeviceToken } from '../../../notifications/push';
import { getBundleId, isIOS } from '../../../utils/deviceInfo';
import { compareServerVersion } from '../../utils';
import roomTypeToApiType, { RoomTypes } from '../methods/roomTypeToApiType';
import sdk from './sdk';
Expand Down Expand Up @@ -813,6 +814,26 @@ export const editMessage = async (message: IMessage) => {
return sdk.post('chat.update', { roomId: rid, msgId: message.id, text: msg });
};

export const registerPushToken = () =>
new Promise<void>(async resolve => {
const token = getDeviceToken();
if (token) {
const type = isIOS ? 'apn' : 'gcm';
const data = {
value: token,
type,
appName: getBundleId
};
try {
// RC 0.60.0
await sdk.post('push.token', data);
} catch (error) {
console.log(error);
}
}
return resolve();
});

export const removePushToken = (): Promise<boolean | void> => {
const token = getDeviceToken();
if (token) {
Expand Down