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-file-upload/server/methods/sendFileMessage.js

59 lines
1.5 KiB

Meteor.methods({
'sendFileMessage'(roomId, store, file, msgData = {}) {
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'sendFileMessage' });
}
var room = Meteor.call('canAccessRoom', roomId, Meteor.userId());
if (!room) {
return false;
}
check(msgData, {
avatar: Match.Optional(String),
emoji: Match.Optional(String),
alias: Match.Optional(String),
msg: Match.Optional(String)
});
RocketChat.models.Uploads.updateFileComplete(file._id, Meteor.userId(), _.omit(file, '_id'));
var fileUrl = '/file-upload/' + file._id + '/' + file.name;
var attachment = {
title: `${TAPi18n.__('Attachment_File_Uploaded')}: ${file.name}`,
title_link: fileUrl,
title_link_download: true
};
if (/^image\/.+/.test(file.type)) {
attachment.image_url = fileUrl;
attachment.image_type = file.type;
attachment.image_size = file.size;
if (file.identify && file.identify.size) {
attachment.image_dimensions = file.identify.size;
}
} else if (/^audio\/.+/.test(file.type)) {
attachment.audio_url = fileUrl;
attachment.audio_type = file.type;
attachment.audio_size = file.size;
} else if (/^video\/.+/.test(file.type)) {
attachment.video_url = fileUrl;
attachment.video_type = file.type;
attachment.video_size = file.size;
}
const msg = Object.assign({ msg: '' }, msgData, {
_id: Random.id(),
rid: roomId,
file: {
_id: file._id
},
groupable: false,
attachments: [attachment]
});
return Meteor.call('sendMessage', msg);
}
});