2021-08-17 09:38:09 +00:00
|
|
|
/*
|
2021-08-26 07:19:44 +00:00
|
|
|
Copyright 2021 The Matrix.org Foundation C.I.C.
|
2021-08-17 09:38:09 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import { MatrixEvent, Room } from 'matrix-js-sdk/src';
|
2021-08-23 16:31:23 +00:00
|
|
|
import { Thread } from 'matrix-js-sdk/src/models/thread';
|
2021-08-17 09:38:09 +00:00
|
|
|
|
|
|
|
import BaseCard from "../views/right_panel/BaseCard";
|
|
|
|
import { RightPanelPhases } from "../../stores/RightPanelStorePhases";
|
|
|
|
import { replaceableComponent } from "../../utils/replaceableComponent";
|
|
|
|
import { MatrixClientPeg } from '../../MatrixClientPeg';
|
|
|
|
|
|
|
|
import ResizeNotifier from '../../utils/ResizeNotifier';
|
|
|
|
import EventTile from '../views/rooms/EventTile';
|
|
|
|
|
|
|
|
interface IProps {
|
|
|
|
roomId: string;
|
|
|
|
onClose: () => void;
|
|
|
|
resizeNotifier: ResizeNotifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IState {
|
|
|
|
threads?: Thread[];
|
|
|
|
}
|
|
|
|
|
|
|
|
@replaceableComponent("structures.ThreadView")
|
2021-08-24 08:09:28 +00:00
|
|
|
export default class ThreadPanel extends React.Component<IProps, IState> {
|
2021-08-17 09:38:09 +00:00
|
|
|
private room: Room;
|
|
|
|
|
|
|
|
constructor(props: IProps) {
|
|
|
|
super(props);
|
|
|
|
this.room = MatrixClientPeg.get().getRoom(this.props.roomId);
|
|
|
|
}
|
|
|
|
|
|
|
|
public componentDidMount(): void {
|
|
|
|
this.room.on("Thread.update", this.onThreadEventReceived);
|
|
|
|
this.room.on("Thread.ready", this.onThreadEventReceived);
|
|
|
|
}
|
|
|
|
|
|
|
|
public componentWillUnmount(): void {
|
|
|
|
this.room.removeListener("Thread.update", this.onThreadEventReceived);
|
|
|
|
this.room.removeListener("Thread.ready", this.onThreadEventReceived);
|
|
|
|
}
|
|
|
|
|
2021-08-24 08:09:28 +00:00
|
|
|
private onThreadEventReceived = () => this.updateThreads();
|
2021-08-17 09:38:09 +00:00
|
|
|
|
2021-08-24 08:09:28 +00:00
|
|
|
private updateThreads = (callback?: () => void): void => {
|
2021-08-17 09:38:09 +00:00
|
|
|
this.setState({
|
|
|
|
threads: this.room.getThreads(),
|
|
|
|
}, callback);
|
|
|
|
};
|
|
|
|
|
2021-08-24 08:09:28 +00:00
|
|
|
private renderEventTile(event: MatrixEvent): JSX.Element {
|
2021-08-17 09:38:09 +00:00
|
|
|
return <EventTile
|
|
|
|
key={event.getId()}
|
|
|
|
mxEvent={event}
|
|
|
|
enableFlair={false}
|
|
|
|
showReadReceipts={false}
|
|
|
|
as="div"
|
|
|
|
/>;
|
|
|
|
}
|
|
|
|
|
2021-08-24 08:09:28 +00:00
|
|
|
public render(): JSX.Element {
|
2021-08-17 09:38:09 +00:00
|
|
|
return (
|
|
|
|
<BaseCard
|
|
|
|
className="mx_ThreadPanel"
|
|
|
|
onClose={this.props.onClose}
|
|
|
|
previousPhase={RightPanelPhases.RoomSummary}
|
|
|
|
>
|
|
|
|
{
|
|
|
|
this.state?.threads.map((thread: Thread) => {
|
|
|
|
if (thread.ready) {
|
|
|
|
return this.renderEventTile(thread.rootEvent);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
</BaseCard>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|