Unverified Commit e792f2a4 authored by Reinaldo Neto's avatar Reinaldo Neto Committed by GitHub
Browse files

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

parent 8efba393
......@@ -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;
export type PushTokenEndpoints = {
'push.token': {
POST: (params: { value: string; type: string; appName: string }) => {
result: {
id: string;
token: string;
appName: string;
userId: string;
};
};
};
};
......@@ -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,
......
......@@ -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) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment