[CHORE] Add wrapper to make Meteor methods calls over REST (#2104)
* [WIP] Use rest instead methodCall * [WIP] Some method calls using wrapper * [WIP] Wrap all necessary methodCalls * fix Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
parent
a5aba5fc84
commit
e34b7cbb87
|
@ -50,6 +50,9 @@ export default {
|
||||||
Accounts_ManuallyApproveNewUsers: {
|
Accounts_ManuallyApproveNewUsers: {
|
||||||
type: 'valueAsBoolean'
|
type: 'valueAsBoolean'
|
||||||
},
|
},
|
||||||
|
API_Use_REST_For_DDP_Calls: {
|
||||||
|
type: 'valueAsBoolean'
|
||||||
|
},
|
||||||
Accounts_iframe_enabled: {
|
Accounts_iframe_enabled: {
|
||||||
type: 'valueAsBoolean'
|
type: 'valueAsBoolean'
|
||||||
},
|
},
|
||||||
|
|
|
@ -25,7 +25,7 @@ async function callJitsi(rid, onlyAudio = false) {
|
||||||
|
|
||||||
if (Jitsi_Enabled_TokenAuth) {
|
if (Jitsi_Enabled_TokenAuth) {
|
||||||
try {
|
try {
|
||||||
accessToken = await this.sdk.methodCall('jitsi:generateAccessToken', rid);
|
accessToken = await this.methodCallWrapper('jitsi:generateAccessToken', rid);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ const RocketChat = {
|
||||||
name, users, type, readOnly, broadcast
|
name, users, type, readOnly, broadcast
|
||||||
}) {
|
}) {
|
||||||
// RC 0.51.0
|
// 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() {
|
async getUserToken() {
|
||||||
try {
|
try {
|
||||||
|
@ -318,8 +318,9 @@ const RocketChat = {
|
||||||
reduxStore.dispatch(shareSetUser({}));
|
reduxStore.dispatch(shareSetUser({}));
|
||||||
},
|
},
|
||||||
|
|
||||||
updateJitsiTimeout(rid) {
|
updateJitsiTimeout(roomId) {
|
||||||
return this.methodCall('jitsi:updateTimeout', rid);
|
// RC 0.74.0
|
||||||
|
return this.post('jitsi.updateTimeout', { roomId });
|
||||||
},
|
},
|
||||||
|
|
||||||
register(credentials) {
|
register(credentials) {
|
||||||
|
@ -327,11 +328,6 @@ const RocketChat = {
|
||||||
return this.post('users.register', credentials, false);
|
return this.post('users.register', credentials, false);
|
||||||
},
|
},
|
||||||
|
|
||||||
setUsername(username) {
|
|
||||||
// RC 0.51.0
|
|
||||||
return this.methodCall('setUsername', username);
|
|
||||||
},
|
|
||||||
|
|
||||||
forgotPassword(email) {
|
forgotPassword(email) {
|
||||||
// RC 0.64.0
|
// RC 0.64.0
|
||||||
return this.post('users.forgotPassword', { email }, false);
|
return this.post('users.forgotPassword', { email }, false);
|
||||||
|
@ -567,7 +563,7 @@ const RocketChat = {
|
||||||
|
|
||||||
spotlight(search, usernames, type) {
|
spotlight(search, usernames, type) {
|
||||||
// RC 0.51.0
|
// RC 0.51.0
|
||||||
return this.methodCall('spotlight', search, usernames, type);
|
return this.methodCallWrapper('spotlight', search, usernames, type);
|
||||||
},
|
},
|
||||||
|
|
||||||
createDirectMessage(username) {
|
createDirectMessage(username) {
|
||||||
|
@ -596,7 +592,7 @@ const RocketChat = {
|
||||||
// TODO: join code
|
// TODO: join code
|
||||||
// RC 0.48.0
|
// RC 0.48.0
|
||||||
if (type === 'p') {
|
if (type === 'p') {
|
||||||
return this.methodCall('joinRoom', roomId);
|
return this.methodCallWrapper('joinRoom', roomId);
|
||||||
}
|
}
|
||||||
return this.post('channels.join', { roomId });
|
return this.post('channels.join', { roomId });
|
||||||
},
|
},
|
||||||
|
@ -738,11 +734,22 @@ const RocketChat = {
|
||||||
},
|
},
|
||||||
getRoomMembers(rid, allUsers, skip = 0, limit = 10) {
|
getRoomMembers(rid, allUsers, skip = 0, limit = 10) {
|
||||||
// RC 0.42.0
|
// 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 { 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() {
|
getUserRoles() {
|
||||||
// RC 0.27.0
|
// RC 0.27.0
|
||||||
return this.methodCall('getUserRoles');
|
return this.methodCallWrapper('getUserRoles');
|
||||||
},
|
},
|
||||||
getRoomCounters(roomId, t) {
|
getRoomCounters(roomId, t) {
|
||||||
// RC 0.65.0
|
// RC 0.65.0
|
||||||
|
@ -767,19 +774,19 @@ const RocketChat = {
|
||||||
},
|
},
|
||||||
closeLivechat(rid, comment) {
|
closeLivechat(rid, comment) {
|
||||||
// RC 0.29.0
|
// 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) {
|
editLivechat(userData, roomData) {
|
||||||
// RC 0.55.0
|
// RC 0.55.0
|
||||||
return this.methodCall('livechat:saveInfo', userData, roomData);
|
return this.methodCallWrapper('livechat:saveInfo', userData, roomData);
|
||||||
},
|
},
|
||||||
returnLivechat(rid) {
|
returnLivechat(rid) {
|
||||||
// RC 0.72.0
|
// RC 0.72.0
|
||||||
return this.methodCall('livechat:returnAsInquiry', rid);
|
return this.methodCallWrapper('livechat:returnAsInquiry', rid);
|
||||||
},
|
},
|
||||||
forwardLivechat(transferData) {
|
forwardLivechat(transferData) {
|
||||||
// RC 0.36.0
|
// RC 0.36.0
|
||||||
return this.methodCall('livechat:transfer', transferData);
|
return this.methodCallWrapper('livechat:transfer', transferData);
|
||||||
},
|
},
|
||||||
getPagesLivechat(rid, offset) {
|
getPagesLivechat(rid, offset) {
|
||||||
// RC 2.3.0
|
// RC 2.3.0
|
||||||
|
@ -799,11 +806,11 @@ const RocketChat = {
|
||||||
},
|
},
|
||||||
getRoutingConfig() {
|
getRoutingConfig() {
|
||||||
// RC 2.0.0
|
// RC 2.0.0
|
||||||
return this.methodCall('livechat:getRoutingConfig');
|
return this.methodCallWrapper('livechat:getRoutingConfig');
|
||||||
},
|
},
|
||||||
getTagsList() {
|
getTagsList() {
|
||||||
// RC 2.0.0
|
// RC 2.0.0
|
||||||
return this.methodCall('livechat:getTagsList');
|
return this.methodCallWrapper('livechat:getTagsList');
|
||||||
},
|
},
|
||||||
getAgentDepartments(uid) {
|
getAgentDepartments(uid) {
|
||||||
// RC 2.4.0
|
// RC 2.4.0
|
||||||
|
@ -815,7 +822,7 @@ const RocketChat = {
|
||||||
},
|
},
|
||||||
changeLivechatStatus() {
|
changeLivechatStatus() {
|
||||||
// RC 0.26.0
|
// RC 0.26.0
|
||||||
return this.methodCall('livechat:changeLivechatStatus');
|
return this.methodCallWrapper('livechat:changeLivechatStatus');
|
||||||
},
|
},
|
||||||
|
|
||||||
getUidDirectMessage(room) {
|
getUidDirectMessage(room) {
|
||||||
|
@ -843,10 +850,10 @@ const RocketChat = {
|
||||||
toggleBlockUser(rid, blocked, block) {
|
toggleBlockUser(rid, blocked, block) {
|
||||||
if (block) {
|
if (block) {
|
||||||
// RC 0.49.0
|
// RC 0.49.0
|
||||||
return this.methodCall('blockUser', { rid, blocked });
|
return this.methodCallWrapper('blockUser', { rid, blocked });
|
||||||
}
|
}
|
||||||
// RC 0.49.0
|
// RC 0.49.0
|
||||||
return this.methodCall('unblockUser', { rid, blocked });
|
return this.methodCallWrapper('unblockUser', { rid, blocked });
|
||||||
},
|
},
|
||||||
leaveRoom(roomId, t) {
|
leaveRoom(roomId, t) {
|
||||||
// RC 0.48.0
|
// RC 0.48.0
|
||||||
|
@ -859,10 +866,10 @@ const RocketChat = {
|
||||||
toggleMuteUserInRoom(rid, username, mute) {
|
toggleMuteUserInRoom(rid, username, mute) {
|
||||||
if (mute) {
|
if (mute) {
|
||||||
// RC 0.51.0
|
// RC 0.51.0
|
||||||
return this.methodCall('muteUserInRoom', { rid, username });
|
return this.methodCallWrapper('muteUserInRoom', { rid, username });
|
||||||
}
|
}
|
||||||
// RC 0.51.0
|
// RC 0.51.0
|
||||||
return this.methodCall('unmuteUserInRoom', { rid, username });
|
return this.methodCallWrapper('unmuteUserInRoom', { rid, username });
|
||||||
},
|
},
|
||||||
toggleArchiveRoom(roomId, t, archive) {
|
toggleArchiveRoom(roomId, t, archive) {
|
||||||
if (archive) {
|
if (archive) {
|
||||||
|
@ -877,7 +884,7 @@ const RocketChat = {
|
||||||
},
|
},
|
||||||
saveRoomSettings(rid, params) {
|
saveRoomSettings(rid, params) {
|
||||||
// RC 0.55.0
|
// RC 0.55.0
|
||||||
return this.methodCall('saveRoomSettings', rid, params);
|
return this.methodCallWrapper('saveRoomSettings', rid, params);
|
||||||
},
|
},
|
||||||
post(...args) {
|
post(...args) {
|
||||||
return new Promise(async(resolve, reject) => {
|
return new Promise(async(resolve, reject) => {
|
||||||
|
@ -930,9 +937,9 @@ const RocketChat = {
|
||||||
// RC 0.62.2
|
// RC 0.62.2
|
||||||
return this.post('users.updateOwnBasicInfo', { data, customFields });
|
return this.post('users.updateOwnBasicInfo', { data, customFields });
|
||||||
},
|
},
|
||||||
saveUserPreferences(params) {
|
saveUserPreferences(data) {
|
||||||
// RC 0.51.0
|
// RC 0.62.0
|
||||||
return this.methodCall('saveUserPreferences', params);
|
return this.post('users.setPreferences', { data });
|
||||||
},
|
},
|
||||||
saveNotificationSettings(roomId, notifications) {
|
saveNotificationSettings(roomId, notifications) {
|
||||||
// RC 0.63.0
|
// RC 0.63.0
|
||||||
|
@ -942,11 +949,11 @@ const RocketChat = {
|
||||||
let { users } = reduxStore.getState().selectedUsers;
|
let { users } = reduxStore.getState().selectedUsers;
|
||||||
users = users.map(u => u.name);
|
users = users.map(u => u.name);
|
||||||
// RC 0.51.0
|
// RC 0.51.0
|
||||||
return this.methodCall('addUsersToRoom', { rid, users });
|
return this.methodCallWrapper('addUsersToRoom', { rid, users });
|
||||||
},
|
},
|
||||||
getSingleMessage(msgId) {
|
getSingleMessage(msgId) {
|
||||||
// RC 0.57.0
|
// RC 0.47.0
|
||||||
return this.methodCall('getSingleMessage', msgId);
|
return this.sdk.get('chat.getMessage', { msgId });
|
||||||
},
|
},
|
||||||
async hasPermission(permissions, rid) {
|
async hasPermission(permissions, rid) {
|
||||||
const db = database.active;
|
const db = database.active;
|
||||||
|
@ -991,7 +998,7 @@ const RocketChat = {
|
||||||
},
|
},
|
||||||
getAvatarSuggestion() {
|
getAvatarSuggestion() {
|
||||||
// RC 0.51.0
|
// RC 0.51.0
|
||||||
return this.methodCall('getAvatarSuggestion');
|
return this.methodCallWrapper('getAvatarSuggestion');
|
||||||
},
|
},
|
||||||
resetAvatar(userId) {
|
resetAvatar(userId) {
|
||||||
// RC 0.55.0
|
// RC 0.55.0
|
||||||
|
@ -999,7 +1006,7 @@ const RocketChat = {
|
||||||
},
|
},
|
||||||
setAvatarFromService({ data, contentType = '', service = null }) {
|
setAvatarFromService({ data, contentType = '', service = null }) {
|
||||||
// RC 0.51.0
|
// RC 0.51.0
|
||||||
return this.methodCall('setAvatarFromService', data, contentType, service);
|
return this.methodCallWrapper('setAvatarFromService', data, contentType, service);
|
||||||
},
|
},
|
||||||
async getAllowCrashReport() {
|
async getAllowCrashReport() {
|
||||||
const allowCrashReport = await AsyncStorage.getItem(CRASH_REPORT_KEY);
|
const allowCrashReport = await AsyncStorage.getItem(CRASH_REPORT_KEY);
|
||||||
|
@ -1211,13 +1218,13 @@ const RocketChat = {
|
||||||
saveAutoTranslate({
|
saveAutoTranslate({
|
||||||
rid, field, value, options
|
rid, field, value, options
|
||||||
}) {
|
}) {
|
||||||
return this.methodCall('autoTranslate.saveSettings', rid, field, value, options);
|
return this.methodCallWrapper('autoTranslate.saveSettings', rid, field, value, options);
|
||||||
},
|
},
|
||||||
getSupportedLanguagesAutoTranslate() {
|
getSupportedLanguagesAutoTranslate() {
|
||||||
return this.methodCall('autoTranslate.getSupportedLanguages', 'en');
|
return this.methodCallWrapper('autoTranslate.getSupportedLanguages', 'en');
|
||||||
},
|
},
|
||||||
translateMessage(message, targetLanguage) {
|
translateMessage(message, targetLanguage) {
|
||||||
return this.methodCall('autoTranslate.translateMessage', message, targetLanguage);
|
return this.methodCallWrapper('autoTranslate.translateMessage', message, targetLanguage);
|
||||||
},
|
},
|
||||||
getRoomTitle(room) {
|
getRoomTitle(room) {
|
||||||
const { UI_Use_Real_Name: useRealName, UI_Allow_room_names_with_special_chars: allowSpecialChars } = reduxStore.getState().settings;
|
const { UI_Use_Real_Name: useRealName, UI_Allow_room_names_with_special_chars: allowSpecialChars } = reduxStore.getState().settings;
|
||||||
|
|
|
@ -698,7 +698,7 @@ class RoomView extends React.Component {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const thread = await RocketChat.getSingleMessage(tmid);
|
const { message: thread } = await RocketChat.getSingleMessage(tmid);
|
||||||
await db.action(async() => {
|
await db.action(async() => {
|
||||||
await db.batch(
|
await db.batch(
|
||||||
threadCollection.prepareCreate((t) => {
|
threadCollection.prepareCreate((t) => {
|
||||||
|
|
|
@ -88,7 +88,7 @@ class SetUsernameView extends React.Component {
|
||||||
|
|
||||||
this.setState({ saving: true });
|
this.setState({ saving: true });
|
||||||
try {
|
try {
|
||||||
await RocketChat.setUsername(username);
|
await RocketChat.saveUserProfile({ username });
|
||||||
await loginRequest({ resume: token });
|
await loginRequest({ resume: token });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
showErrorAlert(e.message, I18n.t('Oops'));
|
showErrorAlert(e.message, I18n.t('Oops'));
|
||||||
|
|
Loading…
Reference in New Issue