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

85 lines
2.2 KiB

import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';
import { Random } from 'meteor/random';
import _ from 'underscore';
Meteor.methods({
async sendFileMessage(roomId, store, file, msgData = {}) {
if (!Meteor.userId()) {
Change meteor error (#2969) * Add function to handle errors * Delete message errors * handle error for hideRoom * Allow returning error instead of calling toastr.error * Handle error for leaveRoom * handle error for openRoom * handleError for toggleFavorite * handleError in updateMessage * error for samlLogout * handleError for assets * Add global handleError to eslint * handleError for addOAuthService * handleError: getUserRoles * handleError: insertOrUpdateUsere * handleError: messageDeleting * handleError: removeUserFromRoles * handleError: addPermissionToRole * handleError: addUserToRole * handleError: deleteRole * handleError: removeRoleFromPermission * handleError: removeUserFromRole * handleError: saveRole * Return ready on publish without permission * handleError: channel-settings * handleError: mailMessages * handleError: fileUpload * handleError: rocketchat-importer * handleError: addIncomingIntegration * handleError: deleteIncomingIntegration * handleError: updateIncomingIntegration * handleError: addOutgoingIntegration * handleError: deleteOutgoingIntegration * handleError: updateOutgoingIntegration * Return ready on publish without permission * handleError ldap * remove throw from client code * handleError: setEmail, slashCommand * Sort en.i18n.json * Google translated languages * Use correct error return from publishes * RateLimiter.limitFunction * Fix order of error "500" * handleError validateEmailDomain * handleError channelSettings; settings * handleError livechat * handleError: Mailer.sendMail * handleError pinMessage and unpinMessage * handleError messageStarring * handleError oauth apps * handleError: saveNotificationSettings * handleError getRoomRoles * handleError: createDirectMessage * handleError saveUserPreferences * handleError: saveUserProfile * handleError sendConfirmationEmail * Add ecmascript to root
10 years ago
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'sendFileMessage' });
}
const 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),
groupable: Match.Optional(Boolean),
msg: Match.Optional(String),
});
RocketChat.models.Uploads.updateFileComplete(file._id, Meteor.userId(), _.omit(file, '_id'));
const fileUrl = `/file-upload/${ file._id }/${ encodeURI(file.name) }`;
const attachment = {
title: file.name,
type: 'file',
description: file.description,
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;
}
try {
attachment.image_preview = await FileUpload.resizeImagePreview(file);
} catch (e) {
delete attachment.image_url;
delete attachment.image_type;
delete attachment.image_size;
delete attachment.image_dimensions;
}
} 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 user = Meteor.user();
let msg = Object.assign({
_id: Random.id(),
rid: roomId,
ts: new Date(),
msg: '',
file: {
_id: file._id,
name: file.name,
type: file.type,
},
groupable: false,
attachments: [attachment],
}, msgData);
msg = Meteor.call('sendMessage', msg);
Enhance outgoing webhooks and add history (#5823) * Convert the majority of the integrations package to JavaScript * Move the trigger handler to it's own class * Start trying to generalize integration items * Yay, additional events trigger outgoing webhooks * Silence codacy and fix eslint problems. * Started work on user created event for outgoing integrations * Finish the outgoing integration work on the user created event. * Add user join and leave room events for outgoing webhooks * Add fields to the rest api integration creation and clean up the processWebhookMessage * Add the HTTP to the incoming webhook context * Don't check for property on result if it isn't there. Closes #4175, #5762, and #5896. * Add archive room and file upload events for the webhooks * Disable integrations when the user to run/post as gets deleted. * Try to fix the tests failing due to the requird events property * Add history of integration which get fired * Add the missing file for the IntegrationHistory * Fix deleting users being broke due to my code * Add the outgoing webhook integration history viewing page along with v1 rest api to retrieve it * Integration history replays are now enabled along with advanced settings * Work on the advanced settings and enable paging on the integration history * Enable i18n for the history and advanced settings * Update the wording on the word placement * Move migration to be 88 now. * Add missing translations for the webhooks * Fix en.i18n.json identation * Fix integrations.html indentation * Fix more identations * Fix identation of integrationsOutgoing.html
9 years ago
Meteor.defer(() => RocketChat.callbacks.run('afterFileUpload', { user, room, message: msg }));
Enhance outgoing webhooks and add history (#5823) * Convert the majority of the integrations package to JavaScript * Move the trigger handler to it's own class * Start trying to generalize integration items * Yay, additional events trigger outgoing webhooks * Silence codacy and fix eslint problems. * Started work on user created event for outgoing integrations * Finish the outgoing integration work on the user created event. * Add user join and leave room events for outgoing webhooks * Add fields to the rest api integration creation and clean up the processWebhookMessage * Add the HTTP to the incoming webhook context * Don't check for property on result if it isn't there. Closes #4175, #5762, and #5896. * Add archive room and file upload events for the webhooks * Disable integrations when the user to run/post as gets deleted. * Try to fix the tests failing due to the requird events property * Add history of integration which get fired * Add the missing file for the IntegrationHistory * Fix deleting users being broke due to my code * Add the outgoing webhook integration history viewing page along with v1 rest api to retrieve it * Integration history replays are now enabled along with advanced settings * Work on the advanced settings and enable paging on the integration history * Enable i18n for the history and advanced settings * Update the wording on the word placement * Move migration to be 88 now. * Add missing translations for the webhooks * Fix en.i18n.json identation * Fix integrations.html indentation * Fix more identations * Fix identation of integrationsOutgoing.html
9 years ago
return msg;
},
});