diff --git a/packages/rocketchat-accounts/.npm/package/.gitignore b/packages/rocketchat-accounts/.npm/package/.gitignore new file mode 100644 index 000000000000..3c3629e647f5 --- /dev/null +++ b/packages/rocketchat-accounts/.npm/package/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/packages/rocketchat-accounts/.npm/package/README b/packages/rocketchat-accounts/.npm/package/README new file mode 100644 index 000000000000..3d492553a438 --- /dev/null +++ b/packages/rocketchat-accounts/.npm/package/README @@ -0,0 +1,7 @@ +This directory and the files immediately inside it are automatically generated +when you change this package's NPM dependencies. Commit the files in this +directory (npm-shrinkwrap.json, .gitignore, and this README) to source control +so that others run the same versions of sub-dependencies. + +You should NOT check in the node_modules directory that Meteor automatically +creates; if you are using git, the .gitignore file tells git to ignore it. diff --git a/packages/rocketchat-accounts/.npm/package/npm-shrinkwrap.json b/packages/rocketchat-accounts/.npm/package/npm-shrinkwrap.json new file mode 100644 index 000000000000..e7626ee239b6 --- /dev/null +++ b/packages/rocketchat-accounts/.npm/package/npm-shrinkwrap.json @@ -0,0 +1,259 @@ +{ + "lockfileVersion": 1, + "dependencies": { + "@accounts/common": { + "version": "0.0.18", + "resolved": "https://registry.npmjs.org/@accounts/common/-/common-0.0.18.tgz", + "integrity": "sha1-QB9Sd+tHk6qNBD8TUCituAh+FHs=" + }, + "@accounts/mongo": { + "version": "0.0.12", + "resolved": "https://registry.npmjs.org/@accounts/mongo/-/mongo-0.0.12.tgz", + "integrity": "sha1-n7UNmgn2vThw5u3ZYC/xHL0gxns=" + }, + "@accounts/server": { + "version": "0.0.18", + "resolved": "https://registry.npmjs.org/@accounts/server/-/server-0.0.18.tgz", + "integrity": "sha1-S7UCs0WZUkRgRbqXYyT5MnuLekQ=" + }, + "addressparser": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/addressparser/-/addressparser-0.3.2.tgz", + "integrity": "sha1-WYc/Nej89sc2HBAjkmHXbhU0i7I=" + }, + "babel-polyfill": { + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-polyfill/-/babel-polyfill-6.26.0.tgz", + "integrity": "sha1-N5k3q8Z9eJWXCtxiHyhM2WbPIVM=" + }, + "babel-runtime": { + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", + "integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=", + "dependencies": { + "regenerator-runtime": { + "version": "0.11.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz", + "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==" + } + } + }, + "base64url": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/base64url/-/base64url-2.0.0.tgz", + "integrity": "sha1-6sFuA+oUOO/5Qj1puqNiYu0fcLs=" + }, + "bcryptjs": { + "version": "2.4.3", + "resolved": "https://registry.npmjs.org/bcryptjs/-/bcryptjs-2.4.3.tgz", + "integrity": "sha1-mrVie5PmBiH/fNrF2pczAn3x0Ms=" + }, + "bson": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/bson/-/bson-1.0.4.tgz", + "integrity": "sha1-k8ENOeqltYQVy8QFLz5T5WKwtyw=" + }, + "buffer-equal-constant-time": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", + "integrity": "sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk=" + }, + "buffer-shims": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/buffer-shims/-/buffer-shims-1.0.0.tgz", + "integrity": "sha1-mXjOMXOIxkmth5MCjDR37wRKi1E=" + }, + "bufferjs": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/bufferjs/-/bufferjs-1.1.0.tgz", + "integrity": "sha1-CV/6OcXmtAoheKEWnJ7/xYSnMgE=" + }, + "core-js": { + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.3.tgz", + "integrity": "sha1-isw4NFgk8W2DZbfJtCWRaOjtYD4=" + }, + "core-util-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" + }, + "crypto": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/crypto/-/crypto-0.0.3.tgz", + "integrity": "sha1-RwqBuGvkxe4XrMggeh9TFa4g27A=" + }, + "ecdsa-sig-formatter": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.9.tgz", + "integrity": "sha1-S8kmJ07Dtau1AW5+HWCSGsJisqE=" + }, + "emailjs": { + "version": "1.0.12", + "resolved": "https://registry.npmjs.org/emailjs/-/emailjs-1.0.12.tgz", + "integrity": "sha1-vWVZxRxJYxJSGGJtoJi+ci96HHI=" + }, + "encoding": { + "version": "0.1.12", + "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz", + "integrity": "sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=" + }, + "es6-promise": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-3.2.1.tgz", + "integrity": "sha1-7FYjOGgDKQkgcXDDlEjiREndH8Q=" + }, + "hoek": { + "version": "2.16.3", + "resolved": "https://registry.npmjs.org/hoek/-/hoek-2.16.3.tgz", + "integrity": "sha1-ILt0A9POo5jpHcRxCo/xuCdKJe0=" + }, + "iconv-lite": { + "version": "0.4.19", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", + "integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==" + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" + }, + "isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" + }, + "isemail": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/isemail/-/isemail-1.2.0.tgz", + "integrity": "sha1-vgPfjMPineTSxd9lASY/H6RZXpo=" + }, + "joi": { + "version": "6.10.1", + "resolved": "https://registry.npmjs.org/joi/-/joi-6.10.1.tgz", + "integrity": "sha1-TVDDGAeRIgAP5fFq8f+OGRe3fgY=" + }, + "jsonwebtoken": { + "version": "7.4.3", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-7.4.3.tgz", + "integrity": "sha1-d/UCHeBYtgWheD+hKD6ZgS5kVjg=" + }, + "jwa": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/jwa/-/jwa-1.1.5.tgz", + "integrity": "sha1-oFUs4CIHQs1S4VN3SjKQXDDnVuU=" + }, + "jws": { + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/jws/-/jws-3.1.4.tgz", + "integrity": "sha1-+ei5M46KhHJ31kRLFGT2GIDgUKI=" + }, + "jwt-decode": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-2.2.0.tgz", + "integrity": "sha1-fYa9VmefWM5qhHBKZX3TkruoGnk=" + }, + "lodash": { + "version": "4.17.5", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.5.tgz", + "integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw==" + }, + "lodash.once": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", + "integrity": "sha1-DdOXEhPHxW34gJd9UEyI+0cal6w=" + }, + "mimelib": { + "version": "0.2.14", + "resolved": "https://registry.npmjs.org/mimelib/-/mimelib-0.2.14.tgz", + "integrity": "sha1-KhqnJL0ZC4W9Um5jF6thBu39aDE=", + "dependencies": { + "addressparser": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/addressparser/-/addressparser-0.2.1.tgz", + "integrity": "sha1-0RpbLu2gTP7+vfMZbBCuE9ts1gc=" + } + } + }, + "moment": { + "version": "2.15.2", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.15.2.tgz", + "integrity": "sha1-G/3t9qbjRfMi/pVtXfW9CKjOhNw=" + }, + "mongodb": { + "version": "2.2.34", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-2.2.34.tgz", + "integrity": "sha1-o09Zu+thdUrsQy3nLD/iFSakTBo=" + }, + "mongodb-core": { + "version": "2.1.18", + "resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-2.1.18.tgz", + "integrity": "sha1-TEYTm986HwMt7ZHbSfOO7AFlkFA=" + }, + "ms": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", + "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==" + }, + "process-nextick-args": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz", + "integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M=" + }, + "readable-stream": { + "version": "2.2.7", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.2.7.tgz", + "integrity": "sha1-BwV6y+JGeyIELTb5jFrVBwVOlbE=" + }, + "regenerator-runtime": { + "version": "0.10.5", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz", + "integrity": "sha1-M2w+/BIgrc7dosn6tntaeVWjNlg=" + }, + "require_optional": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/require_optional/-/require_optional-1.0.1.tgz", + "integrity": "sha512-qhM/y57enGWHAe3v/NcwML6a3/vfESLe/sGM2dII+gEO0BpKRUkWZow/tyloNqJyN6kXSl3RyyM8Ll5D/sJP8g==" + }, + "resolve-from": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-2.0.0.tgz", + "integrity": "sha1-lICrIOlP+h2egKgEx+oUdhGWa1c=" + }, + "safe-buffer": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", + "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==" + }, + "semver": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz", + "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==" + }, + "starttls": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/starttls/-/starttls-1.0.1.tgz", + "integrity": "sha1-5ggcJd5rF49adfjyccFIdEkYO0I=" + }, + "string_decoder": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", + "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==" + }, + "topo": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/topo/-/topo-1.1.0.tgz", + "integrity": "sha1-6ddRYV0buH3IZdsYL6HKCl71NtU=" + }, + "util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" + }, + "xtend": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", + "integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68=" + } + } +} diff --git a/packages/rocketchat-channel-settings/client/views/channelSettings.js b/packages/rocketchat-channel-settings/client/views/channelSettings.js index 13474e64329d..3e13b3e06777 100644 --- a/packages/rocketchat-channel-settings/client/views/channelSettings.js +++ b/packages/rocketchat-channel-settings/client/views/channelSettings.js @@ -1,6 +1,6 @@ import toastr from 'toastr'; import s from 'underscore.string'; -import { RocketChat, RoomSettingsEnum } from 'meteor/rocketchat:lib'; +import { call, erase, hide, leave, RocketChat, RoomSettingsEnum } from 'meteor/rocketchat:lib'; const common = { canLeaveRoom() { const { cl: canLeave, t: roomType } = Template.instance().room; @@ -25,18 +25,6 @@ const common = { return room.t === 'd'; } }; -const call = (method, ...params) => { - return new Promise((resolve, reject) => { - Meteor.call(method, ...params, (err, result)=> { - if (err) { - handleError(err); - return reject(err); - } - return resolve(result); - }); - }); -}; - Template.channelSettingsEditing.events({ 'input .js-input'(e) { @@ -46,11 +34,11 @@ Template.channelSettingsEditing.events({ this.value.set(e.currentTarget.checked); }, 'click .js-reset'(e, t) { - const {settings} = t; + const { settings } = t; Object.keys(settings).forEach(key => settings[key].value.set(settings[key].default.get())); }, async 'click .js-save'(e, t) { - const {settings} = t; + const { settings } = t; Object.keys(settings).forEach(async name => { const setting = settings[name]; const value = setting.value.get(); @@ -201,7 +189,7 @@ Template.channelSettingsEditing.onCreated(function() { }; if (room['default']) { if (RocketChat.authz.hasRole(Meteor.userId(), 'admin')) { - return new Promise((resolve, reject)=> { + return new Promise((resolve, reject) => { modal.open({ title: t('Room_default_change_to_private_will_be_default_no_more'), type: 'warning', @@ -269,7 +257,7 @@ Template.channelSettingsEditing.onCreated(function() { return RocketChat.authz.hasAtLeastOnePermission(['archive-room', 'unarchive-room'], room._id); }, save(value) { - return new Promise((resolve, reject)=>{ + return new Promise((resolve, reject) => { modal.open({ title: t('Are_you_sure'), type: 'warning', @@ -347,7 +335,7 @@ Template.channelSettingsEditing.onCreated(function() { }; Object.keys(this.settings).forEach(key => { const setting = this.settings[key]; - const def =setting.getValue ? setting.getValue(this.room): this.room[key]; + const def = setting.getValue ? setting.getValue(this.room) : this.room[key]; setting.default = new ReactiveVar(def || false); setting.value = new ReactiveVar(def || false); }); @@ -368,7 +356,7 @@ Template.channelSettingsEditing.helpers({ return this.value.get();// ? '' : 'checked'; }, modified(text = '') { - const {settings} = Template.instance(); + const { settings } = Template.instance(); return !Object.keys(settings).some(key => settings[key].default.get() !== settings[key].value.get()) ? text : ''; }, equal(text = '', text2 = '', ret = '*') { @@ -385,7 +373,7 @@ Template.channelSettingsEditing.helpers({ return 'hashtag'; case 'l': return 'livechat'; - default : + default: return null; } }, @@ -420,96 +408,20 @@ Template.channelSettings.events({ t.editing.set(true); }, 'click .js-leave'(e, instance) { - let warnText; - const { rid, name, t : type } = instance.room; - switch (type) { - case 'c': warnText = 'Leave_Room_Warning'; break; - case 'p': warnText = 'Leave_Group_Warning'; break; - case 'd': warnText = 'Leave_Private_Warning'; break; - case 'l': warnText = 'Leave_Livechat_Warning'; break; - } - - modal.open({ - title: t('Are_you_sure'), - text: warnText ? t(warnText, name) : '', - type: 'warning', - showCancelButton: true, - confirmButtonColor: '#DD6B55', - confirmButtonText: t('Yes_leave_it'), - cancelButtonText: t('Cancel'), - closeOnConfirm: true, - html: false - }, async function() { - if (['channel', 'group', 'direct'].includes(FlowRouter.getRouteName()) && (Session.get('openedRoom') === rid)) { - FlowRouter.go('home'); - } - - await call('leaveRoom', rid); - - if (rid === Session.get('openedRoom')) { - Session.delete('openedRoom'); - } - - }); + const { name, t: type } = instance.room; + const rid = instance.room._id; + leave(type, rid, name); }, 'click .js-hide'(e, instance) { - let warnText; - const { rid, name, t: type } = instance.room; - switch (type) { - case 'c': warnText = 'Hide_Room_Warning'; break; - case 'p': warnText = 'Hide_Group_Warning'; break; - case 'd': warnText = 'Hide_Private_Warning'; break; - case 'l': warnText = 'Hide_Livechat_Warning'; break; - } - - modal.open({ - title: t('Are_you_sure'), - text: warnText ? t(warnText, name) : '', - type: 'warning', - showCancelButton: true, - confirmButtonColor: '#DD6B55', - confirmButtonText: t('Yes_hide_it'), - cancelButtonText: t('Cancel'), - closeOnConfirm: true, - html: false - }, async function() { - if (['channel', 'group', 'direct'].includes(FlowRouter.getRouteName()) && (Session.get('openedRoom') === rid)) { - FlowRouter.go('home'); - } - - await call('hideRoom', rid); - - if (rid === Session.get('openedRoom')) { - Session.delete('openedRoom'); - } - - }); + const { name, t: type } = instance.room; + const rid = instance.room._id; + hide(type, rid, name); }, 'click .js-cancel'(e, t) { t.editing.set(false); }, 'click .js-delete'() { - return modal.open({ - title: t('Are_you_sure'), - text: t('Delete_Room_Warning'), - type: 'warning', - showCancelButton: true, - confirmButtonColor: '#DD6B55', - confirmButtonText: t('Yes_delete_it'), - cancelButtonText: t('Cancel'), - closeOnConfirm: false, - html: false - }, () => { - call('eraseRoom', this.rid).then(() => { - modal.open({ - title: t('Deleted'), - text: t('Room_has_been_deleted'), - type: 'success', - timer: 2000, - showConfirmButton: false - }); - }); - }); + return erase(this.rid); } }); @@ -558,7 +470,7 @@ Template.channelSettingsInfo.helpers({ return 'hashtag'; case 'l': return 'livechat'; - default : + default: return null; } } diff --git a/packages/rocketchat-lib/client/lib/ChannelActions.js b/packages/rocketchat-lib/client/lib/ChannelActions.js new file mode 100644 index 000000000000..6f9a6d2e7f66 --- /dev/null +++ b/packages/rocketchat-lib/client/lib/ChannelActions.js @@ -0,0 +1,93 @@ +import { call, UiTextContext } from 'meteor/rocketchat:lib'; + +export function hide(type, rid, name) { + const warnText = RocketChat.roomTypes.roomTypes[type].getUiText(UiTextContext.HIDE_WARNING); + + modal.open({ + title: t('Are_you_sure'), + text: warnText ? t(warnText, name) : '', + type: 'warning', + showCancelButton: true, + confirmButtonColor: '#DD6B55', + confirmButtonText: t('Yes_hide_it'), + cancelButtonText: t('Cancel'), + closeOnConfirm: true, + html: false + }, function() { + if (['channel', 'group', 'direct'].includes(FlowRouter.getRouteName()) && (Session.get('openedRoom') === rid)) { + FlowRouter.go('home'); + } + + Meteor.call('hideRoom', rid, function(err) { + if (err) { + handleError(err); + } else if (rid === Session.get('openedRoom')) { + Session.delete('openedRoom'); + } + }); + }); + + return false; +} + +export function leave(type, rid, name) { + const warnText = RocketChat.roomTypes.roomTypes[type].getUiText(UiTextContext.LEAVE_WARNING); + + modal.open({ + title: t('Are_you_sure'), + text: warnText ? t(warnText, name) : '', + type: 'warning', + showCancelButton: true, + confirmButtonColor: '#DD6B55', + confirmButtonText: t('Yes_leave_it'), + cancelButtonText: t('Cancel'), + closeOnConfirm: false, + html: false + }, function(isConfirm) { + if (isConfirm) { + Meteor.call('leaveRoom', rid, function(err) { + if (err) { + modal.open({ + title: t('Warning'), + text: handleError(err, false), + type: 'warning', + html: false + }); + } else { + modal.close(); + if (['channel', 'group', 'direct'].includes(FlowRouter.getRouteName()) && (Session.get('openedRoom') === rid)) { + FlowRouter.go('home'); + } + + RoomManager.close(rid); + } + }); + } + }); + + return false; +} + +export function erase(rid) { + modal.open({ + title: t('Are_you_sure'), + text: t('Delete_Room_Warning'), + type: 'warning', + showCancelButton: true, + confirmButtonColor: '#DD6B55', + confirmButtonText: t('Yes_delete_it'), + cancelButtonText: t('Cancel'), + closeOnConfirm: false, + html: false + }, () => { + call('eraseRoom', rid).then(() => { + modal.open({ + title: t('Deleted'), + text: t('Room_has_been_deleted'), + type: 'success', + timer: 2000, + showConfirmButton: false + }); + }); + }); +} diff --git a/packages/rocketchat-lib/client/lib/callMethod.js b/packages/rocketchat-lib/client/lib/callMethod.js new file mode 100644 index 000000000000..cd92e9a83f3a --- /dev/null +++ b/packages/rocketchat-lib/client/lib/callMethod.js @@ -0,0 +1,17 @@ +/** + * Wraps a Meteor method into a Promise. + * This is particularly useful for creating information dialogs after execution of a Meteor method + * @param {The Meteor method to be calls} method + * @param {the method's parameters} params + */ +export const call = (method, ...params) => { + return new Promise((resolve, reject) => { + Meteor.call(method, ...params, (err, result) => { + if (err) { + handleError(err); + return reject(err); + } + return resolve(result); + }); + }); +}; diff --git a/packages/rocketchat-lib/client/lib/index.js b/packages/rocketchat-lib/client/lib/index.js index 908b583d61af..11697b503cbc 100644 --- a/packages/rocketchat-lib/client/lib/index.js +++ b/packages/rocketchat-lib/client/lib/index.js @@ -8,9 +8,14 @@ import { RocketChatTabBar } from './RocketChatTabBar'; import { RoomSettingsEnum, RoomTypeConfig, RoomTypeRouteConfig, UiTextContext } from '../../lib/RoomTypeConfig'; - +import { hide, leave, erase } from './ChannelActions'; +import { call } from './callMethod'; export { + call, + erase, + hide, + leave, RocketChatTabBar, RoomSettingsEnum, RoomTypeConfig, diff --git a/packages/rocketchat-ui/client/views/app/popover.js b/packages/rocketchat-ui/client/views/app/popover.js index 02f590ac3d91..3c594d69b566 100644 --- a/packages/rocketchat-ui/client/views/app/popover.js +++ b/packages/rocketchat-ui/client/views/app/popover.js @@ -1,7 +1,7 @@ /* globals popover isRtl */ import _ from 'underscore'; -import {UiTextContext} from 'meteor/rocketchat:lib'; +import { hide, leave } from 'meteor/rocketchat:lib'; this.popover = { renderedPopover: null, @@ -41,7 +41,7 @@ Template.popover.onRendered(function() { const activeElement = this.data.activeElement; const popoverContent = this.firstNode.children[0]; const position = _.throttle(() => { - const position = typeof this.data.position === 'function'? this.data.position() : this.data.position; + const position = typeof this.data.position === 'function' ? this.data.position() : this.data.position; const customCSSProperties = typeof this.data.customCSSProperties === 'function' ? this.data.customCSSProperties() : this.data.customCSSProperties; const mousePosition = typeof this.data.mousePosition === 'function' ? this.data.mousePosition() : this.data.mousePosition; if (position) { @@ -114,7 +114,7 @@ Template.popover.events({ const id = event.currentTarget.dataset.id; const action = RocketChat.messageBox.actions.getById(id); if ((action[0] != null ? action[0].action : undefined) != null) { - action[0].action({rid: t.data.data.rid, messageBox: document.querySelector('.rc-message-box'), element: event.currentTarget, event}); + action[0].action({ rid: t.data.data.rid, messageBox: document.querySelector('.rc-message-box'), element: event.currentTarget, event }); if (id !== 'audio-message') { popover.close(); } @@ -210,75 +210,11 @@ Template.popover.events({ const action = e.currentTarget.dataset.id; if (action === 'hide') { - const warnText = RocketChat.roomTypes.roomTypes[template].getUiText(UiTextContext.HIDE_WARNING); - - modal.open({ - title: t('Are_you_sure'), - text: warnText ? t(warnText, name) : '', - type: 'warning', - showCancelButton: true, - confirmButtonColor: '#DD6B55', - confirmButtonText: t('Yes_hide_it'), - cancelButtonText: t('Cancel'), - closeOnConfirm: true, - html: false - }, function() { - if (['channel', 'group', 'direct'].includes(FlowRouter.getRouteName()) && (Session.get('openedRoom') === rid)) { - FlowRouter.go('home'); - } - - Meteor.call('hideRoom', rid, function(err) { - if (err) { - handleError(err); - } else if (rid === Session.get('openedRoom')) { - Session.delete('openedRoom'); - } - }); - }); + hide(template, rid, name); } if (action === 'leave') { - let warnText; - switch (template) { - case 'c': warnText = 'Leave_Room_Warning'; break; - case 'p': warnText = 'Leave_Group_Warning'; break; - case 'd': warnText = 'Leave_Private_Warning'; break; - case 'l': warnText = 'Hide_Livechat_Warning'; break; - } - - modal.open({ - title: t('Are_you_sure'), - text: warnText ? t(warnText, name) : '', - type: 'warning', - showCancelButton: true, - confirmButtonColor: '#DD6B55', - confirmButtonText: t('Yes_leave_it'), - cancelButtonText: t('Cancel'), - closeOnConfirm: false, - html: false - }, function(isConfirm) { - if (isConfirm) { - Meteor.call('leaveRoom', rid, function(err) { - if (err) { - modal.open({ - title: t('Warning'), - text: handleError(err, false), - type: 'warning', - html: false - }); - } else { - modal.close(); - if (['channel', 'group', 'direct'].includes(FlowRouter.getRouteName()) && (Session.get('openedRoom') === rid)) { - FlowRouter.go('home'); - } - - RoomManager.close(rid); - } - }); - } - }); - - return false; + leave(template, rid, name); } if (action === 'read') { @@ -292,7 +228,7 @@ Template.popover.events({ return handleError(error); } - const subscription = ChatSubscription.findOne({rid}); + const subscription = ChatSubscription.findOne({ rid }); if (subscription == null) { return; }