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/app/message-attachments/client/messageAttachment.js

85 lines
1.8 KiB

import { Template } from 'meteor/templating';
import { DateFormat } from '../../lib';
import { getURL } from '../../utils/client';
import { renderMessageBody } from '../../ui-utils';
const colors = {
good: '#35AC19',
warning: '#FCB316',
danger: '#D30230',
};
Template.messageAttachment.helpers({
parsedText() {
return renderMessageBody({
msg: this.text,
});
},
markdownInPretext() {
return this.mrkdwn_in && this.mrkdwn_in.includes('pretext');
},
parsedPretext() {
return renderMessageBody({
msg: this.pretext,
});
},
loadImage() {
if (this.downloadImages) {
return true;
}
if (this.settings.autoImageLoad === false) {
return false;
}
if (this.settings.saveMobileBandwidth === true) {
return false;
}
return true;
},
getImageHeight(height = 200) {
return height;
},
color() {
return colors[this.color] || this.color;
},
collapsed() {
if (this.collapsed != null) {
return this.collapsed;
}
return false;
},
mediaCollapsed() {
if (this.collapsed != null) {
return this.collapsed;
}
return this.settings.collapseMediaByDefault === true;
},
time() {
const messageDate = new Date(this.ts);
const today = new Date();
if (messageDate.toDateString() === today.toDateString()) {
return DateFormat.formatTime(this.ts);
}
return DateFormat.formatDateAndTime(this.ts);
},
injectIndex(data, previousIndex, index) {
data.index = `${ previousIndex }.attachments.${ index }`;
},
injectSettings(data, settings) {
data.settings = settings;
},
isFile() {
return this.type === 'file';
},
isPDF() {
if (this.type === 'file' && this.title_link.endsWith('.pdf') && Template.parentData().msg.file) {
this.fileId = Template.parentData().msg.file._id;
return true;
}
return false;
},
getURL,
});