From a5d3dd942ecf7854be022dc5f09ffb453d6d8c32 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Mon, 10 Jul 2017 16:04:25 +0100 Subject: [PATCH] q(...) -> Promise.resolve ``` find src spec -name '*.js' | xargs perl -i -pe 's/\bq(\([^(]*\))/Promise.resolve$1/' ``` --- spec/TestClient.js | 2 +- spec/integ/matrix-client-crypto.spec.js | 22 ++++++------ spec/unit/crypto/algorithms/megolm.spec.js | 2 +- spec/unit/interactive-auth.spec.js | 4 +-- spec/unit/matrix-client.spec.js | 8 ++--- spec/unit/timeline-window.spec.js | 12 +++---- src/client.js | 36 +++++++++---------- src/crypto/DeviceList.js | 4 +-- src/crypto/OutgoingRoomKeyRequestManager.js | 2 +- src/crypto/algorithms/megolm.js | 4 +-- src/crypto/algorithms/olm.js | 2 +- src/crypto/index.js | 4 +-- src/crypto/olmlib.js | 2 +- .../store/indexeddb-crypto-store-backend.js | 2 +- src/crypto/store/memory-crypto-store.js | 22 ++++++------ src/interactive-auth.js | 4 +-- src/store/indexeddb-local-backend.js | 10 +++--- src/store/indexeddb-remote-backend.js | 2 +- src/store/indexeddb-store-worker.js | 2 +- src/store/indexeddb.js | 4 +-- src/store/memory.js | 8 ++--- src/store/stub.js | 8 ++--- src/sync.js | 6 ++-- src/timeline-window.js | 12 +++---- 24 files changed, 92 insertions(+), 92 deletions(-) diff --git a/spec/TestClient.js b/spec/TestClient.js index a4ceebddd..a4f789110 100644 --- a/spec/TestClient.js +++ b/spec/TestClient.js @@ -118,7 +118,7 @@ TestClient.prototype.expectDeviceKeyUpload = function() { TestClient.prototype.awaitOneTimeKeyUpload = function() { if (Object.keys(this.oneTimeKeys).length != 0) { // already got one-time keys - return q(this.oneTimeKeys); + return Promise.resolve(this.oneTimeKeys); } this.httpBackend.when("POST", "/keys/upload") diff --git a/spec/integ/matrix-client-crypto.spec.js b/spec/integ/matrix-client-crypto.spec.js index b1734e59c..94429a960 100644 --- a/spec/integ/matrix-client-crypto.spec.js +++ b/spec/integ/matrix-client-crypto.spec.js @@ -406,19 +406,19 @@ describe("MatrixClient crypto", function() { }); it("Bob uploads device keys", function() { - return q() + return Promise.resolve() .then(bobUploadsDeviceKeys); }); it("Ali downloads Bobs device keys", function(done) { - q() + Promise.resolve() .then(bobUploadsDeviceKeys) .then(aliDownloadsKeys) .nodeify(done); }); it("Ali gets keys with an invalid signature", function(done) { - q() + Promise.resolve() .then(bobUploadsDeviceKeys) .then(function() { // tamper bob's keys @@ -515,7 +515,7 @@ describe("MatrixClient crypto", function() { it("Bob starts his client and uploads device keys and one-time keys", function() { - return q() + return Promise.resolve() .then(() => bobTestClient.start()) .then(() => bobTestClient.awaitOneTimeKeyUpload()) .then((keys) => { @@ -525,7 +525,7 @@ describe("MatrixClient crypto", function() { }); it("Ali sends a message", function(done) { - q() + Promise.resolve() .then(() => aliTestClient.start()) .then(() => bobTestClient.start()) .then(() => firstSync(aliTestClient)) @@ -535,7 +535,7 @@ describe("MatrixClient crypto", function() { }); it("Bob receives a message", function(done) { - q() + Promise.resolve() .then(() => aliTestClient.start()) .then(() => bobTestClient.start()) .then(() => firstSync(aliTestClient)) @@ -546,7 +546,7 @@ describe("MatrixClient crypto", function() { }); it("Bob receives a message with a bogus sender", function(done) { - q() + Promise.resolve() .then(() => aliTestClient.start()) .then(() => bobTestClient.start()) .then(() => firstSync(aliTestClient)) @@ -603,7 +603,7 @@ describe("MatrixClient crypto", function() { }); it("Ali blocks Bob's device", function(done) { - q() + Promise.resolve() .then(() => aliTestClient.start()) .then(() => bobTestClient.start()) .then(() => firstSync(aliTestClient)) @@ -622,7 +622,7 @@ describe("MatrixClient crypto", function() { }); it("Bob receives two pre-key messages", function(done) { - q() + Promise.resolve() .then(() => aliTestClient.start()) .then(() => bobTestClient.start()) .then(() => firstSync(aliTestClient)) @@ -635,7 +635,7 @@ describe("MatrixClient crypto", function() { }); it("Bob replies to the message", function() { - return q() + return Promise.resolve() .then(() => aliTestClient.start()) .then(() => bobTestClient.start()) .then(() => firstSync(aliTestClient)) @@ -652,7 +652,7 @@ describe("MatrixClient crypto", function() { it("Ali does a key query when encryption is enabled", function() { // enabling encryption in the room should make alice download devices // for both members. - return q() + return Promise.resolve() .then(() => aliTestClient.start()) .then(() => firstSync(aliTestClient)) .then(() => { diff --git a/spec/unit/crypto/algorithms/megolm.spec.js b/spec/unit/crypto/algorithms/megolm.spec.js index 4c170dc0a..73c71449f 100644 --- a/spec/unit/crypto/algorithms/megolm.spec.js +++ b/spec/unit/crypto/algorithms/megolm.spec.js @@ -125,7 +125,7 @@ describe("MegolmDecryption", function() { const deviceInfo = {}; mockCrypto.getStoredDevice.andReturn(deviceInfo); mockOlmLib.ensureOlmSessionsForDevices.andReturn( - q({'@alice:foo': {'alidevice': { + Promise.resolve({'@alice:foo': {'alidevice': { sessionId: 'alisession', }}}), ); diff --git a/spec/unit/interactive-auth.spec.js b/spec/unit/interactive-auth.spec.js index 6f72785f1..2f810d845 100644 --- a/spec/unit/interactive-auth.spec.js +++ b/spec/unit/interactive-auth.spec.js @@ -81,7 +81,7 @@ describe("InteractiveAuth", function() { type: "logintype", foo: "bar", }); - return q(requestRes); + return Promise.resolve(requestRes); }); ia.attemptAuth().then(function(res) { @@ -138,7 +138,7 @@ describe("InteractiveAuth", function() { type: "logintype", foo: "bar", }); - return q(requestRes); + return Promise.resolve(requestRes); }); ia.submitAuthDict({ diff --git a/spec/unit/matrix-client.spec.js b/spec/unit/matrix-client.spec.js index 25444365d..f6a338658 100644 --- a/spec/unit/matrix-client.spec.js +++ b/spec/unit/matrix-client.spec.js @@ -62,7 +62,7 @@ describe("MatrixClient", function() { let pendingLookup = null; function httpReq(cb, method, path, qp, data, prefix) { if (path === KEEP_ALIVE_PATH && acceptKeepalives) { - return q(); + return Promise.resolve(); } const next = httpLookups.shift(); const logLine = ( @@ -117,7 +117,7 @@ describe("MatrixClient", function() { data: next.error, }); } - return q(next.data); + return Promise.resolve(next.data); } expect(true).toBe(false, "Expected different request. " + logLine); return q.defer().promise; @@ -136,8 +136,8 @@ describe("MatrixClient", function() { "getFilterIdByName", "setFilterIdByName", "getFilter", "storeFilter", "getSyncAccumulator", "startup", "deleteAllData", ].reduce((r, k) => { r[k] = expect.createSpy(); return r; }, {}); - store.getSavedSync = expect.createSpy().andReturn(q(null)); - store.setSyncData = expect.createSpy().andReturn(q(null)); + store.getSavedSync = expect.createSpy().andReturn(Promise.resolve(null)); + store.setSyncData = expect.createSpy().andReturn(Promise.resolve(null)); client = new MatrixClient({ baseUrl: "https://my.home.server", idBaseUrl: identityServerUrl, diff --git a/spec/unit/timeline-window.spec.js b/spec/unit/timeline-window.spec.js index b2c038461..9fe5e96a0 100644 --- a/spec/unit/timeline-window.spec.js +++ b/spec/unit/timeline-window.spec.js @@ -157,7 +157,7 @@ describe("TimelineWindow", function() { client = {}; client.getEventTimeline = function(timelineSet0, eventId0) { expect(timelineSet0).toBe(timelineSet); - return q(timeline); + return Promise.resolve(timeline); }; return new TimelineWindow(client, timelineSet, opts); @@ -191,7 +191,7 @@ describe("TimelineWindow", function() { client.getEventTimeline = function(timelineSet0, eventId0) { expect(timelineSet0).toBe(timelineSet); expect(eventId0).toEqual(eventId); - return q(timeline); + return Promise.resolve(timeline); }; const timelineWindow = new TimelineWindow(client, timelineSet); @@ -219,7 +219,7 @@ describe("TimelineWindow", function() { .toBe(false); expect(timelineWindow.canPaginate(EventTimeline.FORWARDS)) .toBe(false); - return q(timeline); + return Promise.resolve(timeline); }; timelineWindow.load(eventId, 3).then(function() { @@ -383,7 +383,7 @@ describe("TimelineWindow", function() { expect(opts.limit).toEqual(2); addEventsToTimeline(timeline, 3, false); - return q(true); + return Promise.resolve(true); }; timelineWindow.load(eventId, 3).then(function() { @@ -416,7 +416,7 @@ describe("TimelineWindow", function() { expect(opts.limit).toEqual(2); addEventsToTimeline(timeline, 3, true); - return q(true); + return Promise.resolve(true); }; timelineWindow.load(eventId, 3).then(function() { @@ -449,7 +449,7 @@ describe("TimelineWindow", function() { expect(opts.backwards).toBe(false); expect(opts.limit).toEqual(2); paginateCount += 1; - return q(true); + return Promise.resolve(true); }; timelineWindow.load(eventId, 3).then(function() { diff --git a/src/client.js b/src/client.js index 059bb669c..1478e1b9a 100644 --- a/src/client.js +++ b/src/client.js @@ -551,7 +551,7 @@ MatrixClient.prototype.setRoomEncryption = function(roomId, config) { throw new Error("End-to-End encryption disabled"); } this._crypto.setRoomEncryption(roomId, config); - return q(); + return Promise.resolve(); }; /** @@ -730,10 +730,10 @@ MatrixClient.prototype.joinRoom = function(roomIdOrAlias, opts, callback) { const room = this.getRoom(roomIdOrAlias); if (room && room.hasMembershipState(this.credentials.userId, "join")) { - return q(room); + return Promise.resolve(room); } - let sign_promise = q(); + let sign_promise = Promise.resolve(); if (opts.inviteSignUrl) { sign_promise = this._http.requestOtherUrl( @@ -761,7 +761,7 @@ MatrixClient.prototype.joinRoom = function(roomIdOrAlias, opts, callback) { // v2 will do this for us // return syncApi.syncRoom(room); } - return q(room); + return Promise.resolve(room); }).done(function(room) { _resolve(callback, defer, room); }, function(err) { @@ -981,10 +981,10 @@ MatrixClient.prototype.sendEvent = function(roomId, eventType, content, txnId, // marks the event as sent/unsent // returns a promise which resolves with the result of the send request function _sendEvent(client, room, event, callback) { - // Add an extra q() to turn synchronous exceptions into promise rejections, + // Add an extra Promise.resolve() to turn synchronous exceptions into promise rejections, // so that we can handle synchronous and asynchronous exceptions with the // same code path. - return q().then(function() { + return Promise.resolve().then(function() { let encryptionPromise = null; if (client._crypto) { encryptionPromise = client._crypto.encryptEventIfNeeded(event, room); @@ -1238,7 +1238,7 @@ MatrixClient.prototype.sendHtmlEmote = function(roomId, body, htmlBody, callback */ MatrixClient.prototype.sendReceipt = function(event, receiptType, callback) { if (this.isGuest()) { - return q({}); // guests cannot send receipts so don't bother. + return Promise.resolve({}); // guests cannot send receipts so don't bother. } const path = utils.encodeUri("/rooms/$roomId/receipt/$receiptType/$eventId", { @@ -1315,7 +1315,7 @@ MatrixClient.prototype.getUrlPreview = function(url, ts, callback) { const key = ts + "_" + url; const og = this.urlPreviewCache[key]; if (og) { - return q(og); + return Promise.resolve(og); } const self = this; @@ -1341,7 +1341,7 @@ MatrixClient.prototype.getUrlPreview = function(url, ts, callback) { */ MatrixClient.prototype.sendTyping = function(roomId, isTyping, timeoutMs, callback) { if (this.isGuest()) { - return q({}); // guests cannot send typing notifications so don't bother. + return Promise.resolve({}); // guests cannot send typing notifications so don't bother. } const path = utils.encodeUri("/rooms/$roomId/typing/$userId", { @@ -1742,13 +1742,13 @@ MatrixClient.prototype.scrollback = function(room, limit, callback) { } if (room.oldState.paginationToken === null) { - return q(room); // already at the start. + return Promise.resolve(room); // already at the start. } // attempt to grab more events from the store first const numAdded = this.store.scrollback(room, limit).length; if (numAdded === limit) { // store contained everything we needed. - return q(room); + return Promise.resolve(room); } // reduce the required number of events appropriately limit = limit - numAdded; @@ -1881,7 +1881,7 @@ MatrixClient.prototype.getEventTimeline = function(timelineSet, eventId) { } if (timelineSet.getTimelineForEvent(eventId)) { - return q(timelineSet.getTimelineForEvent(eventId)); + return Promise.resolve(timelineSet.getTimelineForEvent(eventId)); } const path = utils.encodeUri( @@ -1969,7 +1969,7 @@ MatrixClient.prototype.paginateEventTimeline = function(eventTimeline, opts) { const token = eventTimeline.getPaginationToken(dir); if (!token) { // no token - no results. - return q(false); + return Promise.resolve(false); } const pendingRequest = eventTimeline._paginationRequests[dir]; @@ -2146,7 +2146,7 @@ MatrixClient.prototype.setGuestAccess = function(roomId, opts) { guest_access: opts.allowJoin ? "can_join" : "forbidden", }); - let readPromise = q(); + let readPromise = Promise.resolve(); if (opts.allowRead) { readPromise = this.sendStateEvent(roomId, "m.room.history_visibility", { history_visibility: "world_readable", @@ -2624,7 +2624,7 @@ MatrixClient.prototype._processRoomEventsSearch = function(searchResults, respon MatrixClient.prototype.syncLeftRooms = function() { // Guard against multiple calls whilst ongoing and multiple calls post success if (this._syncedLeftRooms) { - return q([]); // don't call syncRooms again if it succeeded. + return Promise.resolve([]); // don't call syncRooms again if it succeeded. } if (this._syncLeftRoomsPromise) { return this._syncLeftRoomsPromise; // return the ongoing request @@ -2683,7 +2683,7 @@ MatrixClient.prototype.getFilter = function(userId, filterId, allowCached) { if (allowCached) { const filter = this.store.getFilter(userId, filterId); if (filter) { - return q(filter); + return Promise.resolve(filter); } } @@ -2712,7 +2712,7 @@ MatrixClient.prototype.getFilter = function(userId, filterId, allowCached) { */ MatrixClient.prototype.getOrCreateFilter = function(filterName, filter) { const filterId = this.store.getFilterIdByName(filterName); - let promise = q(); + let promise = Promise.resolve(); const self = this; if (filterId) { @@ -2727,7 +2727,7 @@ MatrixClient.prototype.getOrCreateFilter = function(filterName, filter) { // super, just use that. // debuglog("Using existing filter ID %s: %s", filterId, // JSON.stringify(oldDef)); - return q(filterId); + return Promise.resolve(filterId); } // debuglog("Existing filter ID %s: %s; new filter: %s", // filterId, JSON.stringify(oldDef), JSON.stringify(newDef)); diff --git a/src/crypto/DeviceList.js b/src/crypto/DeviceList.js index c3bec5c36..ddfdca14a 100644 --- a/src/crypto/DeviceList.js +++ b/src/crypto/DeviceList.js @@ -309,7 +309,7 @@ export default class DeviceList { _doKeyDownload(users) { if (users.length === 0) { // nothing to do - return q(); + return Promise.resolve(); } const prom = this._serialiser.updateDevicesForUsers( @@ -459,7 +459,7 @@ class DeviceListUpdateSerialiser { // // of course we ought to do this in a web worker or similar, but // this serves as an easy solution for now. - let prom = q(); + let prom = Promise.resolve(); for (const userId of downloadUsers) { prom = prom.delay(5).then(() => { this._processQueryResponseForUser(userId, dk[userId]); diff --git a/src/crypto/OutgoingRoomKeyRequestManager.js b/src/crypto/OutgoingRoomKeyRequestManager.js index ab7926fbe..8bc860d62 100644 --- a/src/crypto/OutgoingRoomKeyRequestManager.js +++ b/src/crypto/OutgoingRoomKeyRequestManager.js @@ -251,7 +251,7 @@ export default class OutgoingRoomKeyRequestManager { _sendOutgoingRoomKeyRequests() { if (!this._clientRunning) { this._sendOutgoingRoomKeyRequestsTimer = null; - return q(); + return Promise.resolve(); } console.log("Looking for queued outgoing room key requests"); diff --git a/src/crypto/algorithms/megolm.js b/src/crypto/algorithms/megolm.js index f495b7182..161f93c58 100644 --- a/src/crypto/algorithms/megolm.js +++ b/src/crypto/algorithms/megolm.js @@ -132,7 +132,7 @@ function MegolmEncryption(params) { // are using, and which devices we have shared the keys with. It resolves // with an OutboundSessionInfo (or undefined, for the first message in the // room). - this._setupPromise = q(); + this._setupPromise = Promise.resolve(); // default rotation periods this._sessionRotationPeriodMsgs = 100; @@ -348,7 +348,7 @@ MegolmEncryption.prototype._shareKeyWithDevices = function(session, devicesByUse } if (!haveTargets) { - return q(); + return Promise.resolve(); } // TODO: retries diff --git a/src/crypto/algorithms/olm.js b/src/crypto/algorithms/olm.js index f84951177..eac054189 100644 --- a/src/crypto/algorithms/olm.js +++ b/src/crypto/algorithms/olm.js @@ -60,7 +60,7 @@ OlmEncryption.prototype._ensureSession = function(roomMembers) { if (this._sessionPrepared) { // prep already done - return q(); + return Promise.resolve(); } const self = this; diff --git a/src/crypto/index.js b/src/crypto/index.js index 002a928fd..8e71c4a72 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -287,7 +287,7 @@ function _maybeUploadOneTimeKeys(crypto) { } crypto._oneTimeKeyCheckInProgress = true; - q().then(() => { + Promise.resolve().then(() => { // ask the server how many keys we have return crypto._baseApis.uploadKeysRequest({}, { device_id: crypto._deviceId, @@ -701,7 +701,7 @@ Crypto.prototype.isRoomEncrypted = function(roomId) { * session export objects */ Crypto.prototype.exportRoomKeys = function() { - return q( + return Promise.resolve( this._sessionStore.getAllEndToEndInboundGroupSessionKeys().map( (s) => { const sess = this._olmDevice.exportInboundGroupSession( diff --git a/src/crypto/olmlib.js b/src/crypto/olmlib.js index b365e20e8..476aef57d 100644 --- a/src/crypto/olmlib.js +++ b/src/crypto/olmlib.js @@ -148,7 +148,7 @@ module.exports.ensureOlmSessionsForDevices = function( } if (devicesWithoutSession.length === 0) { - return q(result); + return Promise.resolve(result); } // TODO: this has a race condition - if we try to send another message diff --git a/src/crypto/store/indexeddb-crypto-store-backend.js b/src/crypto/store/indexeddb-crypto-store-backend.js index b9fb9599d..e1d4ff1cc 100644 --- a/src/crypto/store/indexeddb-crypto-store-backend.js +++ b/src/crypto/store/indexeddb-crypto-store-backend.js @@ -146,7 +146,7 @@ export class Backend { */ getOutgoingRoomKeyRequestByState(wantedStates) { if (wantedStates.length === 0) { - return q(null); + return Promise.resolve(null); } // this is a bit tortuous because we need to make sure we do the lookup diff --git a/src/crypto/store/memory-crypto-store.js b/src/crypto/store/memory-crypto-store.js index f0fe8195f..2f71c0e4c 100644 --- a/src/crypto/store/memory-crypto-store.js +++ b/src/crypto/store/memory-crypto-store.js @@ -38,7 +38,7 @@ export default class MemoryCryptoStore { * @returns {Promise} Promise which resolves when the store has been cleared. */ deleteAllData() { - return q(); + return Promise.resolve(); } /** @@ -90,10 +90,10 @@ export default class MemoryCryptoStore { getOutgoingRoomKeyRequest(requestBody) { for (const existing of this._outgoingRoomKeyRequests) { if (utils.deepCompare(existing.requestBody, requestBody)) { - return q(existing); + return Promise.resolve(existing); } } - return q(null); + return Promise.resolve(null); } /** @@ -109,11 +109,11 @@ export default class MemoryCryptoStore { for (const req of this._outgoingRoomKeyRequests) { for (const state of wantedStates) { if (req.state === state) { - return q(req); + return Promise.resolve(req); } } } - return q(null); + return Promise.resolve(null); } /** @@ -139,13 +139,13 @@ export default class MemoryCryptoStore { `Cannot update room key request from ${expectedState} ` + `as it was already updated to ${req.state}`, ); - return q(null); + return Promise.resolve(null); } Object.assign(req, updates); - return q(req); + return Promise.resolve(req); } - return q(null); + return Promise.resolve(null); } /** @@ -170,13 +170,13 @@ export default class MemoryCryptoStore { `Cannot delete room key request in state ${req.state} ` + `(expected ${expectedState})`, ); - return q(null); + return Promise.resolve(null); } this._outgoingRoomKeyRequests.splice(i, 1); - return q(req); + return Promise.resolve(req); } - return q(null); + return Promise.resolve(null); } } diff --git a/src/interactive-auth.js b/src/interactive-auth.js index 1fc582b61..076dd2442 100644 --- a/src/interactive-auth.js +++ b/src/interactive-auth.js @@ -119,7 +119,7 @@ InteractiveAuth.prototype = { // wrap in a promise so that if _startNextAuthStage // throws, it rejects the promise in a consistent way - return q().then(() => { + return Promise.resolve().then(() => { // if we have no flows, try a request (we'll have // just a session ID in _data if resuming) if (!this._data.flows) { @@ -258,7 +258,7 @@ InteractiveAuth.prototype = { // hackery to make sure that synchronous exceptions end up in the catch // handler (without the additional event loop entailed by q.fcall or an - // extra q().then) + // extra Promise.resolve().then) let prom; try { prom = this._requestCallback(auth, background); diff --git a/src/store/indexeddb-local-backend.js b/src/store/indexeddb-local-backend.js index 60c753315..d8d8bfb2b 100644 --- a/src/store/indexeddb-local-backend.js +++ b/src/store/indexeddb-local-backend.js @@ -113,7 +113,7 @@ LocalIndexedDBStoreBackend.prototype = { */ connect: function() { if (this.db) { - return q(); + return Promise.resolve(); } const req = this.indexedDB.open(this._dbName, VERSION); req.onupgradeneeded = (ev) => { @@ -204,18 +204,18 @@ LocalIndexedDBStoreBackend.prototype = { if (copy === undefined) copy = true; const data = this._syncAccumulator.getJSON(); - if (!data.nextBatch) return q(null); + if (!data.nextBatch) return Promise.resolve(null); if (copy) { // We must deep copy the stored data so that the /sync processing code doesn't // corrupt the internal state of the sync accumulator (it adds non-clonable keys) - return q(utils.deepCopy(data)); + return Promise.resolve(utils.deepCopy(data)); } else { - return q(data); + return Promise.resolve(data); } }, setSyncData: function(syncData) { - return q().then(() => { + return Promise.resolve().then(() => { this._syncAccumulator.accumulate(syncData); }); }, diff --git a/src/store/indexeddb-remote-backend.js b/src/store/indexeddb-remote-backend.js index 46a3ff66b..286295944 100644 --- a/src/store/indexeddb-remote-backend.js +++ b/src/store/indexeddb-remote-backend.js @@ -96,7 +96,7 @@ RemoteIndexedDBStoreBackend.prototype = { _doCmd: function(cmd, args) { // wrap in a q so if the postMessage throws, // the promise automatically gets rejected - return q().then(() => { + return Promise.resolve().then(() => { const seq = this._nextSeq++; const def = q.defer(); diff --git a/src/store/indexeddb-store-worker.js b/src/store/indexeddb-store-worker.js index 9ca7a7405..3dc16e855 100644 --- a/src/store/indexeddb-store-worker.js +++ b/src/store/indexeddb-store-worker.js @@ -61,7 +61,7 @@ class IndexedDBStoreWorker { // because it's a web worker and there is no window). indexedDB, msg.args[0], ); - prom = q(); + prom = Promise.resolve(); break; case 'connect': prom = this.backend.connect(); diff --git a/src/store/indexeddb.js b/src/store/indexeddb.js index cd33537ac..c9f84c86a 100644 --- a/src/store/indexeddb.js +++ b/src/store/indexeddb.js @@ -115,7 +115,7 @@ utils.inherits(IndexedDBStore, MatrixInMemoryStore); */ IndexedDBStore.prototype.startup = function() { if (this.startedUp) { - return q(); + return Promise.resolve(); } return this.backend.connect().then(() => { @@ -164,7 +164,7 @@ IndexedDBStore.prototype.save = function() { if (now - this._syncTs > WRITE_DELAY_MS) { return this._reallySave(); } - return q(); + return Promise.resolve(); }; IndexedDBStore.prototype._reallySave = function() { diff --git a/src/store/memory.js b/src/store/memory.js index 7ae5153c7..566c04923 100644 --- a/src/store/memory.js +++ b/src/store/memory.js @@ -284,7 +284,7 @@ module.exports.MatrixInMemoryStore.prototype = { * @return {Promise} An immediately resolved promise. */ setSyncData: function(syncData) { - return q(); + return Promise.resolve(); }, /** @@ -297,7 +297,7 @@ module.exports.MatrixInMemoryStore.prototype = { * @return {Promise} An immediately resolved promise. */ startup: function() { - return q(); + return Promise.resolve(); }, /** @@ -306,7 +306,7 @@ module.exports.MatrixInMemoryStore.prototype = { * is no saved sync data. */ getSavedSync: function() { - return q(null); + return Promise.resolve(null); }, /** @@ -329,6 +329,6 @@ module.exports.MatrixInMemoryStore.prototype = { this.accountData = { // type : content }; - return q(); + return Promise.resolve(); }, }; diff --git a/src/store/stub.js b/src/store/stub.js index 22a2cb230..c8a6c69eb 100644 --- a/src/store/stub.js +++ b/src/store/stub.js @@ -189,7 +189,7 @@ StubStore.prototype = { * @return {Promise} An immediately resolved promise. */ setSyncData: function(syncData) { - return q(); + return Promise.resolve(); }, /** @@ -202,7 +202,7 @@ StubStore.prototype = { * @return {Promise} An immediately resolved promise. */ startup: function() { - return q(); + return Promise.resolve(); }, /** @@ -211,7 +211,7 @@ StubStore.prototype = { * is no saved sync data. */ getSavedSync: function() { - return q(null); + return Promise.resolve(null); }, /** @@ -220,7 +220,7 @@ StubStore.prototype = { * @return {Promise} An immediately resolved promise. */ deleteAllData: function() { - return q(); + return Promise.resolve(); }, }; diff --git a/src/sync.js b/src/sync.js index a75285378..1c14e3d77 100644 --- a/src/sync.js +++ b/src/sync.js @@ -558,7 +558,7 @@ SyncApi.prototype._sync = function(syncOptions) { // if there is data there. syncPromise = client.store.getSavedSync(); } else { - syncPromise = q(null); + syncPromise = Promise.resolve(null); } syncPromise.then((savedSync) => { @@ -600,7 +600,7 @@ SyncApi.prototype._sync = function(syncOptions) { return data; }); } else { - return q(data); + return Promise.resolve(data); } }).done((data) => { try { @@ -1127,7 +1127,7 @@ SyncApi.prototype._resolveInvites = function(room) { const user = client.getUser(member.userId); let promise; if (user) { - promise = q({ + promise = Promise.resolve({ avatar_url: user.avatarUrl, displayname: user.displayName, }); diff --git a/src/timeline-window.js b/src/timeline-window.js index 8b456acd0..a7b0d92f7 100644 --- a/src/timeline-window.js +++ b/src/timeline-window.js @@ -136,14 +136,14 @@ TimelineWindow.prototype.load = function(initialEventId, initialWindowSize) { const promState = prom.inspect(); if (promState.state == 'fulfilled') { initFields(promState.value); - return q(); + return Promise.resolve(); } else { return prom.then(initFields); } } else { const tl = this._timelineSet.getLiveTimeline(); initFields(tl); - return q(); + return Promise.resolve(); } }; @@ -235,7 +235,7 @@ TimelineWindow.prototype.paginate = function(direction, size, makeRequest, if (!tl) { debuglog("TimelineWindow: no timeline yet"); - return q(false); + return Promise.resolve(false); } if (tl.pendingPaginate) { @@ -255,20 +255,20 @@ TimelineWindow.prototype.paginate = function(direction, size, makeRequest, if (excess > 0) { this.unpaginate(excess, direction != EventTimeline.BACKWARDS); } - return q(true); + return Promise.resolve(true); } if (!makeRequest || requestLimit === 0) { // todo: should we return something different to indicate that there // might be more events out there, but we haven't found them yet? - return q(false); + return Promise.resolve(false); } // try making a pagination request const token = tl.timeline.getPaginationToken(direction); if (!token) { debuglog("TimelineWindow: no token"); - return q(false); + return Promise.resolve(false); } debuglog("TimelineWindow: starting request");