-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6593 from ggazzo/rocketchat-lib2
Rocketchat lib2
- Loading branch information
Showing
21 changed files
with
528 additions
and
391 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; | ||
} | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); |
Oops, something went wrong.