Chore: Migrate REST API - registerPushToken to Typescript (#3902)

This commit is contained in:
Reinaldo Neto 2022-03-16 17:04:16 -03:00 committed by GitHub
parent 8efba39370
commit e792f2a49b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 21 deletions

View File

@ -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 &
@ -38,4 +39,5 @@ export type Endpoints = ChannelsEndpoints &
SubscriptionsEndpoints &
VideoConferenceEndpoints &
CommandsEndpoints &
PushTokenEndpoints &
DirectoryEndpoint;

View File

@ -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;
};
};
};
};

View File

@ -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';
@ -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,

View File

@ -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';
@ -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) {