mirror of
https://github.com/SchildiChat/element-web.git
synced 2024-10-01 01:26:12 -04:00
Limit the number of messages we load into a chat room when we switch to it (or more accurately, switch back to it).
This commit is contained in:
parent
2355d5e6b5
commit
209e052025
@ -38,11 +38,16 @@ module.exports = React.createClass({
|
|||||||
mixins: [RoomViewController],
|
mixins: [RoomViewController],
|
||||||
|
|
||||||
getMessageTiles: function() {
|
getMessageTiles: function() {
|
||||||
return this.state.room.timeline.map(function(mxEv) {
|
var ret = [];
|
||||||
return (
|
var count = 0;
|
||||||
|
for (var i = this.state.room.timeline.length-1; i >= 0 && count < this.state.messageCap; --i) {
|
||||||
|
var mxEv = this.state.room.timeline[i];
|
||||||
|
ret.unshift(
|
||||||
<li key={mxEv.getId()}><MessageTile mxEvent={mxEv} /></li>
|
<li key={mxEv.getId()}><MessageTile mxEvent={mxEv} /></li>
|
||||||
);
|
);
|
||||||
});
|
++count;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
|
@ -21,11 +21,13 @@ var MatrixClientPeg = require("../../MatrixClientPeg");
|
|||||||
var dis = require("../../dispatcher");
|
var dis = require("../../dispatcher");
|
||||||
|
|
||||||
var PAGINATE_SIZE = 20;
|
var PAGINATE_SIZE = 20;
|
||||||
|
var INITIAL_SIZE = 100;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {
|
return {
|
||||||
room: MatrixClientPeg.get().getRoom(this.props.roomId)
|
room: MatrixClientPeg.get().getRoom(this.props.roomId),
|
||||||
|
messageCap: INITIAL_SIZE
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -113,10 +115,17 @@ module.exports = {
|
|||||||
var messageUl = this.refs.messageList.getDOMNode();
|
var messageUl = this.refs.messageList.getDOMNode();
|
||||||
if (messageUl.scrollTop < messageUl.clientHeight) {
|
if (messageUl.scrollTop < messageUl.clientHeight) {
|
||||||
this.setState({paginating: true});
|
this.setState({paginating: true});
|
||||||
this.waiting_for_paginate = true;
|
|
||||||
|
|
||||||
this.oldScrollHeight = messageUl.scrollHeight;
|
this.oldScrollHeight = messageUl.scrollHeight;
|
||||||
|
|
||||||
|
if (this.state.messageCap < this.state.room.timeline.length) {
|
||||||
|
this.waiting_for_paginate = false;
|
||||||
|
var cap = Math.min(this.state.messageCap + PAGINATE_SIZE, this.state.room.timeline.length);
|
||||||
|
this.setState({messageCap: cap, paginating: true});
|
||||||
|
} else {
|
||||||
|
this.waiting_for_paginate = true;
|
||||||
|
var cap = this.state.messageCap + PAGINATE_SIZE;
|
||||||
|
this.setState({messageCap: cap, paginating: true});
|
||||||
var that = this;
|
var that = this;
|
||||||
MatrixClientPeg.get().scrollback(this.state.room, PAGINATE_SIZE).finally(function() {
|
MatrixClientPeg.get().scrollback(this.state.room, PAGINATE_SIZE).finally(function() {
|
||||||
that.waiting_for_paginate = false;
|
that.waiting_for_paginate = false;
|
||||||
@ -125,6 +134,8 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
// wait and set paginating to false when the component updates
|
// wait and set paginating to false when the component updates
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user