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/client/methods/sendMessage.js

28 lines
879 B

import { Meteor } from 'meteor/meteor';
import s from 'underscore.string';
Meteor.methods({
sendMessage(message) {
if (!Meteor.userId() || s.trim(message.msg) === '') {
return false;
}
const user = Meteor.user();
message.ts = isNaN(TimeSync.serverOffset()) ? new Date() : new Date(Date.now() + TimeSync.serverOffset());
message.u = {
_id: Meteor.userId(),
username: user.username,
};
if (RocketChat.settings.get('UI_Use_Real_Name')) {
message.u.name = user.name;
}
message.temp = true;
if (RocketChat.settings.get('Message_Read_Receipt_Enabled')) {
message.unread = true;
}
message = RocketChat.callbacks.run('beforeSaveMessage', message);
RocketChat.promises.run('onClientMessageReceived', message).then(function(message) {
ChatMessage.insert(message);
return RocketChat.callbacks.run('afterSaveMessage', message);
});
},
});