diff --git a/lib/client.js b/lib/client.js
index ab28ce4b7..c55dba7a5 100644
--- a/lib/client.js
+++ b/lib/client.js
@@ -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
// 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
- // 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.
var matchingEvent = utils.findElement(room.timeline, function(ev) {
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
* pull in. Default: 30.
* @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, Room.oldState.paginationToken
will be
+ * null
.
* @return {module:http-api.MatrixError} Rejects: with an error response.
*/
MatrixClient.prototype.scrollback = function(room, limit, callback) {
if (utils.isFunction(limit)) { callback = limit; limit = undefined; }
+ if (room.oldState.paginationToken === null) {
+ return q(room); // already at the start.
+ }
var path = utils.encodeUri(
"/rooms/$roomId/messages", {$roomId: room.roomId}
);
@@ -824,6 +829,9 @@ MatrixClient.prototype.scrollback = function(room, limit, callback) {
utils.map(res.chunk, _PojoToMatrixEventMapper), true
);
room.oldState.paginationToken = res.end;
+ if (res.chunk.length < limit) {
+ room.oldState.paginationToken = null;
+ }
_resolve(callback, defer, room);
}, function(err) {
_reject(callback, defer, err);
diff --git a/spec/integ/matrix-client-room-timeline.spec.js b/spec/integ/matrix-client-room-timeline.spec.js
index e2ed112e9..b7ddbb6ef 100644
--- a/spec/integ/matrix-client-room-timeline.spec.js
+++ b/spec/integ/matrix-client-room-timeline.spec.js
@@ -73,17 +73,14 @@ describe("MatrixClient room timelines", 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) {
client.on("syncComplete", function() {
var room = client.getRoom(roomId);
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
expect(room.timeline.length).toEqual(2);
// check status
@@ -95,13 +92,13 @@ describe("MatrixClient room timelines", function() {
httpBackend.flush("/events", 1).done(function() {
done();
- })
+ });
});
client.startClient();
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) {
var eventId = "$foo:bar";
httpBackend.when("PUT", "/txn1").respond(200, {
@@ -130,7 +127,7 @@ describe("MatrixClient room timelines", function() {
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) {
var eventId = "$foo:bar";
httpBackend.when("PUT", "/txn1").respond(200, {
@@ -156,7 +153,7 @@ describe("MatrixClient room timelines", function() {
done();
});
});
-
+
});
client.startClient();
httpBackend.flush("/initialSync", 1);
@@ -170,4 +167,4 @@ describe("MatrixClient room timelines", function() {
describe("new events", function() {
});
-});
\ No newline at end of file
+});
diff --git a/spec/mock-request.js b/spec/mock-request.js
index dbc66207a..987c0484e 100644
--- a/spec/mock-request.js
+++ b/spec/mock-request.js
@@ -27,7 +27,9 @@ HttpBackend.prototype = {
var defer = q.defer();
var self = this;
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() {
// if there's more real requests and more expected requests, flush 'em.
console.log(