diff --git a/src/components/structures/FilePanel.js b/src/components/structures/FilePanel.js index f8c03be864..f073785df3 100644 --- a/src/components/structures/FilePanel.js +++ b/src/components/structures/FilePanel.js @@ -25,6 +25,8 @@ import {MatrixClientPeg} from '../../MatrixClientPeg'; import EventIndexPeg from "../../indexing/EventIndexPeg"; import { _t } from '../../languageHandler'; +import RoomScrollStateStore from '../../stores/RoomScrollStateStore'; + /* * Component which shows the filtered file using a TimelinePanel */ @@ -41,6 +43,8 @@ const FilePanel = createReactClass({ getInitialState: function() { return { timelineSet: null, + initialEventId: null, + initialEventPixelOffset: null, }; }, @@ -84,6 +88,16 @@ const FilePanel = createReactClass({ await this.updateTimelineSet(this.props.roomId); + if (this.props.roomId) { + const filePanelScrollState = RoomScrollStateStore.getFilePanelScrollState(this.props.roomId); + if (filePanelScrollState) { + this.setState({ + initialEventId: filePanelScrollState.focussedEvent, + initialEventPixelOffset: filePanelScrollState.pixelOffset, + }); + } + } + if (!MatrixClientPeg.get().isRoomEncrypted(this.props.roomId)) return; // The timelineSets filter makes sure that encrypted events that contain @@ -101,6 +115,10 @@ const FilePanel = createReactClass({ }, componentWillUnmount() { + if (this.props.roomId) { + RoomScrollStateStore.setFilePanelScrollState(this.props.roomId, this._getScrollState()); + } + const client = MatrixClientPeg.get(); if (client === null) return; @@ -190,6 +208,26 @@ const FilePanel = createReactClass({ } }, + _getScrollState: function() { + const timelinePanel = this._timelinePanel; + const scrollState = timelinePanel.getScrollState(); + + if (!timelinePanel) return null; + + if (!scrollState || scrollState.stuckAtBottom) { + return null; + } + + return { + focussedEvent: scrollState.trackedScrollToken, + pixelOffset: scrollState.pixelOffset, + }; + }, + + _getTimelinePanelRef: function(ref) { + this._timelinePanel = ref; + }, + render: function() { if (MatrixClientPeg.get().isGuest()) { return