1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-19 16:42:09 +03:00

Add getSyncToken and setSyncToken to data store interface.

This allows local storage to hold onto the token across page refreshes.
This commit is contained in:
Kegan Dougal
2015-06-26 15:36:53 +01:00
parent 6078100465
commit b7975866fa
5 changed files with 57 additions and 8 deletions

View File

@@ -54,8 +54,6 @@ function MatrixClient(opts) {
return _sendEventHttpRequest(self, eventToSend);
});
}
// track our position in the overall eventstream
this.fromToken = undefined;
this.clientRunning = false;
var httpOpts = {
@@ -986,7 +984,7 @@ MatrixClient.prototype.startClient = function(historyLen) {
// client is already running.
return;
}
if (this.fromToken) {
if (this.store.getSyncToken()) {
// resume from where we left off.
_pollForEvents(this);
return;
@@ -1038,7 +1036,7 @@ MatrixClient.prototype.startClient = function(historyLen) {
}
if (data) {
self.fromToken = data.end;
self.store.setSyncToken(data.end);
var events = [];
for (i = 0; i < data.presence.length; i++) {
events.push(new MatrixEvent(data.presence[i]));
@@ -1087,7 +1085,7 @@ function _pollForEvents(client) {
}, 40000);
client._http.authedRequest(undefined, "GET", "/events", {
from: client.fromToken,
from: client.store.getSyncToken(),
timeout: 30000
}).done(function(data) {
if (discardResult) {
@@ -1152,7 +1150,7 @@ function _pollForEvents(client) {
});
}
if (data) {
self.fromToken = data.end;
self.store.setSyncToken(data.end);
utils.forEach(events, function(e) {
self.emit("event", e);
});