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

Merge branch 'develop' into push

Conflicts:
	lib/client.js
This commit is contained in:
David Baker
2015-06-26 16:39:32 +01:00
6 changed files with 135 additions and 8 deletions

View File

@@ -8,6 +8,8 @@ New features:
New methods:
* `MatrixScheduler.getQueueForEvent(event)`
* `MatrixScheduler.removeEventFromQueue(event)`
* `$DATA_STORE.setSyncToken(token)`
* `$DATA_STORE.getSyncToken()`
Bug fixes:
* Fixed an issue which prevented RoomMember.name being disambiguated if there

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 = {
@@ -1025,7 +1023,7 @@ function doInitialSync(client, historyLen) {
}
if (data) {
client.fromToken = data.end;
client.store.setSyncToken(data.end);
var events = [];
for (i = 0; i < data.presence.length; i++) {
events.push(new MatrixEvent(data.presence[i]));
@@ -1071,7 +1069,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;
@@ -1102,7 +1100,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) {
@@ -1167,7 +1165,7 @@ function _pollForEvents(client) {
});
}
if (data) {
self.fromToken = data.end;
self.store.setSyncToken(data.end);
utils.forEach(events, function(e) {
self.emit("event", e);
});

View File

@@ -6,6 +6,8 @@ module.exports.MatrixEvent = require("./models/event").MatrixEvent;
module.exports.EventStatus = require("./models/event").EventStatus;
/** The {@link module:store/memory.MatrixInMemoryStore|MatrixInMemoryStore} class. */
module.exports.MatrixInMemoryStore = require("./store/memory").MatrixInMemoryStore;
/** The {@link module:store/localstorage.LocalStorageStore|LocalStorageStore} class. */
module.exports.LocalStorageStore = require("./store/localstorage");
/** The {@link module:http-api.MatrixHttpApi|MatrixHttpApi} class. */
module.exports.MatrixHttpApi = require("./http-api").MatrixHttpApi;
/** The {@link module:http-api.MatrixError|MatrixError} class. */

92
lib/store/localstorage.js Normal file
View File

@@ -0,0 +1,92 @@
"use strict";
/**
* This is an internal module.
* @module store/localstorage
*/
/**
* Construct a localstorage store.
* @constructor
* @throws if the global 'localStorage' does not exist.
*/
function LocalStorageStore() {
if (!global.localStorage) {
throw new Error("localStorage not found.");
}
}
LocalStorageStore.prototype = {
/**
* Retrieve the token to stream from.
* @return {string} The token or null.
*/
getSyncToken: function() {
return null;
},
/**
* Set the token to stream from.
* @param {string} token The token to stream from.
*/
setSyncToken: function(token) {
},
/**
* Store a room in local storage.
* @param {Room} room
*/
storeRoom: function(room) {
},
/**
* Retrieve a room from local storage.
* @param {string} roomId
* @return {null}
*/
getRoom: function(roomId) {
return null;
},
/**
* Get a list of all rooms from local storage.
* @return {Array} An empty array.
*/
getRooms: function() {
return [];
},
/**
* Get a list of summaries from local storage.
* @return {Array} An empty array.
*/
getRoomSummaries: function() {
return [];
},
/**
* Store a user in local storage.
* @param {User} user
*/
storeUser: function(user) {
},
/**
* Get a user from local storage.
* @param {string} userId
* @return {null}
*/
getUser: function(userId) {
return null;
}
// TODO
//setMaxHistoryPerRoom: function(maxHistory) {},
// TODO
//reapOldMessages: function() {},
};
/** Local Storage Store class. */
module.exports = LocalStorageStore;

View File

@@ -16,10 +16,27 @@ module.exports.MatrixInMemoryStore = function MatrixInMemoryStore() {
this.users = {
// userId: User
};
this.syncToken = null;
};
module.exports.MatrixInMemoryStore.prototype = {
/**
* Retrieve the token to stream from.
* @return {string} The token or null.
*/
getSyncToken: function() {
return this.syncToken;
},
/**
* Set the token to stream from.
* @param {string} token The token to stream from.
*/
setSyncToken: function(token) {
this.syncToken = token;
},
/**
* Store the given room.
* @param {Room} room The room to be stored. All properties must be stored.

View File

@@ -5,15 +5,31 @@
*/
/**
* Construct a stub store. This does no-ops on all store methods.
* Construct a stub store. This does no-ops on most store methods.
* @constructor
*/
function StubStore() {
this.fromToken = null;
}
StubStore.prototype = {
/**
* Get the sync token.
* @return {string}
*/
getSyncToken: function() {
return this.fromToken;
},
/**
* Set the sync token.
* @param {string} token
*/
setSyncToken: function(token) {
this.fromToken = token;
},
/**
* No-op.
* @param {Room} room