diff --git a/app/definitions/rest/v1/index.ts b/app/definitions/rest/v1/index.ts index a594a966d..4289f55c6 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 000000000..99726eb2b --- /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 788e93a0c..5968d5d45 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 703515698..7e36b7b31 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) {