From e792f2a49b5956f34ae8af81a1b59e37fa86e131 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto <47038980+reinaldonetof@users.noreply.github.com> Date: Wed, 16 Mar 2022 17:04:16 -0300 Subject: [PATCH] Chore: Migrate REST API - registerPushToken to Typescript (#3902) --- app/definitions/rest/v1/index.ts | 2 ++ app/definitions/rest/v1/pushToken.ts | 12 ++++++++++++ app/lib/rocketchat/rocketchat.js | 21 --------------------- app/lib/rocketchat/services/restApi.ts | 21 +++++++++++++++++++++ 4 files changed, 35 insertions(+), 21 deletions(-) create mode 100644 app/definitions/rest/v1/pushToken.ts diff --git a/app/definitions/rest/v1/index.ts b/app/definitions/rest/v1/index.ts index a594a966..4289f55c 100644 --- a/app/definitions/rest/v1/index.ts +++ b/app/definitions/rest/v1/index.ts @@ -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; diff --git a/app/definitions/rest/v1/pushToken.ts b/app/definitions/rest/v1/pushToken.ts new file mode 100644 index 00000000..99726eb2 --- /dev/null +++ b/app/definitions/rest/v1/pushToken.ts @@ -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; + }; + }; + }; +}; diff --git a/app/lib/rocketchat/rocketchat.js b/app/lib/rocketchat/rocketchat.js index 788e93a0..5968d5d4 100644 --- a/app/lib/rocketchat/rocketchat.js +++ b/app/lib/rocketchat/rocketchat.js @@ -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, diff --git a/app/lib/rocketchat/services/restApi.ts b/app/lib/rocketchat/services/restApi.ts index 70351569..7e36b7b3 100644 --- a/app/lib/rocketchat/services/restApi.ts +++ b/app/lib/rocketchat/services/restApi.ts @@ -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(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 => { const token = getDeviceToken(); if (token) {