refactor some call apis

This commit is contained in:
Guilherme Gazzo 2017-11-19 00:31:34 -02:00
parent 3dbd70b42b
commit 654967ccf9
1 changed files with 10 additions and 75 deletions

View File

@ -26,9 +26,7 @@ const RocketChat = {
TOKEN_KEY, TOKEN_KEY,
createChannel({ name, users, type }) { createChannel({ name, users, type }) {
return new Promise((resolve, reject) => { return call(type ? 'createChannel' : 'createPrivateGroup', name, users, type);
Meteor.call(type ? 'createChannel' : 'createPrivateGroup', name, users, type, (err, res) => (err ? reject(err) : resolve(res)));
});
}, },
async getUserToken() { async getUserToken() {
@ -136,36 +134,15 @@ const RocketChat = {
}, },
register({ credentials }) { register({ credentials }) {
return new Promise((resolve, reject) => { return call('registerUser', credentials);
Meteor.call('registerUser', credentials, (err, userId) => {
if (err) {
reject(err);
}
resolve(userId);
});
});
}, },
setUsername({ credentials }) { setUsername({ credentials }) {
return new Promise((resolve, reject) => { return call('setUsername', credentials.username);
Meteor.call('setUsername', credentials.username, (err, result) => {
if (err) {
reject(err);
}
resolve(result);
});
});
}, },
forgotPassword(email) { forgotPassword(email) {
return new Promise((resolve, reject) => { return call('sendForgotPasswordEmail', email);
Meteor.call('sendForgotPasswordEmail', email, (err, result) => {
if (err) {
reject(err);
}
resolve(result);
});
});
}, },
loginWithPassword({ username, password, code }, callback) { loginWithPassword({ username, password, code }, callback) {
@ -317,38 +294,17 @@ const RocketChat = {
}, },
spotlight(search, usernames) { spotlight(search, usernames) {
return new Promise((resolve, reject) => { return call('spotlight', search, usernames);
Meteor.call('spotlight', search, usernames, (error, result) => {
if (error) {
return reject(error);
}
return resolve(result);
});
});
}, },
createDirectMessage(username) { createDirectMessage(username) {
return new Promise((resolve, reject) => { return call('createDirectMessage', username);
Meteor.call('createDirectMessage', username, (error, result) => {
if (error) {
return reject(error);
}
return resolve(result);
});
});
}, },
readMessages(rid) { readMessages(rid) {
return call('readMessages', rid); return call('readMessages', rid);
}, },
joinRoom(rid) { joinRoom(rid) {
return new Promise((resolve, reject) => { return call('joinRoom', rid);
Meteor.call('joinRoom', rid, (error, result) => {
if (error) {
return reject(error);
}
return resolve(result);
});
});
}, },
@ -362,26 +318,12 @@ const RocketChat = {
*/ */
_ufsCreate(fileInfo) { _ufsCreate(fileInfo) {
// return call('ufsCreate', fileInfo); // return call('ufsCreate', fileInfo);
return new Promise((resolve, reject) => { return call('ufsCreate', fileInfo);
Meteor.call('ufsCreate', fileInfo, (error, result) => {
if (error) {
return reject(error);
}
return resolve(result);
});
});
}, },
// ["ZTE8CKHJt7LATv7Me","fileSystem","e8E96b2819" // ["ZTE8CKHJt7LATv7Me","fileSystem","e8E96b2819"
_ufsComplete(fileId, store, token) { _ufsComplete(fileId, store, token) {
return new Promise((resolve, reject) => { return call('ufsComplete', fileId, store, token);
Meteor.call('ufsComplete', fileId, store, token, (error, result) => {
if (error) {
return reject(error);
}
return resolve(result);
});
});
}, },
/* /*
@ -395,14 +337,7 @@ const RocketChat = {
} }
*/ */
_sendFileMessage(rid, data, msg = {}) { _sendFileMessage(rid, data, msg = {}) {
return new Promise((resolve, reject) => { return call('sendFileMessage', rid, null, data, msg);
Meteor.call('sendFileMessage', rid, null, data, msg, (error, result) => {
if (error) {
return reject(error);
}
return resolve(result);
});
});
}, },
async sendFileMessage(rid, fileInfo, data) { async sendFileMessage(rid, fileInfo, data) {
const placeholder = RocketChat.getMessage(rid, 'Sending an image'); const placeholder = RocketChat.getMessage(rid, 'Sending an image');