mirror of https://github.com/vector-im/riot-web
Merge pull request #558 from matrix-org/markjh/presentable
Clean up MFileBody.presentableTextForFilepull/21833/head
commit
32a5d31f01
|
@ -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;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue