-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6500 from ggazzo/rocketchat-message-attachments
converted messageAttachment coffee to js
- Loading branch information
Showing
3 changed files
with
75 additions
and
64 deletions.
There are no files selected for viewing
63 changes: 0 additions & 63 deletions
63
packages/rocketchat-message-attachments/client/messageAttachment.coffee
This file was deleted.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
packages/rocketchat-message-attachments/client/messageAttachment.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }`; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters