mirror of
https://github.com/element-hq/element-web
synced 2024-11-24 10:15:43 +03:00
Merge pull request #180 from matrix-org/rav/optimise_timeline_load
Make room-switching quicker
This commit is contained in:
commit
a9d363c668
1 changed files with 26 additions and 14 deletions
|
@ -459,29 +459,33 @@ var TimelinePanel = React.createClass({
|
||||||
* returns a promise which will resolve when the load completes.
|
* returns a promise which will resolve when the load completes.
|
||||||
*/
|
*/
|
||||||
_loadTimeline: function(eventId, pixelOffset) {
|
_loadTimeline: function(eventId, pixelOffset) {
|
||||||
// TODO: we could optimise this, by not resetting the window if the
|
this._timelineWindow = new Matrix.TimelineWindow(
|
||||||
// event is in the current window (though it's not obvious how we can
|
MatrixClientPeg.get(), this.props.room,
|
||||||
// tell if the current window is on the live event stream)
|
{windowLimit: TIMELINE_CAP});
|
||||||
|
|
||||||
|
var prom = this._timelineWindow.load(eventId, INITIAL_SIZE);
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
events: [],
|
events: [],
|
||||||
timelineLoading: true,
|
timelineLoading: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
this._timelineWindow = new Matrix.TimelineWindow(
|
// if we already have the event in question, TimelineWindow.load
|
||||||
MatrixClientPeg.get(), this.props.room,
|
// returns a resolved promise.
|
||||||
{windowLimit: TIMELINE_CAP});
|
//
|
||||||
|
// In this situation, we don't really want to defer the update of the
|
||||||
|
// state to the next event loop, because it makes room-switching feel
|
||||||
|
// quite slow. So we detect that situation and shortcut straight to
|
||||||
|
// calling _onTimelineUpdated and updating the state.
|
||||||
|
|
||||||
return this._timelineWindow.load(eventId, INITIAL_SIZE).then(() => {
|
var onLoaded = () => {
|
||||||
debuglog("TimelinePanel: timeline loaded");
|
|
||||||
this._onTimelineUpdated(true);
|
this._onTimelineUpdated(true);
|
||||||
}).finally(() => {
|
|
||||||
this.setState({
|
this.setState({timelineLoading: false}, () => {
|
||||||
timelineLoading: false,
|
|
||||||
}, () => {
|
|
||||||
// initialise the scroll state of the message panel
|
// initialise the scroll state of the message panel
|
||||||
if (!this.refs.messagePanel) {
|
if (!this.refs.messagePanel) {
|
||||||
// this shouldn't happen.
|
// this shouldn't happen - _onTimelineUpdated checks we're
|
||||||
|
// mounted, and timelineLoading is now false.
|
||||||
console.log("can't initialise scroll state because " +
|
console.log("can't initialise scroll state because " +
|
||||||
"messagePanel didn't load");
|
"messagePanel didn't load");
|
||||||
return;
|
return;
|
||||||
|
@ -495,7 +499,15 @@ var TimelinePanel = React.createClass({
|
||||||
this.sendReadReceipt();
|
this.sendReadReceipt();
|
||||||
this.updateReadMarker();
|
this.updateReadMarker();
|
||||||
});
|
});
|
||||||
});
|
};
|
||||||
|
|
||||||
|
if (prom.isPending()) {
|
||||||
|
prom = prom.then(onLoaded);
|
||||||
|
} else {
|
||||||
|
onLoaded();
|
||||||
|
}
|
||||||
|
|
||||||
|
prom.done();
|
||||||
},
|
},
|
||||||
|
|
||||||
_onTimelineUpdated: function(gotResults) {
|
_onTimelineUpdated: function(gotResults) {
|
||||||
|
|
Loading…
Reference in a new issue