2016-08-31 10:58:06 +00:00
|
|
|
/*
|
|
|
|
Copyright 2016 OpenMarket Ltd
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2017-05-23 14:16:31 +00:00
|
|
|
import React from 'react';
|
2016-08-31 10:58:06 +00:00
|
|
|
|
2017-05-23 14:16:31 +00:00
|
|
|
import Matrix from 'matrix-js-sdk';
|
|
|
|
import sdk from '../../index';
|
|
|
|
import MatrixClientPeg from '../../MatrixClientPeg';
|
2017-11-13 19:19:33 +00:00
|
|
|
import { _t } from '../../languageHandler';
|
2016-08-31 10:58:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Component which shows the filtered file using a TimelinePanel
|
|
|
|
*/
|
2017-10-11 16:56:17 +00:00
|
|
|
const FilePanel = React.createClass({
|
2016-08-31 10:58:06 +00:00
|
|
|
displayName: 'FilePanel',
|
|
|
|
|
2016-09-05 23:59:17 +00:00
|
|
|
propTypes: {
|
|
|
|
roomId: React.PropTypes.string.isRequired,
|
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
timelineSet: null,
|
2017-01-20 14:22:27 +00:00
|
|
|
};
|
2016-09-05 23:59:17 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
componentWillMount: function() {
|
2016-09-07 14:43:14 +00:00
|
|
|
this.updateTimelineSet(this.props.roomId);
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillReceiveProps: function(nextProps) {
|
|
|
|
if (nextProps.roomId !== this.props.roomId) {
|
2016-09-07 15:09:44 +00:00
|
|
|
// otherwise we race between re-rendering the TimelinePanel and setting the new timelineSet.
|
|
|
|
//
|
|
|
|
// FIXME: this race only happens because of the promise returned by getOrCreateFilter().
|
|
|
|
// We should only need to create the containsUrl filter once per login session, so in practice
|
|
|
|
// it shouldn't be being done here at all. Then we could just update the timelineSet directly
|
|
|
|
// without resetting it first, and speed up room-change.
|
2016-09-07 14:43:14 +00:00
|
|
|
this.setState({ timelineSet: null });
|
|
|
|
this.updateTimelineSet(nextProps.roomId);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
updateTimelineSet: function(roomId) {
|
2017-10-11 16:56:17 +00:00
|
|
|
const client = MatrixClientPeg.get();
|
|
|
|
const room = client.getRoom(roomId);
|
2016-09-07 14:43:14 +00:00
|
|
|
|
2017-05-12 21:38:57 +00:00
|
|
|
this.noRoom = !room;
|
|
|
|
|
2016-09-07 14:43:14 +00:00
|
|
|
if (room) {
|
2017-10-11 16:56:17 +00:00
|
|
|
const filter = new Matrix.Filter(client.credentials.userId);
|
2016-09-05 23:59:17 +00:00
|
|
|
filter.setDefinition(
|
|
|
|
{
|
|
|
|
"room": {
|
|
|
|
"timeline": {
|
2017-10-11 16:56:17 +00:00
|
|
|
"contains_url": true,
|
2016-09-05 23:59:17 +00:00
|
|
|
},
|
2017-10-11 16:56:17 +00:00
|
|
|
},
|
|
|
|
},
|
2016-09-05 23:59:17 +00:00
|
|
|
);
|
|
|
|
|
2016-09-07 15:09:44 +00:00
|
|
|
// FIXME: we shouldn't be doing this every time we change room - see comment above.
|
2016-09-05 23:59:17 +00:00
|
|
|
client.getOrCreateFilter("FILTER_FILES_" + client.credentials.userId, filter).then(
|
|
|
|
(filterId)=>{
|
2016-09-07 01:16:29 +00:00
|
|
|
filter.filterId = filterId;
|
2017-10-11 16:56:17 +00:00
|
|
|
const timelineSet = room.getOrCreateFilteredTimelineSet(filter);
|
2016-09-05 23:59:17 +00:00
|
|
|
this.setState({ timelineSet: timelineSet });
|
|
|
|
},
|
|
|
|
(error)=>{
|
|
|
|
console.error("Failed to get or create file panel filter", error);
|
2017-10-11 16:56:17 +00:00
|
|
|
},
|
2016-09-05 23:59:17 +00:00
|
|
|
);
|
2017-05-12 21:38:57 +00:00
|
|
|
} else {
|
2016-09-05 23:59:17 +00:00
|
|
|
console.error("Failed to add filtered timelineSet for FilePanel as no room!");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-08-31 10:58:06 +00:00
|
|
|
render: function() {
|
2017-05-15 09:15:35 +00:00
|
|
|
if (MatrixClientPeg.get().isGuest()) {
|
|
|
|
return <div className="mx_FilePanel mx_RoomView_messageListWrapper">
|
2017-06-07 10:40:46 +00:00
|
|
|
<div className="mx_RoomView_empty">
|
2017-11-13 19:19:33 +00:00
|
|
|
{ _t("You must <a>register</a> to use this functionality",
|
|
|
|
{},
|
|
|
|
{ 'a': (sub) => <a href="#/register" key="sub">{ sub }</a> })
|
|
|
|
}
|
2017-06-07 10:40:46 +00:00
|
|
|
</div>
|
2017-05-15 09:15:35 +00:00
|
|
|
</div>;
|
|
|
|
} else if (this.noRoom) {
|
2017-05-12 21:38:57 +00:00
|
|
|
return <div className="mx_FilePanel mx_RoomView_messageListWrapper">
|
2017-10-11 16:56:17 +00:00
|
|
|
<div className="mx_RoomView_empty">{ _t("You must join the room to see its files") }</div>
|
2017-05-12 21:38:57 +00:00
|
|
|
</div>;
|
|
|
|
}
|
|
|
|
|
2016-08-31 10:58:06 +00:00
|
|
|
// wrap a TimelinePanel with the jump-to-event bits turned off.
|
2017-10-11 16:56:17 +00:00
|
|
|
const TimelinePanel = sdk.getComponent("structures.TimelinePanel");
|
|
|
|
const Loader = sdk.getComponent("elements.Spinner");
|
2016-08-31 10:58:06 +00:00
|
|
|
|
2016-09-06 00:44:55 +00:00
|
|
|
if (this.state.timelineSet) {
|
2016-09-10 00:39:19 +00:00
|
|
|
// console.log("rendering TimelinePanel for timelineSet " + this.state.timelineSet.room.roomId + " " +
|
|
|
|
// "(" + this.state.timelineSet._timelines.join(", ") + ")" + " with key " + this.props.roomId);
|
2016-09-06 00:44:55 +00:00
|
|
|
return (
|
2016-09-08 13:52:08 +00:00
|
|
|
<TimelinePanel key={"filepanel_" + this.props.roomId}
|
2016-09-07 01:16:29 +00:00
|
|
|
className="mx_FilePanel"
|
2016-09-06 00:44:55 +00:00
|
|
|
manageReadReceipts={false}
|
|
|
|
manageReadMarkers={false}
|
|
|
|
timelineSet={this.state.timelineSet}
|
2017-10-11 16:56:17 +00:00
|
|
|
showUrlPreview = {false}
|
2016-09-11 01:14:27 +00:00
|
|
|
tileShape="file_grid"
|
2017-05-23 14:16:31 +00:00
|
|
|
empty={_t('There are no visible files in this room')}
|
2016-09-06 00:44:55 +00:00
|
|
|
/>
|
|
|
|
);
|
2017-10-11 16:56:17 +00:00
|
|
|
} else {
|
2016-09-07 14:43:14 +00:00
|
|
|
return (
|
|
|
|
<div className="mx_FilePanel">
|
2017-10-11 16:56:17 +00:00
|
|
|
<Loader />
|
2016-09-07 14:43:14 +00:00
|
|
|
</div>
|
|
|
|
);
|
2016-09-06 00:44:55 +00:00
|
|
|
}
|
2016-08-31 10:58:06 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2016-09-06 00:44:55 +00:00
|
|
|
module.exports = FilePanel;
|