mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-18 06:35:35 +08:00
FilePanel: Refactor out the file panel and convert the methods to async ones.
This commit is contained in:
parent
491cef4f92
commit
d30c46a641
@ -40,42 +40,50 @@ 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 filter = new Matrix.Filter(client.credentials.userId);
|
||||||
|
filter.setDefinition(
|
||||||
|
{
|
||||||
|
"room": {
|
||||||
|
"timeline": {
|
||||||
|
"contains_url": true,
|
||||||
|
"types": [
|
||||||
|
"m.room.message",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// FIXME: we shouldn't be doing this every time we change room - see comment above.
|
||||||
|
// TODO: Remove this stale comment? Which comment above?
|
||||||
|
const filterId = await client.getOrCreateFilter("FILTER_FILES_" + client.credentials.userId, filter)
|
||||||
|
filter.filterId = filterId;
|
||||||
|
const timelineSet = room.getOrCreateFilteredTimelineSet(filter);
|
||||||
|
|
||||||
|
return timelineSet;
|
||||||
|
},
|
||||||
|
|
||||||
|
async updateTimelineSet(roomId: string) {
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.get();
|
||||||
const room = client.getRoom(roomId);
|
const room = client.getRoom(roomId);
|
||||||
|
|
||||||
this.noRoom = !room;
|
this.noRoom = !room;
|
||||||
|
|
||||||
if (room) {
|
if (room) {
|
||||||
const filter = new Matrix.Filter(client.credentials.userId);
|
try {
|
||||||
filter.setDefinition(
|
let timelineSet = await this.fetchFileEventsServer(room)
|
||||||
{
|
this.setState({ timelineSet: timelineSet });
|
||||||
"room": {
|
|
||||||
"timeline": {
|
|
||||||
"contains_url": true,
|
|
||||||
"types": [
|
|
||||||
"m.room.message",
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
// FIXME: we shouldn't be doing this every time we change room - see comment above.
|
} catch (error) {
|
||||||
client.getOrCreateFilter("FILTER_FILES_" + client.credentials.userId, filter).then(
|
console.error("Failed to get or create file panel filter", error);
|
||||||
(filterId)=>{
|
}
|
||||||
filter.filterId = filterId;
|
|
||||||
const timelineSet = room.getOrCreateFilteredTimelineSet(filter);
|
|
||||||
this.setState({ timelineSet: timelineSet });
|
|
||||||
},
|
|
||||||
(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!");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user