parent
9508f2cb44
commit
69b9d3d49f
@ -1,63 +0,0 @@ |
|||||||
import moment from 'moment' |
|
||||||
|
|
||||||
fixCordova = (url) -> |
|
||||||
if url?.indexOf('data:image') is 0 |
|
||||||
return url |
|
||||||
|
|
||||||
if Meteor.isCordova and url?[0] is '/' |
|
||||||
url = Meteor.absoluteUrl().replace(/\/$/, '') + url |
|
||||||
query = "rc_uid=#{Meteor.userId()}&rc_token=#{Meteor._localStorage.getItem('Meteor.loginToken')}" |
|
||||||
if url.indexOf('?') is -1 |
|
||||||
url = url + '?' + query |
|
||||||
else |
|
||||||
url = url + '&' + query |
|
||||||
|
|
||||||
if Meteor.settings.public.sandstorm or 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 |
|
||||||
|
|
||||||
Template.messageAttachment.helpers |
|
||||||
fixCordova: fixCordova |
|
||||||
|
|
||||||
parsedText: -> |
|
||||||
renderMessageBody { msg: this.text } |
|
||||||
|
|
||||||
loadImage: -> |
|
||||||
if Meteor.user()?.settings?.preferences?.autoImageLoad is false and this.downloadImages? is not true |
|
||||||
return false |
|
||||||
|
|
||||||
if Meteor.Device.isPhone() and Meteor.user()?.settings?.preferences?.saveMobileBandwidth and this.downloadImages? is not true |
|
||||||
return false |
|
||||||
|
|
||||||
return true |
|
||||||
|
|
||||||
getImageHeight: (height) -> |
|
||||||
return height or 200 |
|
||||||
|
|
||||||
color: -> |
|
||||||
switch @color |
|
||||||
when 'good' then return '#35AC19' |
|
||||||
when 'warning' then return '#FCB316' |
|
||||||
when 'danger' then return '#D30230' |
|
||||||
else return @color |
|
||||||
|
|
||||||
collapsed: -> |
|
||||||
if this.collapsed? |
|
||||||
return this.collapsed |
|
||||||
else |
|
||||||
return Meteor.user()?.settings?.preferences?.collapseMediaByDefault is true |
|
||||||
|
|
||||||
time: -> |
|
||||||
messageDate = new Date(@ts) |
|
||||||
today = new Date() |
|
||||||
if messageDate.toDateString() is today.toDateString() |
|
||||||
return moment(@ts).format(RocketChat.settings.get('Message_TimeFormat')) |
|
||||||
else |
|
||||||
return moment(@ts).format(RocketChat.settings.get('Message_TimeAndDateFormat')) |
|
||||||
|
|
||||||
injectIndex: (data, previousIndex, index) -> |
|
||||||
data.index = previousIndex + '.attachments.' + index |
|
||||||
return |
|
||||||
@ -0,0 +1,80 @@ |
|||||||
|
import moment from 'moment'; |
||||||
|
|
||||||
|
const fixCordova = function(url) { |
||||||
|
let query; |
||||||
|
if (url && url.indexOf('data:image') === 0) { |
||||||
|
return url; |
||||||
|
} |
||||||
|
if (Meteor.isCordova && (url && url[0] === '/')) { |
||||||
|
url = Meteor.absoluteUrl().replace(/\/$/, '') + url; |
||||||
|
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) { |
||||||
|
return height || 200; |
||||||
|
}, |
||||||
|
color() { |
||||||
|
switch (this.color) { |
||||||
|
case 'good': |
||||||
|
return '#35AC19'; |
||||||
|
case 'warning': |
||||||
|
return '#FCB316'; |
||||||
|
case 'danger': |
||||||
|
return '#D30230'; |
||||||
|
default: |
||||||
|
return 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 }`; |
||||||
|
} |
||||||
|
}); |
||||||
Loading…
Reference in new issue