diff --git a/src/components/structures/ThreadView.tsx b/src/components/structures/ThreadView.tsx index 2eb4af94fc..f1bf103402 100644 --- a/src/components/structures/ThreadView.tsx +++ b/src/components/structures/ThreadView.tsx @@ -22,6 +22,7 @@ import { TimelineWindow } from 'matrix-js-sdk/src/timeline-window'; import { Direction } from 'matrix-js-sdk/src/models/event-timeline'; import { IRelationsRequestOpts } from 'matrix-js-sdk/src/@types/requests'; import classNames from "classnames"; +import { logger } from 'matrix-js-sdk/src/logger'; import BaseCard from "../views/right_panel/BaseCard"; import { RightPanelPhases } from "../../stores/right-panel/RightPanelStorePhases"; @@ -305,6 +306,14 @@ export default class ThreadView extends React.Component { let timeline: JSX.Element; if (this.state.thread) { + if (this.props.initialEvent && this.props.initialEvent.getRoomId() !== this.state.thread.roomId) { + logger.warn("ThreadView attempting to render TimelinePanel with mismatched initialEvent", + this.state.thread.roomId, + this.props.initialEvent.getRoomId(), + this.props.initialEvent.getId(), + ); + } + timeline = <> { * @param {boolean?} scrollIntoView whether to scroll the event into view. */ private loadTimeline(eventId?: string, pixelOffset?: number, offsetBase?: number, scrollIntoView = true): void { - this.timelineWindow = new TimelineWindow( - MatrixClientPeg.get(), this.props.timelineSet, - { windowLimit: this.props.timelineCap }); + const cli = MatrixClientPeg.get(); + this.timelineWindow = new TimelineWindow(cli, this.props.timelineSet, { windowLimit: this.props.timelineCap }); const onLoaded = () => { if (this.unmounted) return; @@ -1290,8 +1290,7 @@ class TimelinePanel extends React.Component { // we're in a setState callback, and we know // timelineLoading is now false, so render() should have // mounted the message panel. - logger.log("can't initialise scroll state because " + - "messagePanel didn't load"); + logger.log("can't initialise scroll state because messagePanel didn't load"); return; } @@ -1305,15 +1304,13 @@ class TimelinePanel extends React.Component { }); }; - const onError = (error) => { + const onError = (error: MatrixError) => { if (this.unmounted) return; this.setState({ timelineLoading: false }); - logger.error( - `Error loading timeline panel at ${eventId}: ${error}`, - ); + logger.error(`Error loading timeline panel at ${this.props.timelineSet.room?.roomId}/${eventId}: ${error}`); - let onFinished; + let onFinished: () => void; // if we were given an event ID, then when the user closes the // dialog, let's jump to the end of the timeline. If we weren't, @@ -1329,22 +1326,24 @@ class TimelinePanel extends React.Component { }); }; } - let message; + + let description: string; if (error.errcode == 'M_FORBIDDEN') { - message = _t( + description = _t( "Tried to load a specific point in this room's timeline, but you " + "do not have permission to view the message in question.", ); } else { - message = _t( + description = _t( "Tried to load a specific point in this room's timeline, but was " + "unable to find it.", ); } + Modal.createTrackedDialog('Failed to load timeline position', '', ErrorDialog, { title: _t("Failed to load timeline position"), - description: message, - onFinished: onFinished, + description, + onFinished, }); };