diff --git a/lib/store/memory.js b/lib/store/memory.js index 79cc25cae..5bdc3ef25 100644 --- a/lib/store/memory.js +++ b/lib/store/memory.js @@ -9,9 +9,9 @@ * Construct a new in-memory data store for the Matrix Client. * @constructor * @param {Object=} opts Config options - * @param {LocalStorage} opts.localStorage The local storage instance to persist some forms - * of data such as tokens. Rooms will NOT be stored. See {@link WebStorageStore} to - * persist rooms. + * @param {LocalStorage} opts.localStorage The local storage instance to persist + * some forms of data such as tokens. Rooms will NOT be stored. See + * {@link WebStorageStore} to persist rooms. */ module.exports.MatrixInMemoryStore = function MatrixInMemoryStore(opts) { opts = opts || {}; diff --git a/lib/sync.js b/lib/sync.js index 957a66a0e..f6e47e435 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -9,11 +9,9 @@ * for HTTP and WS at some point. */ var q = require("q"); -var StubStore = require("./store/stub"); var User = require("./models/user"); var Room = require("./models/room"); var utils = require("./utils"); -var MatrixEvent = require("./models/event").MatrixEvent; var httpApi = require("./http-api"); var Filter = require("./filter"); @@ -216,18 +214,21 @@ SyncApi.prototype._sync = function(syncOptions, attempt) { // } // } - // set the sync token NOW *before* processing the events. We do this so if something - // barfs on an event we can skip it rather than constantly polling with the same token. + // set the sync token NOW *before* processing the events. We do this so + // if something barfs on an event we can skip it rather than constantly + // polling with the same token. client.store.setSyncToken(data.next_batch); // TODO-arch: - // - Each event we pass through needs to be emitted via 'event', can we do this in one place? + // - Each event we pass through needs to be emitted via 'event', can we + // do this in one place? // - The isBrandNewRoom boilerplate is boilerplatey. try { // handle presence events (User objects) if (data.presence && utils.isArray(data.presence.events)) { - data.presence.events.map(client.getEventMapper()).forEach(function(presenceEvent) { + data.presence.events.map(client.getEventMapper()).forEach( + function(presenceEvent) { var user = client.store.getUser(presenceEvent.getSender()); if (user) { user.setPresenceEvent(presenceEvent); @@ -241,8 +242,9 @@ SyncApi.prototype._sync = function(syncOptions, attempt) { }); } - // the returned json structure is abit crap, so make it into a nicer form (array) after - // applying sanity to make sure we don't fail on missing keys (on the off chance) + // the returned json structure is abit crap, so make it into a + // nicer form (array) after applying sanity to make sure we don't fail + // on missing keys (on the off chance) var inviteRooms = []; var joinRooms = []; var leaveRooms = []; @@ -304,7 +306,7 @@ SyncApi.prototype._sync = function(syncOptions, attempt) { console.error("Caught /sync error:"); console.error(e); } - + // emit synced events if (!syncOptions.hasSyncedBefore) { updateSyncState(client, "PREPARED"); @@ -315,6 +317,10 @@ SyncApi.prototype._sync = function(syncOptions, attempt) { }, errHandler); }; +/** + * @param {Object} obj + * @return {Object[]} + */ SyncApi.prototype._mapSyncResponseToRoomArray = function(obj) { // Maps { roomid: {stuff}, roomid: {stuff} } // to @@ -333,8 +339,13 @@ SyncApi.prototype._mapSyncResponseToRoomArray = function(obj) { arrObj.isBrandNewRoom = isBrandNewRoom; return arrObj; }); -} +}; +/** + * @param {Object} obj + * @param {Room} room + * @return {MatrixEvent[]} + */ SyncApi.prototype._mapSyncEventsFormat = function(obj, room) { if (!obj || !utils.isArray(obj.events)) { return []; @@ -348,6 +359,9 @@ SyncApi.prototype._mapSyncEventsFormat = function(obj, room) { }); }; +/** + * @param {Room} room + */ SyncApi.prototype._resolveInvites = function(room) { if (!room || !this.opts.resolveInvitesToProfiles) { return; @@ -383,12 +397,13 @@ SyncApi.prototype._resolveInvites = function(room) { } inviteEvent.getContent().avatar_url = info.avatar_url; inviteEvent.getContent().displayname = info.displayname; - member.setMembershipEvent(inviteEvent, room.currentState); // fire listeners + // fire listeners + member.setMembershipEvent(inviteEvent, room.currentState); }, function(err) { // OH WELL. }); }); -} +}; /** * @param {Room} room @@ -398,8 +413,8 @@ SyncApi.prototype._resolveInvites = function(room) { * is earlier in time. Higher index is later. * @param {string=} paginationToken */ -SyncApi.prototype._processRoomEvents = function(room, stateEventList, timelineEventList, - paginationToken) { +SyncApi.prototype._processRoomEvents = function(room, stateEventList, + timelineEventList, paginationToken) { timelineEventList = timelineEventList || []; var client = this.client; // "old" and "current" state are the same initially; they @@ -425,7 +440,7 @@ SyncApi.prototype._processRoomEvents = function(room, stateEventList, timelineEv if (paginationToken) { room.oldState.paginationToken = paginationToken; } -} +}; function retryTimeMsForAttempt(attempt) { // 2,4,8,16,32,64,128,128,128,... seconds diff --git a/lib/utils.js b/lib/utils.js index 90416fb85..32741f2f6 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -371,7 +371,7 @@ module.exports.runPolyfills = function() { // Array.prototype.forEach // ======================================================== // SOURCE: - // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach // Production steps of ECMA-262, Edition 5, 15.4.4.18 // Reference: http://es5.github.io/#x15.4.4.18 if (!Array.prototype.forEach) { @@ -380,14 +380,15 @@ module.exports.runPolyfills = function() { var T, k; - if (this == null) { + if (this === null || this === undefined) { throw new TypeError(' this is null or not defined'); } // 1. Let O be the result of calling ToObject passing the |this| value as the argument. var O = Object(this); - // 2. Let lenValue be the result of calling the Get internal method of O with the argument "length". + // 2. Let lenValue be the result of calling the Get internal method of O with the + // argument "length". // 3. Let len be ToUint32(lenValue). var len = O.length >>> 0; @@ -412,12 +413,14 @@ module.exports.runPolyfills = function() { // a. Let Pk be ToString(k). // This is implicit for LHS operands of the in operator - // b. Let kPresent be the result of calling the HasProperty internal method of O with argument Pk. + // b. Let kPresent be the result of calling the HasProperty internal + // method of O with + // argument Pk. // This step can be combined with c // c. If kPresent is true, then if (k in O) { - // i. Let kValue be the result of calling the Get internal method of O with argument Pk. + // i. Let kValue be the result of calling the Get internal method of O with argument Pk kValue = O[k]; // ii. Call the Call internal method of callback with T as the this value and