FilePanel: Refactor out the file panel and convert the methods to async ones.

This commit is contained in:
Damir Jelić 2020-01-14 11:20:56 +01:00
parent 491cef4f92
commit d30c46a641

View File

@ -40,17 +40,13 @@ const FilePanel = createReactClass({
}; };
}, },
componentDidMount: function() { async componentDidMount() {
this.updateTimelineSet(this.props.roomId); await this.updateTimelineSet(this.props.roomId);
}, },
updateTimelineSet: function(roomId) { async fetchFileEventsServer(room) {
const client = MatrixClientPeg.get(); const client = MatrixClientPeg.get();
const room = client.getRoom(roomId);
this.noRoom = !room;
if (room) {
const filter = new Matrix.Filter(client.credentials.userId); const filter = new Matrix.Filter(client.credentials.userId);
filter.setDefinition( filter.setDefinition(
{ {
@ -66,16 +62,28 @@ const FilePanel = createReactClass({
); );
// FIXME: we shouldn't be doing this every time we change room - see comment above. // FIXME: we shouldn't be doing this every time we change room - see comment above.
client.getOrCreateFilter("FILTER_FILES_" + client.credentials.userId, filter).then( // TODO: Remove this stale comment? Which comment above?
(filterId)=>{ const filterId = await client.getOrCreateFilter("FILTER_FILES_" + client.credentials.userId, filter)
filter.filterId = filterId; filter.filterId = filterId;
const timelineSet = room.getOrCreateFilteredTimelineSet(filter); const timelineSet = room.getOrCreateFilteredTimelineSet(filter);
return timelineSet;
},
async updateTimelineSet(roomId: string) {
const client = MatrixClientPeg.get();
const room = client.getRoom(roomId);
this.noRoom = !room;
if (room) {
try {
let timelineSet = await this.fetchFileEventsServer(room)
this.setState({ timelineSet: timelineSet }); this.setState({ timelineSet: timelineSet });
},
(error)=>{ } catch (error) {
console.error("Failed to get or create file panel filter", error); console.error("Failed to get or create file panel filter", error);
}, }
);
} else { } else {
console.error("Failed to add filtered timelineSet for FilePanel as no room!"); console.error("Failed to add filtered timelineSet for FilePanel as no room!");
} }