Skip to content

Commit 53e9d03

Browse files
committed
See uploaded files
1 parent 36ecbfc commit 53e9d03

5 files changed

Lines changed: 86 additions & 1 deletion

File tree

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
},
2222
"dependencies": {
2323
"classnames": "^2.1.2",
24+
"filesize": "^3.1.2",
2425
"flux": "^2.0.3",
2526
"matrix-js-sdk": "0.1.1",
2627
"q": "^1.4.1",
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
Copyright 2015 OpenMarket Ltd
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
var React = require('react');
20+
var filesize = require('filesize');
21+
22+
var MFileTileController = require("../../../../src/controllers/molecules/MFileTile");
23+
24+
var MatrixClientPeg = require('../../../../src/MatrixClientPeg');
25+
26+
module.exports = React.createClass({
27+
displayName: 'MFileTile',
28+
mixins: [MFileTileController],
29+
30+
render: function() {
31+
var content = this.props.mxEvent.getContent();
32+
var cli = MatrixClientPeg.get();
33+
34+
return (
35+
<span className="mx_MFileTile">
36+
<a href={cli.mxcUrlToHttp(content.url)}>
37+
{this.presentableTextForFile(content)}
38+
</a>
39+
</span>
40+
);
41+
},
42+
});

‎skins/base/views/molecules/MessageTile.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ var tileTypes = {
3131
'm.text': ComponentBroker.get('molecules/MTextTile'),
3232
'm.notice': ComponentBroker.get('molecules/MNoticeTile'),
3333
'm.emote': ComponentBroker.get('molecules/MEmoteTile'),
34-
'm.image': ComponentBroker.get('molecules/MImageTile')
34+
'm.image': ComponentBroker.get('molecules/MImageTile'),
35+
'm.file': ComponentBroker.get('molecules/MFileTile')
3536
};
3637

3738
var MessageTileController = require("../../../../src/controllers/molecules/MessageTile");

‎src/ComponentBroker.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ require('../skins/base/views/molecules/MTextTile');
7070
require('../skins/base/views/molecules/MNoticeTile');
7171
require('../skins/base/views/molecules/MEmoteTile');
7272
require('../skins/base/views/molecules/MImageTile');
73+
require('../skins/base/views/molecules/MFileTile');
7374
require('../skins/base/views/molecules/MRoomMemberTile');
7475
require('../skins/base/views/molecules/RoomHeader');
7576
require('../skins/base/views/molecules/MessageComposer');
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Copyright 2015 OpenMarket Ltd
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
module.exports = {
20+
presentableTextForFile: function(content) {
21+
var linkText = 'Attachment';
22+
if (content.body && content.body.length > 0) {
23+
linkText = content.body;
24+
}
25+
26+
var additionals = [];
27+
if (content.info.mimetype && content.info.mimetype.length > 0) {
28+
additionals.push(content.info.mimetype);
29+
}
30+
if (content.info.size && content.info.size.length > 0) {
31+
additionals.push(filesize(content.info.size));
32+
}
33+
34+
if (additionals.length > 0) {
35+
linkText += ' (' + additionals.join(',') + ')';
36+
}
37+
return linkText;
38+
}
39+
};
40+

0 commit comments

Comments
 (0)