From aaecda53d67acda0c1c5f4b74fe1482348fb1581 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Tue, 30 Jun 2015 11:48:49 +0100 Subject: [PATCH] Add scrollback to store interface --- lib/store/memory.js | 11 ++++ lib/store/stub.js | 10 ++++ lib/store/webstorage.js | 127 ++++++++++++++++++++-------------------- 3 files changed, 86 insertions(+), 62 deletions(-) diff --git a/lib/store/memory.js b/lib/store/memory.js index 737c0750a..9db8f9e06 100644 --- a/lib/store/memory.js +++ b/lib/store/memory.js @@ -87,6 +87,17 @@ module.exports.MatrixInMemoryStore.prototype = { */ getUser: function(userId) { return this.users[userId] || null; + }, + + /** + * Retrieve scrollback for this room. + * @param {Room} room The matrix room + * @param {integer} limit The max number of old events to retrieve. + * @return {Array} An array of objects which will be at most 'limit' + * length and at least 0. The objects are the raw event JSON. + */ + scrollback: function(room, limit) { + return []; } // TODO diff --git a/lib/store/stub.js b/lib/store/stub.js index b10a02462..0d06082d2 100644 --- a/lib/store/stub.js +++ b/lib/store/stub.js @@ -76,6 +76,16 @@ StubStore.prototype = { */ getUser: function(userId) { return null; + }, + + /** + * No-op. + * @param {Room} room + * @param {integer} limit + * @return {Array} + */ + scrollback: function(room, limit) { + return []; } // TODO diff --git a/lib/store/webstorage.js b/lib/store/webstorage.js index 261a0eda6..9966c3c54 100644 --- a/lib/store/webstorage.js +++ b/lib/store/webstorage.js @@ -139,77 +139,80 @@ function WebStorageStore(store, batchSize) { } } -WebStorageStore.prototype = { - /** - * Retrieve the token to stream from. - * @return {string} The token or null. - */ - getSyncToken: function() { - return null; - }, +/** + * Retrieve the token to stream from. + * @return {string} The token or null. + */ +WebStorageStore.prototype.getSyncToken = function() { + return this.store.getItem("sync_token"); +}; - /** - * Set the token to stream from. - * @param {string} token The token to stream from. - */ - setSyncToken: function(token) { +/** + * Set the token to stream from. + * @param {string} token The token to stream from. + */ +WebStorageStore.prototype.setSyncToken = function(token) { + this.store.setItem("sync_token", token); +}; - }, +/** + * Store a room in web storage. + * @param {Room} room + */ +WebStorageStore.prototype.storeRoom = function(room) { +}; - /** - * Store a room in web storage. - * @param {Room} room - */ - storeRoom: function(room) { - }, +/** + * Retrieve a room from web storage. + * @param {string} roomId + * @return {null} + */ +WebStorageStore.prototype.getRoom = function(roomId) { + return null; +}; - /** - * Retrieve a room from web storage. - * @param {string} roomId - * @return {null} - */ - getRoom: function(roomId) { - return null; - }, +/** + * Get a list of all rooms from web storage. + * @return {Array} An empty array. + */ +WebStorageStore.prototype.getRooms = function() { + return []; +}; - /** - * Get a list of all rooms from web storage. - * @return {Array} An empty array. - */ - getRooms: function() { - return []; - }, +/** + * Get a list of summaries from web storage. + * @return {Array} An empty array. + */ +WebStorageStore.prototype.getRoomSummaries = function() { + return []; +}; - /** - * Get a list of summaries from web storage. - * @return {Array} An empty array. - */ - getRoomSummaries: function() { - return []; - }, +/** + * Store a user in web storage. + * @param {User} user + */ +WebStorageStore.prototype.storeUser = function(user) { +}; - /** - * Store a user in web storage. - * @param {User} user - */ - storeUser: function(user) { - }, +/** + * Get a user from web storage. + * @param {string} userId + * @return {null} + */ +WebStorageStore.prototype.getUser = function(userId) { + return null; +}; - /** - * Get a user from web storage. - * @param {string} userId - * @return {null} - */ - getUser: function(userId) { - return null; - } - - // TODO - //setMaxHistoryPerRoom: function(maxHistory) {}, - - // TODO - //reapOldMessages: function() {}, +/** + * Retrieve scrollback for this room. + * @param {Room} room The matrix room + * @param {integer} limit The max number of old events to retrieve. + * @return {Array} An array of objects which will be at most 'limit' + * length and at least 0. The objects are the raw event JSON. + */ +WebStorageStore.prototype.scrollback = function(room, limit) { + return []; }; /** Web Storage Store class. */