Skip to content

Commit

Permalink
Merge pull request #6500 from ggazzo/rocketchat-message-attachments
Browse files Browse the repository at this point in the history
converted messageAttachment coffee to js
  • Loading branch information
engelgabriel authored Mar 29, 2017
2 parents c5708f5 + 4e1d31e commit d408fa7
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 64 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import moment from 'moment';
const colors = {
good: '#35AC19',
warning: '#FCB316',
danger: '#D30230'
};
const fixCordova = function(url) {
if (url && url.indexOf('data:image') === 0) {
return url;
}
if (Meteor.isCordova && (url && url[0] === '/')) {
url = Meteor.absoluteUrl().replace(/\/$/, '') + url;
const query = `rc_uid=${ Meteor.userId() }&rc_token=${ Meteor._localStorage.getItem('Meteor.loginToken') }`;
if (url.indexOf('?') === -1) {
url = `${ url }?${ query }`;
} else {
url = `${ url }&${ query }`;
}
}
if (Meteor.settings['public'].sandstorm || url.match(/^(https?:)?\/\//i)) {
return url;
} else if (navigator.userAgent.indexOf('Electron') > -1) {
return __meteor_runtime_config__.ROOT_URL_PATH_PREFIX + url;
} else {
return Meteor.absoluteUrl().replace(/\/$/, '') + __meteor_runtime_config__.ROOT_URL_PATH_PREFIX + url;
}
};
/*globals renderMessageBody*/
Template.messageAttachment.helpers({
fixCordova,
parsedText() {
return renderMessageBody({
msg: this.text
});
},
loadImage() {
const user = Meteor.user();
if (user && user.settings && user.settings.preferences && this.downloadImages !== true) {
if (user.settings.preferences.autoImageLoad === false) {
return false;
}
if (Meteor.Device.isPhone() && user.settings.preferences.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;
} else {
const user = Meteor.user();
return user && user.settings && user.settings.preferences && user.settings.preferences.collapseMediaByDefault === true;
}
},
time() {
const messageDate = new Date(this.ts);
const today = new Date();
if (messageDate.toDateString() === today.toDateString()) {
return moment(this.ts).format(RocketChat.settings.get('Message_TimeFormat'));
} else {
return moment(this.ts).format(RocketChat.settings.get('Message_TimeAndDateFormat'));
}
},
injectIndex(data, previousIndex, index) {
data.index = `${ previousIndex }.attachments.${ index }`;
}
});
2 changes: 1 addition & 1 deletion packages/rocketchat-message-attachments/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Package.onUse(function(api) {
]);

api.addFiles('client/messageAttachment.html', 'client');
api.addFiles('client/messageAttachment.coffee', 'client');
api.addFiles('client/messageAttachment.js', 'client');

// stylesheets
api.addFiles('client/stylesheets/messageAttachments.less', 'client');
Expand Down

0 comments on commit d408fa7

Please sign in to comment.