Merge pull request #558 from matrix-org/markjh/presentable

Clean up MFileBody.presentableTextForFile
pull/21833/head
David Baker 2016-11-15 16:12:52 +00:00 committed by GitHub
commit 32a5d31f01
1 changed files with 18 additions and 12 deletions

View File

@ -32,24 +32,30 @@ module.exports = React.createClass({
}; };
}, },
/**
* Extracts a human readable label for the file attachment to use as
* link text.
*
* @params {Object} content The "content" key of the matrix event.
* @return {string} the human readable link text for the attachment.
*/
presentableTextForFile: function(content) { presentableTextForFile: function(content) {
var linkText = 'Attachment'; var linkText = 'Attachment';
if (content.body && content.body.length > 0) { if (content.body && content.body.length > 0) {
// The content body should be the name of the file including a
// file extension.
linkText = content.body; linkText = content.body;
} }
var additionals = []; if (content.info && content.info.size) {
if (content.info) { // If we know the size of the file then add it as human readable
// if (content.info.mimetype && content.info.mimetype.length > 0) { // string to the end of the link text so that the user knows how
// additionals.push(content.info.mimetype); // big a file they are downloading.
// } // The content.info also contains a MIME-type but we don't display
if (content.info.size) { // it since it is "ugly", users generally aren't aware what it
additionals.push(filesize(content.info.size)); // means and the type of the attachment can usually be inferrered
} // from the file extension.
} linkText += ' (' + filesize(content.info.size) + ')';
if (additionals.length > 0) {
linkText += ' (' + additionals.join(', ') + ')';
} }
return linkText; return linkText;
}, },