Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Clean up MFileBody.presentableTextForFile
Browse files Browse the repository at this point in the history
  • Loading branch information
NegativeMjark committed Nov 15, 2016
1 parent bb776c2 commit 595493e
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/components/views/messages/MFileBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down

0 comments on commit 595493e

Please sign in to comment.