From 595493e5bb3354d81654bbcda136c4cc68f30c7a Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Tue, 15 Nov 2016 15:54:14 +0000 Subject: [PATCH] Clean up MFileBody.presentableTextForFile --- src/components/views/messages/MFileBody.js | 30 +++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/components/views/messages/MFileBody.js b/src/components/views/messages/MFileBody.js index e8c97e5f44..3f29915561 100644 --- a/src/components/views/messages/MFileBody.js +++ b/src/components/views/messages/MFileBody.js @@ -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) { var linkText = 'Attachment'; if (content.body && content.body.length > 0) { + // The content body should be the name of the file including a + // file extension. linkText = content.body; } - var additionals = []; - if (content.info) { - // if (content.info.mimetype && content.info.mimetype.length > 0) { - // additionals.push(content.info.mimetype); - // } - if (content.info.size) { - additionals.push(filesize(content.info.size)); - } - } - - if (additionals.length > 0) { - linkText += ' (' + additionals.join(', ') + ')'; + if (content.info && content.info.size) { + // If we know the size of the file then add it as human readable + // string to the end of the link text so that the user knows how + // big a file they are downloading. + // The content.info also contains a MIME-type but we don't display + // it since it is "ugly", users generally aren't aware what it + // means and the type of the attachment can usually be inferrered + // from the file extension. + linkText += ' (' + filesize(content.info.size) + ')'; } return linkText; },