1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-07-31 15:24:23 +03:00

Set Room.oldState.paginationToken to null at the start of the timeline. Fix linting errors.

This commit is contained in:
Kegan Dougal
2015-06-25 15:28:25 +01:00
parent c4c68a0287
commit 325c00c660
3 changed files with 20 additions and 13 deletions

View File

@ -315,7 +315,7 @@ function _sendEvent(client, room, event, callback) {
// try to find an event with this event_id. If we find it, this is // try to find an event with this event_id. If we find it, this is
// the echo of this event *from the event stream* so we can remove // the echo of this event *from the event stream* so we can remove
// the fake event we made above. If we don't find it, we're still // the fake event we made above. If we don't find it, we're still
// waiting on the fake event and so should assign the fake event // waiting on the real event and so should assign the fake event
// with the real event_id for matching later. // with the real event_id for matching later.
var matchingEvent = utils.findElement(room.timeline, function(ev) { var matchingEvent = utils.findElement(room.timeline, function(ev) {
return ev.getId() === eventId; return ev.getId() === eventId;
@ -804,11 +804,16 @@ MatrixClient.prototype.roomState = function(roomId, callback) {
* @param {Integer} limit Optional. The maximum number of previous events to * @param {Integer} limit Optional. The maximum number of previous events to
* pull in. Default: 30. * pull in. Default: 30.
* @param {module:client.callback} callback Optional. * @param {module:client.callback} callback Optional.
* @return {module:client.Promise} Resolves: Room. * @return {module:client.Promise} Resolves: Room. If you are at the beginning
* of the timeline, <code>Room.oldState.paginationToken</code> will be
* <code>null</code>.
* @return {module:http-api.MatrixError} Rejects: with an error response. * @return {module:http-api.MatrixError} Rejects: with an error response.
*/ */
MatrixClient.prototype.scrollback = function(room, limit, callback) { MatrixClient.prototype.scrollback = function(room, limit, callback) {
if (utils.isFunction(limit)) { callback = limit; limit = undefined; } if (utils.isFunction(limit)) { callback = limit; limit = undefined; }
if (room.oldState.paginationToken === null) {
return q(room); // already at the start.
}
var path = utils.encodeUri( var path = utils.encodeUri(
"/rooms/$roomId/messages", {$roomId: room.roomId} "/rooms/$roomId/messages", {$roomId: room.roomId}
); );
@ -824,6 +829,9 @@ MatrixClient.prototype.scrollback = function(room, limit, callback) {
utils.map(res.chunk, _PojoToMatrixEventMapper), true utils.map(res.chunk, _PojoToMatrixEventMapper), true
); );
room.oldState.paginationToken = res.end; room.oldState.paginationToken = res.end;
if (res.chunk.length < limit) {
room.oldState.paginationToken = null;
}
_resolve(callback, defer, room); _resolve(callback, defer, room);
}, function(err) { }, function(err) {
_reject(callback, defer, err); _reject(callback, defer, err);

View File

@ -73,17 +73,14 @@ describe("MatrixClient room timelines", function() {
}); });
describe("local echo events", function() { describe("local echo events", function() {
var sendEvent = utils.mkMessage({
room: roomId, user: otherUserId, msg: "hello"
});
it("should be added immediately after calling MatrixClient.sendEvent "+ it("should be added immediately after calling MatrixClient.sendEvent " +
"with EventStatus.SENDING and the right event.sender", function(done) { "with EventStatus.SENDING and the right event.sender", function(done) {
client.on("syncComplete", function() { client.on("syncComplete", function() {
var room = client.getRoom(roomId); var room = client.getRoom(roomId);
expect(room.timeline.length).toEqual(1); expect(room.timeline.length).toEqual(1);
var promise = client.sendTextMessage(roomId, "I am a fish", "txn1"); client.sendTextMessage(roomId, "I am a fish", "txn1");
// check it was added // check it was added
expect(room.timeline.length).toEqual(2); expect(room.timeline.length).toEqual(2);
// check status // check status
@ -95,13 +92,13 @@ describe("MatrixClient room timelines", function() {
httpBackend.flush("/events", 1).done(function() { httpBackend.flush("/events", 1).done(function() {
done(); done();
}) });
}); });
client.startClient(); client.startClient();
httpBackend.flush("/initialSync", 1); httpBackend.flush("/initialSync", 1);
}); });
it("should be updated correctly when the send request finishes "+ it("should be updated correctly when the send request finishes " +
"BEFORE the event comes down the event stream", function(done) { "BEFORE the event comes down the event stream", function(done) {
var eventId = "$foo:bar"; var eventId = "$foo:bar";
httpBackend.when("PUT", "/txn1").respond(200, { httpBackend.when("PUT", "/txn1").respond(200, {
@ -130,7 +127,7 @@ describe("MatrixClient room timelines", function() {
httpBackend.flush("/initialSync", 1); httpBackend.flush("/initialSync", 1);
}); });
it("should be updated correctly when the send request finishes "+ it("should be updated correctly when the send request finishes " +
"AFTER the event comes down the event stream", function(done) { "AFTER the event comes down the event stream", function(done) {
var eventId = "$foo:bar"; var eventId = "$foo:bar";
httpBackend.when("PUT", "/txn1").respond(200, { httpBackend.when("PUT", "/txn1").respond(200, {
@ -156,7 +153,7 @@ describe("MatrixClient room timelines", function() {
done(); done();
}); });
}); });
}); });
client.startClient(); client.startClient();
httpBackend.flush("/initialSync", 1); httpBackend.flush("/initialSync", 1);
@ -170,4 +167,4 @@ describe("MatrixClient room timelines", function() {
describe("new events", function() { describe("new events", function() {
}); });
}); });

View File

@ -27,7 +27,9 @@ HttpBackend.prototype = {
var defer = q.defer(); var defer = q.defer();
var self = this; var self = this;
var flushed = 0; var flushed = 0;
console.log("HTTP backend flushing... (path=%s numToFlush=%s)", path, numToFlush); console.log(
"HTTP backend flushing... (path=%s numToFlush=%s)", path, numToFlush
);
var tryFlush = function() { var tryFlush = function() {
// if there's more real requests and more expected requests, flush 'em. // if there's more real requests and more expected requests, flush 'em.
console.log( console.log(