Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/constants/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export default {
Accounts_ManuallyApproveNewUsers: {
type: 'valueAsBoolean'
},
API_Use_REST_For_DDP_Calls: {
type: 'valueAsBoolean'
},
CROWD_Enable: {
type: 'valueAsBoolean'
},
Expand Down
75 changes: 41 additions & 34 deletions app/lib/rocketchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -319,20 +319,16 @@ 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) {
// RC 0.50.0
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);
Expand Down Expand Up @@ -566,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) {
Expand Down Expand Up @@ -595,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 });
},
Expand Down Expand Up @@ -734,11 +730,22 @@ 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 { 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() {
// RC 0.27.0
return this.methodCall('getUserRoles');
return this.methodCallWrapper('getUserRoles');
},
getRoomCounters(roomId, t) {
// RC 0.65.0
Expand All @@ -763,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
Expand All @@ -795,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
Expand Down Expand Up @@ -835,10 +842,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
Expand All @@ -851,10 +858,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) {
Expand All @@ -869,7 +876,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) => {
Expand Down Expand Up @@ -922,9 +929,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
Expand All @@ -934,11 +941,11 @@ 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.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;
Expand Down Expand Up @@ -983,15 +990,15 @@ const RocketChat = {
},
getAvatarSuggestion() {
// RC 0.51.0
return this.methodCall('getAvatarSuggestion');
return this.methodCallWrapper('getAvatarSuggestion');
},
resetAvatar(userId) {
// RC 0.55.0
return this.post('users.resetAvatar', { userId });
},
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);
Expand Down Expand Up @@ -1203,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;
Expand Down
2 changes: 1 addition & 1 deletion app/views/RoomView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion app/views/SetUsernameView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down