diff --git a/packages/rocketchat-drupal/lib/common.js b/packages/rocketchat-drupal/lib/common.js index 6386d9de4061..32c0a5e80682 100644 --- a/packages/rocketchat-drupal/lib/common.js +++ b/packages/rocketchat-drupal/lib/common.js @@ -1,6 +1,6 @@ import { Meteor } from 'meteor/meteor'; import { Tracker } from 'meteor/tracker'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { settings } from 'meteor/rocketchat:settings'; import { CustomOAuth } from 'meteor/rocketchat:custom-oauth'; // Drupal Server CallBack URL needs to be http(s)://{rocketchat.server}[:port]/_oauth/drupal @@ -25,7 +25,7 @@ const Drupal = new CustomOAuth('drupal', config); if (Meteor.isServer) { Meteor.startup(function() { - RocketChat.settings.get('API_Drupal_URL', function(key, value) { + settings.get('API_Drupal_URL', function(key, value) { config.serverURL = value; Drupal.configure(config); }); @@ -33,8 +33,8 @@ if (Meteor.isServer) { } else { Meteor.startup(function() { Tracker.autorun(function() { - if (RocketChat.settings.get('API_Drupal_URL')) { - config.serverURL = RocketChat.settings.get('API_Drupal_URL'); + if (settings.get('API_Drupal_URL')) { + config.serverURL = settings.get('API_Drupal_URL'); Drupal.configure(config); } }); diff --git a/packages/rocketchat-drupal/package.js b/packages/rocketchat-drupal/package.js index 5841812c23e7..4b14e98941ee 100644 --- a/packages/rocketchat-drupal/package.js +++ b/packages/rocketchat-drupal/package.js @@ -9,7 +9,7 @@ Package.onUse(function(api) { api.use([ 'ecmascript', 'service-configuration', - 'rocketchat:lib@0.0.1', + 'rocketchat:settings', 'rocketchat:custom-oauth', 'templating', ]); diff --git a/packages/rocketchat-drupal/server/startup.js b/packages/rocketchat-drupal/server/startup.js index 389c2d06dbf1..186ccf6dae9b 100644 --- a/packages/rocketchat-drupal/server/startup.js +++ b/packages/rocketchat-drupal/server/startup.js @@ -1,6 +1,6 @@ -import { RocketChat } from 'meteor/rocketchat:lib'; +import { settings } from 'meteor/rocketchat:settings'; -RocketChat.settings.addGroup('OAuth', function() { +settings.addGroup('OAuth', function() { this.section('Drupal', function() { const enableQuery = { _id: 'Accounts_OAuth_Drupal', diff --git a/packages/rocketchat-emoji-custom/client/admin/adminEmoji.js b/packages/rocketchat-emoji-custom/client/admin/adminEmoji.js index b73fe2b8829a..09cc41bcfb58 100644 --- a/packages/rocketchat-emoji-custom/client/admin/adminEmoji.js +++ b/packages/rocketchat-emoji-custom/client/admin/adminEmoji.js @@ -1,9 +1,9 @@ import { ReactiveVar } from 'meteor/reactive-var'; -import { RocketChat, RocketChatTabBar } from 'meteor/rocketchat:lib'; +import { RocketChatTabBar, SideNav, TabBar } from 'meteor/rocketchat:ui-utils'; import { Tracker } from 'meteor/tracker'; +import { EmojiCustom } from 'meteor/rocketchat:models'; import { FlowRouter } from 'meteor/kadira:flow-router'; import { Template } from 'meteor/templating'; -import { SideNav } from 'meteor/rocketchat:ui'; import s from 'underscore.string'; Template.adminEmoji.helpers({ @@ -49,7 +49,7 @@ Template.adminEmoji.onCreated(function() { this.tabBar.showGroup(FlowRouter.current().route.name); this.tabBarData = new ReactiveVar(); - RocketChat.TabBar.addButton({ + TabBar.addButton({ groups: ['emoji-custom'], id: 'add-emoji', i18nTitle: 'Custom_Emoji_Add', @@ -58,7 +58,7 @@ Template.adminEmoji.onCreated(function() { order: 1, }); - RocketChat.TabBar.addButton({ + TabBar.addButton({ groups: ['emoji-custom'], id: 'admin-emoji-info', i18nTitle: 'Custom_Emoji_Info', @@ -85,7 +85,7 @@ Template.adminEmoji.onCreated(function() { const limit = (instance.limit != null) ? instance.limit.get() : 0; - return RocketChat.models.EmojiCustom.find(query, { limit, sort: { name: 1 } }).fetch(); + return EmojiCustom.find(query, { limit, sort: { name: 1 } }).fetch(); }; }); @@ -113,7 +113,7 @@ Template.adminEmoji.events({ 'click .emoji-info'(e, instance) { e.preventDefault(); - instance.tabBarData.set(RocketChat.models.EmojiCustom.findOne({ _id: this._id })); + instance.tabBarData.set(EmojiCustom.findOne({ _id: this._id })); instance.tabBar.open('admin-emoji-info'); }, diff --git a/packages/rocketchat-emoji-custom/client/admin/emojiEdit.js b/packages/rocketchat-emoji-custom/client/admin/emojiEdit.js index b318029e4dd6..105089915506 100644 --- a/packages/rocketchat-emoji-custom/client/admin/emojiEdit.js +++ b/packages/rocketchat-emoji-custom/client/admin/emojiEdit.js @@ -1,8 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { Template } from 'meteor/templating'; import { TAPi18n } from 'meteor/tap:i18n'; -import { handleError } from 'meteor/rocketchat:lib'; -import { t } from 'meteor/rocketchat:utils'; +import { t, handleError } from 'meteor/rocketchat:utils'; import toastr from 'toastr'; import s from 'underscore.string'; diff --git a/packages/rocketchat-emoji-custom/client/admin/emojiInfo.js b/packages/rocketchat-emoji-custom/client/admin/emojiInfo.js index 3fb81a237eeb..f1564fa520ce 100644 --- a/packages/rocketchat-emoji-custom/client/admin/emojiInfo.js +++ b/packages/rocketchat-emoji-custom/client/admin/emojiInfo.js @@ -1,9 +1,8 @@ import { Meteor } from 'meteor/meteor'; import { ReactiveVar } from 'meteor/reactive-var'; import { Template } from 'meteor/templating'; -import { handleError } from 'meteor/rocketchat:lib'; -import { modal } from 'meteor/rocketchat:ui'; -import { t } from 'meteor/rocketchat:utils'; +import { handleError, t } from 'meteor/rocketchat:utils'; +import { modal } from 'meteor/rocketchat:ui-utils'; Template.emojiInfo.helpers({ name() { diff --git a/packages/rocketchat-emoji-custom/client/admin/startup.js b/packages/rocketchat-emoji-custom/client/admin/startup.js index 0d6b232eb9a5..294fd023c190 100644 --- a/packages/rocketchat-emoji-custom/client/admin/startup.js +++ b/packages/rocketchat-emoji-custom/client/admin/startup.js @@ -1,10 +1,11 @@ -import { RocketChat } from 'meteor/rocketchat:lib'; +import { AdminBox } from 'meteor/rocketchat:ui-utils'; +import { hasPermission } from 'meteor/rocketchat:authorization'; -RocketChat.AdminBox.addOption({ +AdminBox.addOption({ href: 'emoji-custom', i18nLabel: 'Custom_Emoji', icon: 'emoji', permissionGranted() { - return RocketChat.authz.hasPermission('manage-emoji'); + return hasPermission('manage-emoji'); }, }); diff --git a/packages/rocketchat-emoji-custom/client/index.js b/packages/rocketchat-emoji-custom/client/index.js index 9688848698dd..06b377694769 100644 --- a/packages/rocketchat-emoji-custom/client/index.js +++ b/packages/rocketchat-emoji-custom/client/index.js @@ -1,4 +1,3 @@ -import './models/EmojiCustom'; import './lib/emojiCustom'; import './notifications/deleteEmojiCustom'; import './notifications/updateEmojiCustom'; diff --git a/packages/rocketchat-emoji-custom/client/lib/emojiCustom.js b/packages/rocketchat-emoji-custom/client/lib/emojiCustom.js index c60674a2ac44..515f504e2159 100644 --- a/packages/rocketchat-emoji-custom/client/lib/emojiCustom.js +++ b/packages/rocketchat-emoji-custom/client/lib/emojiCustom.js @@ -1,9 +1,10 @@ import { Meteor } from 'meteor/meteor'; import { Blaze } from 'meteor/blaze'; import { Session } from 'meteor/session'; -import { RocketChat } from 'meteor/rocketchat:lib'; import { isSetNotNull } from '../lib/function-isSet'; -import { RoomManager } from 'meteor/rocketchat:ui'; +import { RoomManager } from 'meteor/rocketchat:ui-utils'; +import { emoji, EmojiPicker } from 'meteor/rocketchat:emoji'; +import { CachedCollectionManager } from 'meteor/rocketchat:ui-cached-collection'; export const getEmojiUrlFromName = function(name, extension) { Session.get; @@ -25,25 +26,25 @@ export const getEmojiUrlFromName = function(name, extension) { Blaze.registerHelper('emojiUrlFromName', getEmojiUrlFromName); export const deleteEmojiCustom = function(emojiData) { - delete RocketChat.emoji.list[`:${ emojiData.name }:`]; - const arrayIndex = RocketChat.emoji.packages.emojiCustom.emojisByCategory.rocket.indexOf(emojiData.name); + delete emoji.list[`:${ emojiData.name }:`]; + const arrayIndex = emoji.packages.emojiCustom.emojisByCategory.rocket.indexOf(emojiData.name); if (arrayIndex !== -1) { - RocketChat.emoji.packages.emojiCustom.emojisByCategory.rocket.splice(arrayIndex, 1); + emoji.packages.emojiCustom.emojisByCategory.rocket.splice(arrayIndex, 1); } - const arrayIndexList = RocketChat.emoji.packages.emojiCustom.list.indexOf(`:${ emojiData.name }:`); + const arrayIndexList = emoji.packages.emojiCustom.list.indexOf(`:${ emojiData.name }:`); if (arrayIndexList !== -1) { - RocketChat.emoji.packages.emojiCustom.list.splice(arrayIndexList, 1); + emoji.packages.emojiCustom.list.splice(arrayIndexList, 1); } if (isSetNotNull(() => emojiData.aliases)) { for (const alias of emojiData.aliases) { - delete RocketChat.emoji.list[`:${ alias }:`]; - const aliasIndex = RocketChat.emoji.packages.emojiCustom.list.indexOf(`:${ alias }:`); + delete emoji.list[`:${ alias }:`]; + const aliasIndex = emoji.packages.emojiCustom.list.indexOf(`:${ alias }:`); if (aliasIndex !== -1) { - RocketChat.emoji.packages.emojiCustom.list.splice(aliasIndex, 1); + emoji.packages.emojiCustom.list.splice(aliasIndex, 1); } } } - RocketChat.EmojiPicker.updateRecent(); + EmojiPicker.updateRecent(); }; export const updateEmojiCustom = function(emojiData) { @@ -53,40 +54,40 @@ export const updateEmojiCustom = function(emojiData) { const previousExists = isSetNotNull(() => emojiData.previousName); const currentAliases = isSetNotNull(() => emojiData.aliases); - if (previousExists && isSetNotNull(() => RocketChat.emoji.list[`:${ emojiData.previousName }:`].aliases)) { - for (const alias of RocketChat.emoji.list[`:${ emojiData.previousName }:`].aliases) { - delete RocketChat.emoji.list[`:${ alias }:`]; - const aliasIndex = RocketChat.emoji.packages.emojiCustom.list.indexOf(`:${ alias }:`); + if (previousExists && isSetNotNull(() => emoji.list[`:${ emojiData.previousName }:`].aliases)) { + for (const alias of emoji.list[`:${ emojiData.previousName }:`].aliases) { + delete emoji.list[`:${ alias }:`]; + const aliasIndex = emoji.packages.emojiCustom.list.indexOf(`:${ alias }:`); if (aliasIndex !== -1) { - RocketChat.emoji.packages.emojiCustom.list.splice(aliasIndex, 1); + emoji.packages.emojiCustom.list.splice(aliasIndex, 1); } } } if (previousExists && emojiData.name !== emojiData.previousName) { - const arrayIndex = RocketChat.emoji.packages.emojiCustom.emojisByCategory.rocket.indexOf(emojiData.previousName); + const arrayIndex = emoji.packages.emojiCustom.emojisByCategory.rocket.indexOf(emojiData.previousName); if (arrayIndex !== -1) { - RocketChat.emoji.packages.emojiCustom.emojisByCategory.rocket.splice(arrayIndex, 1); + emoji.packages.emojiCustom.emojisByCategory.rocket.splice(arrayIndex, 1); } - const arrayIndexList = RocketChat.emoji.packages.emojiCustom.list.indexOf(`:${ emojiData.previousName }:`); + const arrayIndexList = emoji.packages.emojiCustom.list.indexOf(`:${ emojiData.previousName }:`); if (arrayIndexList !== -1) { - RocketChat.emoji.packages.emojiCustom.list.splice(arrayIndexList, 1); + emoji.packages.emojiCustom.list.splice(arrayIndexList, 1); } - delete RocketChat.emoji.list[`:${ emojiData.previousName }:`]; + delete emoji.list[`:${ emojiData.previousName }:`]; } - const categoryIndex = RocketChat.emoji.packages.emojiCustom.emojisByCategory.rocket.indexOf(`${ emojiData.name }`); + const categoryIndex = emoji.packages.emojiCustom.emojisByCategory.rocket.indexOf(`${ emojiData.name }`); if (categoryIndex === -1) { - RocketChat.emoji.packages.emojiCustom.emojisByCategory.rocket.push(`${ emojiData.name }`); - RocketChat.emoji.packages.emojiCustom.list.push(`:${ emojiData.name }:`); + emoji.packages.emojiCustom.emojisByCategory.rocket.push(`${ emojiData.name }`); + emoji.packages.emojiCustom.list.push(`:${ emojiData.name }:`); } - RocketChat.emoji.list[`:${ emojiData.name }:`] = Object.assign({ emojiPackage: 'emojiCustom' }, RocketChat.emoji.list[`:${ emojiData.name }:`], emojiData); + emoji.list[`:${ emojiData.name }:`] = Object.assign({ emojiPackage: 'emojiCustom' }, emoji.list[`:${ emojiData.name }:`], emojiData); if (currentAliases) { for (const alias of emojiData.aliases) { - RocketChat.emoji.packages.emojiCustom.list.push(`:${ alias }:`); - RocketChat.emoji.list[`:${ alias }:`] = {}; - RocketChat.emoji.list[`:${ alias }:`].emojiPackage = 'emojiCustom'; - RocketChat.emoji.list[`:${ alias }:`].aliasOf = emojiData.name; + emoji.packages.emojiCustom.list.push(`:${ alias }:`); + emoji.list[`:${ alias }:`] = {}; + emoji.list[`:${ alias }:`].emojiPackage = 'emojiCustom'; + emoji.list[`:${ alias }:`].aliasOf = emojiData.name; } } @@ -119,30 +120,30 @@ export const updateEmojiCustom = function(emojiData) { } } - RocketChat.EmojiPicker.updateRecent(); + EmojiPicker.updateRecent(); }; -RocketChat.emoji.packages.emojiCustom = { +emoji.packages.emojiCustom = { emojiCategories: { rocket: 'Custom' }, toneList: {}, list: [], render(html) { - const regShortNames = new RegExp(`]*>.*?<\/object>|]*>.*?<\/span>|<(?:object|embed|svg|img|div|span|p|a)[^>]*>|(${ RocketChat.emoji.packages.emojiCustom.list.join('|') })`, 'gi'); + const regShortNames = new RegExp(`]*>.*?<\/object>|]*>.*?<\/span>|<(?:object|embed|svg|img|div|span|p|a)[^>]*>|(${ emoji.packages.emojiCustom.list.join('|') })`, 'gi'); // replace regular shortnames first html = html.replace(regShortNames, function(shortname) { // console.log('shortname (preif) ->', shortname, html); - if ((typeof shortname === 'undefined') || (shortname === '') || (RocketChat.emoji.packages.emojiCustom.list.indexOf(shortname) === -1)) { + if ((typeof shortname === 'undefined') || (shortname === '') || (emoji.packages.emojiCustom.list.indexOf(shortname) === -1)) { // if the shortname doesnt exist just return the entire match return shortname; } else { let emojiAlias = shortname.replace(/:/g, ''); - let dataCheck = RocketChat.emoji.list[shortname]; + let dataCheck = emoji.list[shortname]; if (dataCheck.hasOwnProperty('aliasOf')) { emojiAlias = dataCheck.aliasOf; - dataCheck = RocketChat.emoji.list[`:${ emojiAlias }:`]; + dataCheck = emoji.list[`:${ emojiAlias }:`]; } return `${ shortname }`; @@ -154,19 +155,19 @@ RocketChat.emoji.packages.emojiCustom = { }; Meteor.startup(() => - RocketChat.CachedCollectionManager.onLogin(() => { + CachedCollectionManager.onLogin(() => { Meteor.call('listEmojiCustom', (error, result) => { - RocketChat.emoji.packages.emojiCustom.emojisByCategory = { rocket: [] }; - for (const emoji of result) { - RocketChat.emoji.packages.emojiCustom.emojisByCategory.rocket.push(emoji.name); - RocketChat.emoji.packages.emojiCustom.list.push(`:${ emoji.name }:`); - RocketChat.emoji.list[`:${ emoji.name }:`] = emoji; - RocketChat.emoji.list[`:${ emoji.name }:`].emojiPackage = 'emojiCustom'; - for (const alias of emoji.aliases) { - RocketChat.emoji.packages.emojiCustom.list.push(`:${ alias }:`); - RocketChat.emoji.list[`:${ alias }:`] = { + emoji.packages.emojiCustom.emojisByCategory = { rocket: [] }; + for (const currentEmoji of result) { + emoji.packages.emojiCustom.emojisByCategory.rocket.push(currentEmoji.name); + emoji.packages.emojiCustom.list.push(`:${ currentEmoji.name }:`); + emoji.list[`:${ currentEmoji.name }:`] = currentEmoji; + emoji.list[`:${ currentEmoji.name }:`].emojiPackage = 'emojiCustom'; + for (const alias of currentEmoji.aliases) { + emoji.packages.emojiCustom.list.push(`:${ alias }:`); + emoji.list[`:${ alias }:`] = { emojiPackage: 'emojiCustom', - aliasOf: emoji.name, + aliasOf: currentEmoji.name, }; } } diff --git a/packages/rocketchat-emoji-custom/client/notifications/deleteEmojiCustom.js b/packages/rocketchat-emoji-custom/client/notifications/deleteEmojiCustom.js index bcff8efd765e..54a1f446757f 100644 --- a/packages/rocketchat-emoji-custom/client/notifications/deleteEmojiCustom.js +++ b/packages/rocketchat-emoji-custom/client/notifications/deleteEmojiCustom.js @@ -1,7 +1,7 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { Notifications } from 'meteor/rocketchat:notifications'; import { deleteEmojiCustom } from '../lib/emojiCustom'; Meteor.startup(() => - RocketChat.Notifications.onLogged('deleteEmojiCustom', (data) => deleteEmojiCustom(data.emojiData)) + Notifications.onLogged('deleteEmojiCustom', (data) => deleteEmojiCustom(data.emojiData)) ); diff --git a/packages/rocketchat-emoji-custom/client/notifications/updateEmojiCustom.js b/packages/rocketchat-emoji-custom/client/notifications/updateEmojiCustom.js index f6e33743339d..6ee84095130d 100644 --- a/packages/rocketchat-emoji-custom/client/notifications/updateEmojiCustom.js +++ b/packages/rocketchat-emoji-custom/client/notifications/updateEmojiCustom.js @@ -1,7 +1,7 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { Notifications } from 'meteor/rocketchat:notifications'; import { updateEmojiCustom } from '../lib/emojiCustom'; Meteor.startup(() => - RocketChat.Notifications.onLogged('updateEmojiCustom', (data) => updateEmojiCustom(data.emojiData)) + Notifications.onLogged('updateEmojiCustom', (data) => updateEmojiCustom(data.emojiData)) ); diff --git a/packages/rocketchat-emoji-custom/package.js b/packages/rocketchat-emoji-custom/package.js index 87f122eb2bc3..0bbb099c27ea 100644 --- a/packages/rocketchat-emoji-custom/package.js +++ b/packages/rocketchat-emoji-custom/package.js @@ -10,8 +10,13 @@ Package.onUse(function(api) { 'ecmascript', 'rocketchat:emoji', 'rocketchat:file', - 'rocketchat:lib', 'rocketchat:utils', + 'rocketchat:models', + 'rocketchat:settings', + 'rocketchat:authorization', + 'rocketchat:notifications', + 'rocketchat:ui-cached-collection', + 'rocketchat:ui-utils', 'templating', 'webapp', 'kadira:flow-router', diff --git a/packages/rocketchat-emoji-custom/server/index.js b/packages/rocketchat-emoji-custom/server/index.js index cc0b89be8d5b..162ae9a35d14 100644 --- a/packages/rocketchat-emoji-custom/server/index.js +++ b/packages/rocketchat-emoji-custom/server/index.js @@ -1,6 +1,5 @@ import './startup/emoji-custom'; import './startup/settings'; -import './models/EmojiCustom'; import './publications/fullEmojiData'; import './methods/listEmojiCustom'; import './methods/deleteEmojiCustom'; diff --git a/packages/rocketchat-emoji-custom/server/methods/deleteEmojiCustom.js b/packages/rocketchat-emoji-custom/server/methods/deleteEmojiCustom.js index 38d4b6c6ee15..b4f1df41cf38 100644 --- a/packages/rocketchat-emoji-custom/server/methods/deleteEmojiCustom.js +++ b/packages/rocketchat-emoji-custom/server/methods/deleteEmojiCustom.js @@ -1,13 +1,15 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { EmojiCustom } from 'meteor/rocketchat:models'; +import { Notifications } from 'meteor/rocketchat:notifications'; import { RocketChatFileEmojiCustomInstance } from '../startup/emoji-custom'; Meteor.methods({ deleteEmojiCustom(emojiID) { let emoji = null; - if (RocketChat.authz.hasPermission(this.userId, 'manage-emoji')) { - emoji = RocketChat.models.EmojiCustom.findOneByID(emojiID); + if (hasPermission(this.userId, 'manage-emoji')) { + emoji = EmojiCustom.findOneByID(emojiID); } else { throw new Meteor.Error('not_authorized'); } @@ -17,8 +19,8 @@ Meteor.methods({ } RocketChatFileEmojiCustomInstance.deleteFile(encodeURIComponent(`${ emoji.name }.${ emoji.extension }`)); - RocketChat.models.EmojiCustom.removeByID(emojiID); - RocketChat.Notifications.notifyLogged('deleteEmojiCustom', { emojiData: emoji }); + EmojiCustom.removeByID(emojiID); + Notifications.notifyLogged('deleteEmojiCustom', { emojiData: emoji }); return true; }, diff --git a/packages/rocketchat-emoji-custom/server/methods/insertOrUpdateEmoji.js b/packages/rocketchat-emoji-custom/server/methods/insertOrUpdateEmoji.js index 09112918bb5b..40d07322f4ba 100644 --- a/packages/rocketchat-emoji-custom/server/methods/insertOrUpdateEmoji.js +++ b/packages/rocketchat-emoji-custom/server/methods/insertOrUpdateEmoji.js @@ -1,12 +1,14 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { Notifications } from 'meteor/rocketchat:notifications'; +import { EmojiCustom } from 'meteor/rocketchat:models'; import { RocketChatFileEmojiCustomInstance } from '../startup/emoji-custom'; import _ from 'underscore'; import s from 'underscore.string'; Meteor.methods({ insertOrUpdateEmoji(emojiData) { - if (!RocketChat.authz.hasPermission(this.userId, 'manage-emoji')) { + if (!hasPermission(this.userId, 'manage-emoji')) { throw new Meteor.Error('not_authorized'); } @@ -41,14 +43,14 @@ Meteor.methods({ let matchingResults = []; if (emojiData._id) { - matchingResults = RocketChat.models.EmojiCustom.findByNameOrAliasExceptID(emojiData.name, emojiData._id).fetch(); + matchingResults = EmojiCustom.findByNameOrAliasExceptID(emojiData.name, emojiData._id).fetch(); for (const alias of emojiData.aliases) { - matchingResults = matchingResults.concat(RocketChat.models.EmojiCustom.findByNameOrAliasExceptID(alias, emojiData._id).fetch()); + matchingResults = matchingResults.concat(EmojiCustom.findByNameOrAliasExceptID(alias, emojiData._id).fetch()); } } else { - matchingResults = RocketChat.models.EmojiCustom.findByNameOrAlias(emojiData.name).fetch(); + matchingResults = EmojiCustom.findByNameOrAlias(emojiData.name).fetch(); for (const alias of emojiData.aliases) { - matchingResults = matchingResults.concat(RocketChat.models.EmojiCustom.findByNameOrAlias(alias).fetch()); + matchingResults = matchingResults.concat(EmojiCustom.findByNameOrAlias(alias).fetch()); } } @@ -64,9 +66,9 @@ Meteor.methods({ extension: emojiData.extension, }; - const _id = RocketChat.models.EmojiCustom.create(createEmoji); + const _id = EmojiCustom.create(createEmoji); - RocketChat.Notifications.notifyLogged('updateEmojiCustom', { emojiData: createEmoji }); + Notifications.notifyLogged('updateEmojiCustom', { emojiData: createEmoji }); return _id; } else { @@ -77,7 +79,7 @@ Meteor.methods({ RocketChatFileEmojiCustomInstance.deleteFile(encodeURIComponent(`${ emojiData.previousName }.${ emojiData.extension }`)); RocketChatFileEmojiCustomInstance.deleteFile(encodeURIComponent(`${ emojiData.previousName }.${ emojiData.previousExtension }`)); - RocketChat.models.EmojiCustom.setExtension(emojiData._id, emojiData.extension); + EmojiCustom.setExtension(emojiData._id, emojiData.extension); } else if (emojiData.name !== emojiData.previousName) { const rs = RocketChatFileEmojiCustomInstance.getFileWithReadStream(encodeURIComponent(`${ emojiData.previousName }.${ emojiData.previousExtension }`)); if (rs !== null) { @@ -91,16 +93,16 @@ Meteor.methods({ } if (emojiData.name !== emojiData.previousName) { - RocketChat.models.EmojiCustom.setName(emojiData._id, emojiData.name); + EmojiCustom.setName(emojiData._id, emojiData.name); } if (emojiData.aliases) { - RocketChat.models.EmojiCustom.setAliases(emojiData._id, emojiData.aliases); + EmojiCustom.setAliases(emojiData._id, emojiData.aliases); } else { - RocketChat.models.EmojiCustom.setAliases(emojiData._id, []); + EmojiCustom.setAliases(emojiData._id, []); } - RocketChat.Notifications.notifyLogged('updateEmojiCustom', { emojiData }); + Notifications.notifyLogged('updateEmojiCustom', { emojiData }); return true; } diff --git a/packages/rocketchat-emoji-custom/server/methods/listEmojiCustom.js b/packages/rocketchat-emoji-custom/server/methods/listEmojiCustom.js index 876555266596..ebc34347fa1a 100644 --- a/packages/rocketchat-emoji-custom/server/methods/listEmojiCustom.js +++ b/packages/rocketchat-emoji-custom/server/methods/listEmojiCustom.js @@ -1,8 +1,8 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { EmojiCustom } from 'meteor/rocketchat:models'; Meteor.methods({ listEmojiCustom(options = {}) { - return RocketChat.models.EmojiCustom.find(options).fetch(); + return EmojiCustom.find(options).fetch(); }, }); diff --git a/packages/rocketchat-emoji-custom/server/methods/uploadEmojiCustom.js b/packages/rocketchat-emoji-custom/server/methods/uploadEmojiCustom.js index a99da17ffa23..a8d27d449056 100644 --- a/packages/rocketchat-emoji-custom/server/methods/uploadEmojiCustom.js +++ b/packages/rocketchat-emoji-custom/server/methods/uploadEmojiCustom.js @@ -1,11 +1,12 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { Notifications } from 'meteor/rocketchat:notifications'; +import { hasPermission } from 'meteor/rocketchat:authorization'; import { RocketChatFile } from 'meteor/rocketchat:file'; import { RocketChatFileEmojiCustomInstance } from '../startup/emoji-custom'; Meteor.methods({ uploadEmojiCustom(binaryContent, contentType, emojiData) { - if (!RocketChat.authz.hasPermission(this.userId, 'manage-emoji')) { + if (!hasPermission(this.userId, 'manage-emoji')) { throw new Meteor.Error('not_authorized'); } @@ -17,7 +18,7 @@ Meteor.methods({ RocketChatFileEmojiCustomInstance.deleteFile(encodeURIComponent(`${ emojiData.name }.${ emojiData.extension }`)); const ws = RocketChatFileEmojiCustomInstance.createWriteStream(encodeURIComponent(`${ emojiData.name }.${ emojiData.extension }`), contentType); ws.on('end', Meteor.bindEnvironment(() => - Meteor.setTimeout(() => RocketChat.Notifications.notifyLogged('updateEmojiCustom', { emojiData }), 500) + Meteor.setTimeout(() => Notifications.notifyLogged('updateEmojiCustom', { emojiData }), 500) )); rs.pipe(ws); diff --git a/packages/rocketchat-emoji-custom/server/publications/fullEmojiData.js b/packages/rocketchat-emoji-custom/server/publications/fullEmojiData.js index daffef5d2b52..3d5f9ca7ed85 100644 --- a/packages/rocketchat-emoji-custom/server/publications/fullEmojiData.js +++ b/packages/rocketchat-emoji-custom/server/publications/fullEmojiData.js @@ -1,5 +1,5 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { EmojiCustom } from 'meteor/rocketchat:models'; import s from 'underscore.string'; Meteor.publish('fullEmojiData', function(filter, limit) { @@ -23,8 +23,8 @@ Meteor.publish('fullEmojiData', function(filter, limit) { if (filter) { const filterReg = new RegExp(s.escapeRegExp(filter), 'i'); - return RocketChat.models.EmojiCustom.findByNameOrAlias(filterReg, options); + return EmojiCustom.findByNameOrAlias(filterReg, options); } - return RocketChat.models.EmojiCustom.find({}, options); + return EmojiCustom.find({}, options); }); diff --git a/packages/rocketchat-emoji-custom/server/startup/emoji-custom.js b/packages/rocketchat-emoji-custom/server/startup/emoji-custom.js index 7d4ea3b7906c..e58ba8336ad6 100644 --- a/packages/rocketchat-emoji-custom/server/startup/emoji-custom.js +++ b/packages/rocketchat-emoji-custom/server/startup/emoji-custom.js @@ -1,6 +1,6 @@ import { Meteor } from 'meteor/meteor'; import { WebApp } from 'meteor/webapp'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { settings } from 'meteor/rocketchat:settings'; import { RocketChatFile } from 'meteor/rocketchat:file'; import _ from 'underscore'; @@ -9,8 +9,8 @@ export let RocketChatFileEmojiCustomInstance; Meteor.startup(function() { let storeType = 'GridFS'; - if (RocketChat.settings.get('EmojiUpload_Storage_Type')) { - storeType = RocketChat.settings.get('EmojiUpload_Storage_Type'); + if (settings.get('EmojiUpload_Storage_Type')) { + storeType = settings.get('EmojiUpload_Storage_Type'); } const RocketChatStore = RocketChatFile[storeType]; @@ -22,9 +22,9 @@ Meteor.startup(function() { console.log(`Using ${ storeType } for custom emoji storage`.green); let path = '~/uploads'; - if (RocketChat.settings.get('EmojiUpload_FileSystemPath') != null) { - if (RocketChat.settings.get('EmojiUpload_FileSystemPath').trim() !== '') { - path = RocketChat.settings.get('EmojiUpload_FileSystemPath'); + if (settings.get('EmojiUpload_FileSystemPath') != null) { + if (settings.get('EmojiUpload_FileSystemPath').trim() !== '') { + path = settings.get('EmojiUpload_FileSystemPath'); } } diff --git a/packages/rocketchat-emoji-custom/server/startup/settings.js b/packages/rocketchat-emoji-custom/server/startup/settings.js index 2b3e516e8e84..7329bff949c9 100644 --- a/packages/rocketchat-emoji-custom/server/startup/settings.js +++ b/packages/rocketchat-emoji-custom/server/startup/settings.js @@ -1,6 +1,6 @@ -import { RocketChat } from 'meteor/rocketchat:lib'; +import { settings } from 'meteor/rocketchat:settings'; -RocketChat.settings.addGroup('EmojiCustomFilesystem', function() { +settings.addGroup('EmojiCustomFilesystem', function() { this.add('EmojiUpload_Storage_Type', 'GridFS', { type: 'select', values: [{ diff --git a/packages/rocketchat-lib/client/models/index.js b/packages/rocketchat-lib/client/models/index.js index bcf24e138126..9f619d8adc6a 100644 --- a/packages/rocketchat-lib/client/models/index.js +++ b/packages/rocketchat-lib/client/models/index.js @@ -1,4 +1,4 @@ -import { Base as _Base, Avatars, Uploads, UserDataFiles, CustomSounds } from 'meteor/rocketchat:models'; +import { Base as _Base, Avatars, Uploads, UserDataFiles, CustomSounds, EmojiCustom } from 'meteor/rocketchat:models'; Object.assign(RocketChat.models, { _Base, @@ -6,4 +6,5 @@ Object.assign(RocketChat.models, { Uploads, UserDataFiles, CustomSounds, + EmojiCustom, }); diff --git a/packages/rocketchat-lib/server/models/index.js b/packages/rocketchat-lib/server/models/index.js index ebb3c8bd4bc2..09ea0d36112d 100644 --- a/packages/rocketchat-lib/server/models/index.js +++ b/packages/rocketchat-lib/server/models/index.js @@ -15,6 +15,7 @@ import { Base as _Base, Permissions, Roles, + EmojiCustom, } from 'meteor/rocketchat:models'; Object.assign(RocketChat.models, { @@ -34,4 +35,5 @@ Object.assign(RocketChat.models, { IntegrationHistory, Permissions, Roles, + EmojiCustom, }); diff --git a/packages/rocketchat-models/client/index.js b/packages/rocketchat-models/client/index.js index f6fbaee7114a..0185653df2e1 100644 --- a/packages/rocketchat-models/client/index.js +++ b/packages/rocketchat-models/client/index.js @@ -18,6 +18,7 @@ import { UserAndRoom } from './models/UserAndRoom'; import { UserRoles } from './models/UserRoles'; import { AuthzCachedCollection, ChatPermissions } from './models/ChatPermissions'; import CustomSounds from './models/CustomSounds'; +import EmojiCustom from './models/EmojiCustom'; import _ from 'underscore'; const Users = _.extend({}, users, Meteor.users); @@ -49,4 +50,5 @@ export { ChatSubscription, Rooms, CustomSounds, + EmojiCustom, }; diff --git a/packages/rocketchat-emoji-custom/client/models/EmojiCustom.js b/packages/rocketchat-models/client/models/EmojiCustom.js similarity index 59% rename from packages/rocketchat-emoji-custom/client/models/EmojiCustom.js rename to packages/rocketchat-models/client/models/EmojiCustom.js index 79794f59848e..bb70c24fa1a5 100644 --- a/packages/rocketchat-emoji-custom/client/models/EmojiCustom.js +++ b/packages/rocketchat-models/client/models/EmojiCustom.js @@ -1,6 +1,6 @@ -import { RocketChat } from 'meteor/rocketchat:lib'; +import { Base } from './_Base'; -class EmojiCustom extends RocketChat.models._Base { +export class EmojiCustom extends Base { constructor() { super(); this._initModel('custom_emoji'); @@ -19,4 +19,4 @@ class EmojiCustom extends RocketChat.models._Base { } } -RocketChat.models.EmojiCustom = new EmojiCustom(); +export default new EmojiCustom(); diff --git a/packages/rocketchat-models/server/index.js b/packages/rocketchat-models/server/index.js index 54b5dfc3289c..3d3d9e52b3c4 100644 --- a/packages/rocketchat-models/server/index.js +++ b/packages/rocketchat-models/server/index.js @@ -17,6 +17,7 @@ import CustomSounds from './models/CustomSounds'; import Integrations from './models/Integrations'; import IntegrationHistory from './models/IntegrationHistory'; import CredentialTokens from './models/CredentialTokens'; +import EmojiCustom from './models/EmojiCustom'; export { Base, @@ -38,4 +39,5 @@ export { Integrations, IntegrationHistory, CredentialTokens, + EmojiCustom, }; diff --git a/packages/rocketchat-emoji-custom/server/models/EmojiCustom.js b/packages/rocketchat-models/server/models/EmojiCustom.js similarity index 88% rename from packages/rocketchat-emoji-custom/server/models/EmojiCustom.js rename to packages/rocketchat-models/server/models/EmojiCustom.js index babaf960fba0..8f9f676072f5 100644 --- a/packages/rocketchat-emoji-custom/server/models/EmojiCustom.js +++ b/packages/rocketchat-models/server/models/EmojiCustom.js @@ -1,6 +1,6 @@ -import { RocketChat } from 'meteor/rocketchat:lib'; +import { Base } from './_Base'; -class EmojiCustom extends RocketChat.models._Base { +class EmojiCustom extends Base { constructor() { super('custom_emoji'); @@ -88,4 +88,4 @@ class EmojiCustom extends RocketChat.models._Base { } } -RocketChat.models.EmojiCustom = new EmojiCustom(); +export default new EmojiCustom();