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/packages/rocketchat-lib/lib/messageBox.js

66 lines
1.5 KiB

import EventEmitter from 'wolfy87-eventemitter';
RocketChat.messageBox = new EventEmitter;
RocketChat.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());
}
8 years ago
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);
8 years ago
}
};