= ({ hasThreads, filterOption, showAllThreadsCallback }) => {
let body: JSX.Element;
if (hasThreads) {
body = <>
{ _t("Reply to an ongoing thread or use ā%(replyInThread)sā "
+ "when hovering over a message to start a new one.", {
replyInThread: _t("Reply in thread"),
}) }
{ /* Always display that paragraph to prevent layout shift when hiding the button */ }
{ (filterOption === ThreadFilterType.My)
? { _t("Show all threads") }
: <> >
}
>;
} else {
body = <>
{ _t("Threads help keep your conversations on-topic and easy to track.") }
{ _t('Tip: Use ā%(replyInThread)sā when hovering over a message.', {
replyInThread: _t("Reply in thread"),
}, {
b: sub => { sub } ,
}) }
>;
}
return
{ _t("Keep discussions organised with threads") }
{ body }
;
};
const ThreadPanel: React.FC = ({
roomId,
onClose,
permalinkCreator,
}) => {
const mxClient = useContext(MatrixClientContext);
const roomContext = useContext(RoomContext);
const timelinePanel = useRef();
const card = useRef();
const [filterOption, setFilterOption] = useState(ThreadFilterType.All);
const [room, setRoom] = useState(null);
const [timelineSet, setTimelineSet] = useState(null);
const [narrow, setNarrow] = useState(false);
useEffect(() => {
const room = mxClient.getRoom(roomId);
room.createThreadsTimelineSets().then(() => {
return room.fetchRoomThreads();
}).then(() => {
setFilterOption(ThreadFilterType.All);
setRoom(room);
});
}, [mxClient, roomId]);
useEffect(() => {
function refreshTimeline() {
timelinePanel?.current.refreshTimeline();
}
room?.on(ThreadEvent.Update, refreshTimeline);
return () => {
room?.removeListener(ThreadEvent.Update, refreshTimeline);
};
}, [room, mxClient, timelineSet]);
useEffect(() => {
if (room) {
if (filterOption === ThreadFilterType.My) {
setTimelineSet(room.threadsTimelineSets[1]);
} else {
setTimelineSet(room.threadsTimelineSets[0]);
}
}
}, [room, filterOption]);
useEffect(() => {
if (timelineSet && !Thread.hasServerSideSupport) {
timelinePanel.current.refreshTimeline();
}
}, [timelineSet, timelinePanel]);
const openFeedback = shouldShowFeedback() ? () => {
Modal.createDialog(BetaFeedbackDialog, {
featureId: "feature_thread",
});
} : null;
return (
}
footer={<>
{
dis.dispatch({
action: Action.ViewUserSettings,
initialTabId: UserTab.Labs,
});
}}
/>
{ openFeedback && _t("Give feedback ", {}, {
a: sub =>
{ sub } ,
}) }
>}
className="mx_ThreadPanel"
onClose={onClose}
withoutScrollContainer={true}
ref={card}
>
{ timelineSet
? 0}
filterOption={filterOption}
showAllThreadsCallback={() => setFilterOption(ThreadFilterType.All)}
/>}
alwaysShowTimestamps={true}
layout={Layout.Group}
hideThreadedMessages={false}
hidden={false}
showReactions={false}
className="mx_RoomView_messagePanel"
membersLoaded={true}
permalinkCreator={permalinkCreator}
disableGrouping={true}
/>
:
}
);
};
export default ThreadPanel;