Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rocketchat lib2 #6593

Merged
merged 4 commits into from
Apr 19, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions packages/rocketchat-lib/lib/Message.coffee

This file was deleted.

29 changes: 29 additions & 0 deletions packages/rocketchat-lib/lib/Message.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
RocketChat.Message = {
parse(msg, language) {
const messageType = RocketChat.MessageTypes.getType(msg);
if (messageType) {
if (messageType.render) {
return messageType.render(msg);
} else if (messageType.template) {
// Render message
return;
} else if (messageType.message) {
if (!language && typeof localStorage !== 'undefined') {
language = localStorage.getItem('userLanguage');
}
const data = (typeof messageType.data === 'function' && messageType.data(msg)) || {};
return TAPi18n.__(messageType.message, data, language);
}
}
if (msg.u && msg.u.username === RocketChat.settings.get('Chatops_Username')) {
msg.html = msg.msg;
return msg.html;
}
msg.html = msg.msg;
if (_.trim(msg.html) !== '') {
msg.html = _.escapeHTML(msg.html);
}
msg.html = msg.html.replace(/\n/gm, '<br/>');
return msg.html;
}
};
112 changes: 0 additions & 112 deletions packages/rocketchat-lib/lib/MessageTypes.coffee

This file was deleted.

167 changes: 167 additions & 0 deletions packages/rocketchat-lib/lib/MessageTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
RocketChat.MessageTypes = new class {
constructor() {
this.types = {};
}

registerType(options) {
return this.types[options.id] = options;
}

getType(message) {
return this.types[message && message.t];
}

isSystemMessage(message) {
const type = this.types[message && message.t];
return type && type.system;
}

};

Meteor.startup(function() {
RocketChat.MessageTypes.registerType({
id: 'r',
system: true,
message: 'Room_name_changed',
data(message) {
return {
room_name: message.msg,
user_by: message.u.username
};
}
});
RocketChat.MessageTypes.registerType({
id: 'au',
system: true,
message: 'User_added_by',
data(message) {
return {
user_added: message.msg,
user_by: message.u.username
};
}
});
RocketChat.MessageTypes.registerType({
id: 'ru',
system: true,
message: 'User_removed_by',
data(message) {
return {
user_removed: message.msg,
user_by: message.u.username
};
}
});
RocketChat.MessageTypes.registerType({
id: 'ul',
system: true,
message: 'User_left',
data(message) {
return {
user_left: message.u.username
};
}
});
RocketChat.MessageTypes.registerType({
id: 'uj',
system: true,
message: 'User_joined_channel',
data(message) {
return {
user: message.u.username
};
}
});
RocketChat.MessageTypes.registerType({
id: 'wm',
system: true,
message: 'Welcome',
data(message) {
return {
user: message.u.username
};
}
});
RocketChat.MessageTypes.registerType({
id: 'rm',
system: true,
message: 'Message_removed',
data(message) {
return {
user: message.u.username
};
}
});
RocketChat.MessageTypes.registerType({
id: 'rtc',
render(message) {
return RocketChat.callbacks.run('renderRtcMessage', message);
}
});
RocketChat.MessageTypes.registerType({
id: 'user-muted',
system: true,
message: 'User_muted_by',
data(message) {
return {
user_muted: message.msg,
user_by: message.u.username
};
}
});
RocketChat.MessageTypes.registerType({
id: 'user-unmuted',
system: true,
message: 'User_unmuted_by',
data(message) {
return {
user_unmuted: message.msg,
user_by: message.u.username
};
}
});
RocketChat.MessageTypes.registerType({
id: 'subscription-role-added',
system: true,
message: '__username__was_set__role__by__user_by_',
data(message) {
return {
username: message.msg,
role: message.role,
user_by: message.u.username
};
}
});
RocketChat.MessageTypes.registerType({
id: 'subscription-role-removed',
system: true,
message: '__username__is_no_longer__role__defined_by__user_by_',
data(message) {
return {
username: message.msg,
role: message.role,
user_by: message.u.username
};
}
});
RocketChat.MessageTypes.registerType({
id: 'room-archived',
system: true,
message: 'This_room_has_been_archived_by__username_',
data(message) {
return {
username: message.u.username
};
}
});
RocketChat.MessageTypes.registerType({
id: 'room-unarchived',
system: true,
message: 'This_room_has_been_unarchived_by__username_',
data(message) {
return {
username: message.u.username
};
}
});
});
26 changes: 0 additions & 26 deletions packages/rocketchat-lib/lib/slashCommand.coffee

This file was deleted.

31 changes: 31 additions & 0 deletions packages/rocketchat-lib/lib/slashCommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
RocketChat.slashCommands = {
commands: {}
};

RocketChat.slashCommands.add = function(command, callback, options = {}, result) {
RocketChat.slashCommands.commands[command] = {
command,
callback,
params: options.params,
description: options.description,
clientOnly: options.clientOnly || false,
result
};
};

RocketChat.slashCommands.run = function(command, params, item) {
if (RocketChat.slashCommands.commands[command] && RocketChat.slashCommands.commands[command].callback) {
return RocketChat.slashCommands.commands[command].callback(command, params, item);
}
};

Meteor.methods({
slashCommand(command) {
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'slashCommand'
});
}
return RocketChat.slashCommands.run(command.cmd, command.params, command.msg);
}
});
Loading