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';
|
2019-08-30 09:34:59 +00:00
|
|
|
import createReactClass from 'create-react-class';
|
2017-12-26 01:03:18 +00:00
|
|
|
import PropTypes from 'prop-types';
|
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
|
|
|
|
*/
|
2019-08-30 09:34:59 +00:00
|
|
|
const FilePanel = createReactClass({
|
2016-08-31 10:58:06 +00:00
|
|
|
displayName: 'FilePanel',
|
|
|
|
|
2016-09-05 23:59:17 +00:00
|
|
|
propTypes: {
|
2017-12-26 01:03:18 +00:00
|
|
|
roomId: PropTypes.string.isRequired,
|
2016-09-05 23:59:17 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
timelineSet: null,
|
2017-01-20 14:22:27 +00:00
|
|
|
};
|
2016-09-05 23:59:17 +00:00
|
|
|
},
|
|
|
|
|
2019-11-06 09:32:20 +00:00
|
|
|
componentDidMount: function() {
|
2016-09-07 14:43:14 +00:00
|
|
|
this.updateTimelineSet(this.props.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,
|
2018-06-16 18:52:15 +00:00
|
|
|
"types": [
|
|
|
|
"m.room.message",
|
2018-01-08 12:06:32 +00:00
|
|
|
],
|
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 (
|
2019-10-14 09:44:42 +00:00
|
|
|
<div className="mx_FilePanel" role="tabpanel">
|
|
|
|
<TimelinePanel key={"filepanel_" + this.props.roomId}
|
|
|
|
manageReadReceipts={false}
|
|
|
|
manageReadMarkers={false}
|
|
|
|
timelineSet={this.state.timelineSet}
|
|
|
|
showUrlPreview = {false}
|
|
|
|
tileShape="file_grid"
|
|
|
|
resizeNotifier={this.props.resizeNotifier}
|
|
|
|
empty={_t('There are no visible files in this room')}
|
|
|
|
/>
|
|
|
|
</div>
|
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 (
|
2019-10-03 08:35:39 +00:00
|
|
|
<div className="mx_FilePanel" role="tabpanel">
|
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;
|