The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Rocket.Chat/app/ui-utils/client/lib/messageBox.js

66 lines
1.4 KiB

Convert rocketchat-ui-sidenav to main module structure (#13098) * Move rocketchat settings to specific package * WIP: Move models from rocketchat-lib to a specific package (server) * Move function from rocketchat:lib to rocketchat:utils to use it in rocketchat:models * Move client models from rocketchat:lib to rocketchat:models * Fix lint * Move rocketchat.info from lib to utils * Remove directly dependency between lib and migrations * Move statistics Model to rocketchat:models * Create rocketchat:metrics to be able to depacking rocketchat callbacks * Move callbacks to specific package * Remove unused dependency * Move rocketchat-notifications to a specific package * Move rocketchat-promises to a specific package * remove directly dependency from metrics and models * Move CachedCollection from lib to models * Move ui models/collections from ui to models * Move authorization client/ui models to rocketchat:models to be able to remove lib dependency * Creation of rocketchat:ui-utils to help decouple rocketchat:lib and rocketchat:authz * Move some common functions to rocketchat:utils * Change imports to dynamic imports to avoid directly dependency between some packages * Move authz models to rocketchat:models * Remove directly dependency between rocketchat:authz and rocketchat:lib * Move some functions from rocketchat:lib to rocketchat:utils * Add functions to settings package * Convert rocketchat:file-upload to main module structure * Import FileUpload where it is being used * Remove FileUpload and fileUploadHandler from globals eslintrc * Move some functions to rocketchat:ui-utils * Remove directly dependency between rocketchat:authorization and rocketchat:ui-utils * Remove dependency between lazy-load and lib * Change imports of renderMessageBody from ui-message to ui-utils * Add import of main ready from ui-utils * Convert rocketchat-ui-sidenav to main module structure * Add imports of toolbarSearch from ui-sidenav * Remove toolbarSearch from eslintrc globals * Merge branch 'develop' into globals/move-rocketchat-callbacks * Fix import missed objects inside RocketChat namespace * Fix lint * Remove duplicated code inside rocketchat:lib * Remove unused file
7 years ago
import EventEmitter from 'wolfy87-eventemitter';
export const messageBox = new EventEmitter;
messageBox.actions = new class {
constructor() {
this.actions = {};
}
/* Add a action to messagebox
@param group
@param label
@param config
icon: icon class
action: action function
condition: condition to display the action
*/
add(group, label, config) {
if (!group && !label && !config) {
return;
}
if (!this.actions[group]) {
this.actions[group] = [];
}
const actionExists = this.actions[group].find((action) => action.label === label);
if (actionExists) {
return;
}
this.actions[group].push({ ...config, label });
}
remove(group, expression) {
if (!group || !this.actions[group]) {
return false;
}
return (this.actions[group] = this.actions[group].filter((action) => expression.test(action.id)));
}
get(group) {
if (!group) {
return Object.keys(this.actions).reduce((ret, key) => {
const actions = this.actions[key].filter((action) => !action.condition || action.condition());
if (actions.length) {
ret[key] = actions;
}
return ret;
}, {});
}
return this.actions[group].filter((action) => !action.condition || action.condition());
}
getById(id) {
const messageActions = this.actions;
let actions = [];
Object.keys(messageActions).forEach(function(action) {
actions = actions.concat(messageActions[action]);
});
return actions.filter((action) => action.id === id);
}
};