From ff95961a16de67ea453b02419300fc85b9c3e6c2 Mon Sep 17 00:00:00 2001 From: Djorkaeff Alexandre Date: Mon, 11 May 2020 13:48:44 -0300 Subject: [PATCH 1/4] [WIP] Use rest instead methodCall --- app/lib/rocketchat.js | 20 ++++++++------------ app/views/SetUsernameView.js | 2 +- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index 0366040726a..ee3f06283c8 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -319,8 +319,9 @@ const RocketChat = { reduxStore.dispatch(shareSetUser(null)); }, - updateJitsiTimeout(rid) { - return this.methodCall('jitsi:updateTimeout', rid); + updateJitsiTimeout(roomId) { + // RC 0.74.0 + return this.post('jitsi.updateTimeout', { roomId }); }, register(credentials) { @@ -328,11 +329,6 @@ const RocketChat = { return this.post('users.register', credentials, false); }, - setUsername(username) { - // RC 0.51.0 - return this.methodCall('setUsername', username); - }, - forgotPassword(email) { // RC 0.64.0 return this.post('users.forgotPassword', { email }, false); @@ -922,9 +918,9 @@ const RocketChat = { // RC 0.62.2 return this.post('users.updateOwnBasicInfo', { data, customFields }); }, - saveUserPreferences(params) { - // RC 0.51.0 - return this.methodCall('saveUserPreferences', params); + saveUserPreferences(data) { + // RC 0.62.0 + return this.post('users.setPreferences', { data }); }, saveNotificationSettings(roomId, notifications) { // RC 0.63.0 @@ -937,8 +933,8 @@ const RocketChat = { return this.methodCall('addUsersToRoom', { rid, users }); }, getSingleMessage(msgId) { - // RC 0.57.0 - return this.methodCall('getSingleMessage', msgId); + // RC 0.47.0 + return this.sdk.get('chat.getMessage', { msgId }); }, async hasPermission(permissions, rid) { const db = database.active; diff --git a/app/views/SetUsernameView.js b/app/views/SetUsernameView.js index d6fbb5e3da6..16e111d73f5 100644 --- a/app/views/SetUsernameView.js +++ b/app/views/SetUsernameView.js @@ -93,7 +93,7 @@ class SetUsernameView extends React.Component { this.setState({ saving: true }); try { - await RocketChat.setUsername(username); + await RocketChat.saveUserProfile({ username }); await loginRequest({ resume: token }); } catch (e) { showErrorAlert(e.message, I18n.t('Oops')); From 76105f6cfb1576823c010e25282fbb8c3b7c575e Mon Sep 17 00:00:00 2001 From: Djorkaeff Alexandre Date: Mon, 11 May 2020 14:45:23 -0300 Subject: [PATCH 2/4] [WIP] Some method calls using wrapper --- app/lib/rocketchat.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index ee3f06283c8..c051fa341ae 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -591,7 +591,7 @@ const RocketChat = { // TODO: join code // RC 0.48.0 if (type === 'p') { - return this.methodCall('joinRoom', roomId); + return this.methodCallWrapper('joinRoom', roomId); } return this.post('channels.join', { roomId }); }, @@ -730,11 +730,18 @@ const RocketChat = { }, getRoomMembers(rid, allUsers, skip = 0, limit = 10) { // RC 0.42.0 - return this.methodCall('getUsersOfRoom', rid, allUsers, { skip, limit }); + return this.methodCallWrapper('getUsersOfRoom', rid, allUsers, { skip, limit }); }, + + async methodCallWrapper(method, ...params) { + const data = await this.post(`method.call/${ method }`, { message: JSON.stringify({ method, params }) }); + const { result } = JSON.parse(data.message); + return result; + }, + getUserRoles() { // RC 0.27.0 - return this.methodCall('getUserRoles'); + return this.methodCallWrapper('getUserRoles'); }, getRoomCounters(roomId, t) { // RC 0.65.0 @@ -831,10 +838,10 @@ const RocketChat = { toggleBlockUser(rid, blocked, block) { if (block) { // RC 0.49.0 - return this.methodCall('blockUser', { rid, blocked }); + return this.methodCallWrapper('blockUser', { rid, blocked }); } // RC 0.49.0 - return this.methodCall('unblockUser', { rid, blocked }); + return this.methodCallWrapper('unblockUser', { rid, blocked }); }, leaveRoom(roomId, t) { // RC 0.48.0 @@ -847,10 +854,10 @@ const RocketChat = { toggleMuteUserInRoom(rid, username, mute) { if (mute) { // RC 0.51.0 - return this.methodCall('muteUserInRoom', { rid, username }); + return this.methodCallWrapper('muteUserInRoom', { rid, username }); } // RC 0.51.0 - return this.methodCall('unmuteUserInRoom', { rid, username }); + return this.methodCallWrapper('unmuteUserInRoom', { rid, username }); }, toggleArchiveRoom(roomId, t, archive) { if (archive) { @@ -865,7 +872,7 @@ const RocketChat = { }, saveRoomSettings(rid, params) { // RC 0.55.0 - return this.methodCall('saveRoomSettings', rid, params); + return this.methodCallWrapper('saveRoomSettings', rid, params); }, post(...args) { return new Promise(async(resolve, reject) => { @@ -930,7 +937,7 @@ const RocketChat = { let { users } = reduxStore.getState().selectedUsers; users = users.map(u => u.name); // RC 0.51.0 - return this.methodCall('addUsersToRoom', { rid, users }); + return this.methodCallWrapper('addUsersToRoom', { rid, users }); }, getSingleMessage(msgId) { // RC 0.47.0 From 2974a4b149f03cac011f0afd74e471c22e8b2255 Mon Sep 17 00:00:00 2001 From: Djorkaeff Alexandre Date: Mon, 11 May 2020 14:54:53 -0300 Subject: [PATCH 3/4] [WIP] Wrap all necessary methodCalls --- app/constants/settings.js | 3 +++ app/lib/rocketchat.js | 36 ++++++++++++++++++++---------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/app/constants/settings.js b/app/constants/settings.js index ba63d4cab32..d8c15ef36bb 100644 --- a/app/constants/settings.js +++ b/app/constants/settings.js @@ -50,6 +50,9 @@ export default { Accounts_ManuallyApproveNewUsers: { type: 'valueAsBoolean' }, + API_Use_REST_For_DDP_Calls: { + type: 'valueAsBoolean' + }, CROWD_Enable: { type: 'valueAsBoolean' }, diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index c051fa341ae..1360c932813 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -77,7 +77,7 @@ const RocketChat = { name, users, type, readOnly, broadcast }) { // RC 0.51.0 - return this.methodCall(type ? 'createPrivateGroup' : 'createChannel', name, users, readOnly, {}, { broadcast }); + return this.methodCallWrapper(type ? 'createPrivateGroup' : 'createChannel', name, users, readOnly, {}, { broadcast }); }, async getUserToken() { try { @@ -562,7 +562,7 @@ const RocketChat = { spotlight(search, usernames, type) { // RC 0.51.0 - return this.methodCall('spotlight', search, usernames, type); + return this.methodCallWrapper('spotlight', search, usernames, type); }, createDirectMessage(username) { @@ -734,9 +734,13 @@ const RocketChat = { }, async methodCallWrapper(method, ...params) { - const data = await this.post(`method.call/${ method }`, { message: JSON.stringify({ method, params }) }); - const { result } = JSON.parse(data.message); - return result; + const { API_Use_REST_For_DDP_Calls } = reduxStore.getState().settings; + if (API_Use_REST_For_DDP_Calls) { + const data = await this.post(`method.call/${ method }`, { message: JSON.stringify({ method, params }) }); + const { result } = JSON.parse(data.message); + return result; + } + return this.methodCall(method, ...params); }, getUserRoles() { @@ -766,19 +770,19 @@ const RocketChat = { }, closeLivechat(rid, comment) { // RC 0.29.0 - return this.methodCall('livechat:closeRoom', rid, comment, { clientAction: true }); + return this.methodCallWrapper('livechat:closeRoom', rid, comment, { clientAction: true }); }, editLivechat(userData, roomData) { // RC 0.55.0 - return this.methodCall('livechat:saveInfo', userData, roomData); + return this.methodCallWrapper('livechat:saveInfo', userData, roomData); }, returnLivechat(rid) { // RC 0.72.0 - return this.methodCall('livechat:returnAsInquiry', rid); + return this.methodCallWrapper('livechat:returnAsInquiry', rid); }, forwardLivechat(transferData) { // RC 0.36.0 - return this.methodCall('livechat:transfer', transferData); + return this.methodCallWrapper('livechat:transfer', transferData); }, getPagesLivechat(rid, offset) { // RC 2.3.0 @@ -798,11 +802,11 @@ const RocketChat = { }, getRoutingConfig() { // RC 2.0.0 - return this.methodCall('livechat:getRoutingConfig'); + return this.methodCallWrapper('livechat:getRoutingConfig'); }, getTagsList() { // RC 2.0.0 - return this.methodCall('livechat:getTagsList'); + return this.methodCallWrapper('livechat:getTagsList'); }, getAgentDepartments(uid) { // RC 2.4.0 @@ -986,7 +990,7 @@ const RocketChat = { }, getAvatarSuggestion() { // RC 0.51.0 - return this.methodCall('getAvatarSuggestion'); + return this.methodCallWrapper('getAvatarSuggestion'); }, resetAvatar(userId) { // RC 0.55.0 @@ -994,7 +998,7 @@ const RocketChat = { }, setAvatarFromService({ data, contentType = '', service = null }) { // RC 0.51.0 - return this.methodCall('setAvatarFromService', data, contentType, service); + return this.methodCallWrapper('setAvatarFromService', data, contentType, service); }, async getAllowCrashReport() { const allowCrashReport = await AsyncStorage.getItem(CRASH_REPORT_KEY); @@ -1206,13 +1210,13 @@ const RocketChat = { saveAutoTranslate({ rid, field, value, options }) { - return this.methodCall('autoTranslate.saveSettings', rid, field, value, options); + return this.methodCallWrapper('autoTranslate.saveSettings', rid, field, value, options); }, getSupportedLanguagesAutoTranslate() { - return this.methodCall('autoTranslate.getSupportedLanguages', 'en'); + return this.methodCallWrapper('autoTranslate.getSupportedLanguages', 'en'); }, translateMessage(message, targetLanguage) { - return this.methodCall('autoTranslate.translateMessage', message, targetLanguage); + return this.methodCallWrapper('autoTranslate.translateMessage', message, targetLanguage); }, getRoomTitle(room) { const { UI_Use_Real_Name: useRealName, UI_Allow_room_names_with_special_chars: allowSpecialChars } = reduxStore.getState().settings; From d23bcd9d82db1d5ba866282c18f194473569ee24 Mon Sep 17 00:00:00 2001 From: Djorkaeff Alexandre Date: Mon, 11 May 2020 15:15:49 -0300 Subject: [PATCH 4/4] fix --- app/views/RoomView/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/RoomView/index.js b/app/views/RoomView/index.js index 5dba91af79f..6b91b1d3a54 100644 --- a/app/views/RoomView/index.js +++ b/app/views/RoomView/index.js @@ -728,7 +728,7 @@ class RoomView extends React.Component { }); }); } else { - const thread = await RocketChat.getSingleMessage(tmid); + const { message: thread } = await RocketChat.getSingleMessage(tmid); await db.action(async() => { await db.batch( threadCollection.prepareCreate((t) => {