From f8d83f8273aa7d66f5df8994f46b119d30db0771 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 25 Nov 2019 14:14:10 +0000 Subject: [PATCH 01/25] Stop using Bluebird::mapSeries --- src/sync.js | 6 +++--- src/utils.js | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/sync.js b/src/sync.js index 590cc16b4..a5e1ab12c 100644 --- a/src/sync.js +++ b/src/sync.js @@ -1150,7 +1150,7 @@ SyncApi.prototype._processSyncResponse = async function( }); // Handle joins - await Promise.mapSeries(joinRooms, async function(joinObj) { + await utils.promiseMapSeries(joinRooms, async function(joinObj) { const room = joinObj.room; const stateEvents = self._mapSyncEventsFormat(joinObj.state, room); const timelineEvents = self._mapSyncEventsFormat(joinObj.timeline, room); @@ -1278,8 +1278,8 @@ SyncApi.prototype._processSyncResponse = async function( } } - await Promise.mapSeries(stateEvents, processRoomEvent); - await Promise.mapSeries(timelineEvents, processRoomEvent); + await utils.promiseMapSeries(stateEvents, processRoomEvent); + await utils.promiseMapSeries(timelineEvents, processRoomEvent); ephemeralEvents.forEach(function(e) { client.emit("event", e); }); diff --git a/src/utils.js b/src/utils.js index 49863ecd8..c24df57aa 100644 --- a/src/utils.js +++ b/src/utils.js @@ -731,3 +731,9 @@ module.exports.defer = () => { return {resolve, reject, promise}; }; + +module.exports.promiseMapSeries = async (promises, fn) => { + for (const o of await promises) { + await fn(await o); + } +}; From fddf2843b4acda43d1a419e20ec0e1a42e0c72ca Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 25 Nov 2019 14:22:07 +0000 Subject: [PATCH 02/25] Replace Bluebird.try --- src/crypto/store/memory-crypto-store.js | 2 +- src/store/indexeddb-local-backend.js | 12 ++++++------ src/utils.js | 10 ++++++++++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/crypto/store/memory-crypto-store.js b/src/crypto/store/memory-crypto-store.js index 2897be81e..f3bab6516 100644 --- a/src/crypto/store/memory-crypto-store.js +++ b/src/crypto/store/memory-crypto-store.js @@ -69,7 +69,7 @@ export default class MemoryCryptoStore { getOrAddOutgoingRoomKeyRequest(request) { const requestBody = request.requestBody; - return Promise.try(() => { + return utils.promiseTry(() => { // first see if we already have an entry for this request. const existing = this._getOutgoingRoomKeyRequest(requestBody); diff --git a/src/store/indexeddb-local-backend.js b/src/store/indexeddb-local-backend.js index b1ddb144d..cbebb6c17 100644 --- a/src/store/indexeddb-local-backend.js +++ b/src/store/indexeddb-local-backend.js @@ -436,7 +436,7 @@ LocalIndexedDBStoreBackend.prototype = { */ _persistSyncData: function(nextBatch, roomsData, groupsData) { logger.log("Persisting sync data up to ", nextBatch); - return Promise.try(() => { + return utils.promiseTry(() => { const txn = this.db.transaction(["sync"], "readwrite"); const store = txn.objectStore("sync"); store.put({ @@ -456,7 +456,7 @@ LocalIndexedDBStoreBackend.prototype = { * @return {Promise} Resolves if the events were persisted. */ _persistAccountData: function(accountData) { - return Promise.try(() => { + return utils.promiseTry(() => { const txn = this.db.transaction(["accountData"], "readwrite"); const store = txn.objectStore("accountData"); for (let i = 0; i < accountData.length; i++) { @@ -475,7 +475,7 @@ LocalIndexedDBStoreBackend.prototype = { * @return {Promise} Resolves if the users were persisted. */ _persistUserPresenceEvents: function(tuples) { - return Promise.try(() => { + return utils.promiseTry(() => { const txn = this.db.transaction(["users"], "readwrite"); const store = txn.objectStore("users"); for (const tuple of tuples) { @@ -495,7 +495,7 @@ LocalIndexedDBStoreBackend.prototype = { * @return {Promise} A list of presence events in their raw form. */ getUserPresenceEvents: function() { - return Promise.try(() => { + return utils.promiseTry(() => { const txn = this.db.transaction(["users"], "readonly"); const store = txn.objectStore("users"); return selectQuery(store, undefined, (cursor) => { @@ -512,7 +512,7 @@ LocalIndexedDBStoreBackend.prototype = { logger.log( `LocalIndexedDBStoreBackend: loading account data...`, ); - return Promise.try(() => { + return utils.promiseTry(() => { const txn = this.db.transaction(["accountData"], "readonly"); const store = txn.objectStore("accountData"); return selectQuery(store, undefined, (cursor) => { @@ -534,7 +534,7 @@ LocalIndexedDBStoreBackend.prototype = { logger.log( `LocalIndexedDBStoreBackend: loading sync data...`, ); - return Promise.try(() => { + return utils.promiseTry(() => { const txn = this.db.transaction(["sync"], "readonly"); const store = txn.objectStore("sync"); return selectQuery(store, undefined, (cursor) => { diff --git a/src/utils.js b/src/utils.js index c24df57aa..2cf2dc509 100644 --- a/src/utils.js +++ b/src/utils.js @@ -737,3 +737,13 @@ module.exports.promiseMapSeries = async (promises, fn) => { await fn(await o); } }; + +module.exports.promiseTry = (fn) => { + return new Promise((resolve, reject) => { + try { + fn().then(resolve, reject); + } catch (e) { + reject(e); + } + }); +}; From bab45821397e0b05c4c5923473bae0be14ca1cdc Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 25 Nov 2019 14:33:25 +0000 Subject: [PATCH 03/25] Replace more Bluebirdy stuffs --- spec/unit/crypto/DeviceList.spec.js | 8 +++--- spec/unit/crypto/algorithms/megolm.spec.js | 4 +-- spec/unit/crypto/backup.spec.js | 2 +- spec/unit/scheduler.spec.js | 29 +++++++++++----------- src/crypto/DeviceList.js | 4 +-- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/spec/unit/crypto/DeviceList.spec.js b/spec/unit/crypto/DeviceList.spec.js index 14d4d91e3..f86cbd1c5 100644 --- a/spec/unit/crypto/DeviceList.spec.js +++ b/spec/unit/crypto/DeviceList.spec.js @@ -87,7 +87,7 @@ describe('DeviceList', function() { dl.startTrackingDeviceList('@test1:sw1v.org'); - const queryDefer1 = Promise.defer(); + const queryDefer1 = utils.defer(); downloadSpy.mockReturnValue(queryDefer1.promise); const prom1 = dl.refreshOutdatedDeviceLists(); @@ -106,7 +106,7 @@ describe('DeviceList', function() { dl.startTrackingDeviceList('@test1:sw1v.org'); - const queryDefer1 = Promise.defer(); + const queryDefer1 = utils.defer(); downloadSpy.mockReturnValue(queryDefer1.promise); const prom1 = dl.refreshOutdatedDeviceLists(); @@ -114,7 +114,7 @@ describe('DeviceList', function() { downloadSpy.mockReset(); // outdated notif arrives while the request is in flight. - const queryDefer2 = Promise.defer(); + const queryDefer2 = utils.defer(); downloadSpy.mockReturnValue(queryDefer2.promise); dl.invalidateUserDeviceList('@test1:sw1v.org'); @@ -134,7 +134,7 @@ describe('DeviceList', function() { logger.log("Creating new devicelist to simulate app reload"); downloadSpy.mockReset(); const dl2 = createTestDeviceList(); - const queryDefer3 = Promise.defer(); + const queryDefer3 = utils.defer(); downloadSpy.mockReturnValue(queryDefer3.promise); const prom3 = dl2.refreshOutdatedDeviceLists(); diff --git a/spec/unit/crypto/algorithms/megolm.spec.js b/spec/unit/crypto/algorithms/megolm.spec.js index ad5e7f20a..77b185b23 100644 --- a/spec/unit/crypto/algorithms/megolm.spec.js +++ b/spec/unit/crypto/algorithms/megolm.spec.js @@ -56,7 +56,7 @@ describe("MegolmDecryption", function() { mockOlmLib = {}; mockOlmLib.ensureOlmSessionsForDevices = jest.fn(); mockOlmLib.encryptMessageForDevice = - jest.fn().mockReturnValue(Promise.resolve()); + jest.fn().mockResolvedValue(undefined); megolmDecryption.olmlib = mockOlmLib; }); @@ -282,7 +282,7 @@ describe("MegolmDecryption", function() { }, }, })); - mockBaseApis.sendToDevice = jest.fn().mockReturnValue(Promise.resolve()); + mockBaseApis.sendToDevice = jest.fn().mockResolvedValue(undefined); mockCrypto.downloadKeys.mockReturnValue(Promise.resolve({ '@alice:home.server': { diff --git a/spec/unit/crypto/backup.spec.js b/spec/unit/crypto/backup.spec.js index 7413ee0da..6a7ed7e24 100644 --- a/spec/unit/crypto/backup.spec.js +++ b/spec/unit/crypto/backup.spec.js @@ -157,7 +157,7 @@ describe("MegolmBackup", function() { mockOlmLib = {}; mockOlmLib.ensureOlmSessionsForDevices = jest.fn(); mockOlmLib.encryptMessageForDevice = - jest.fn().mockReturnValue(Promise.resolve()); + jest.fn().mockResolvedValue(undefined); }); describe("backup", function() { diff --git a/spec/unit/scheduler.spec.js b/spec/unit/scheduler.spec.js index 941223a5a..cf41ceed4 100644 --- a/spec/unit/scheduler.spec.js +++ b/spec/unit/scheduler.spec.js @@ -3,6 +3,7 @@ import 'source-map-support/register'; import Promise from 'bluebird'; +import {defer} from '../../src/utils'; const sdk = require("../.."); const MatrixScheduler = sdk.MatrixScheduler; const MatrixError = sdk.MatrixError; @@ -14,7 +15,7 @@ describe("MatrixScheduler", function() { let scheduler; let retryFn; let queueFn; - let defer; + let deferred; const roomId = "!foo:bar"; const eventA = utils.mkMessage({ user: "@alice:bar", room: roomId, event: true, @@ -37,7 +38,7 @@ describe("MatrixScheduler", function() { }); retryFn = null; queueFn = null; - defer = Promise.defer(); + deferred = defer(); }); it("should process events in a queue in a FIFO manner", async function() { @@ -47,8 +48,8 @@ describe("MatrixScheduler", function() { queueFn = function() { return "one_big_queue"; }; - const deferA = Promise.defer(); - const deferB = Promise.defer(); + const deferA = defer(); + const deferB = defer(); let yieldedA = false; scheduler.setProcessFunction(function(event) { if (yieldedA) { @@ -74,7 +75,7 @@ describe("MatrixScheduler", function() { it("should invoke the retryFn on failure and wait the amount of time specified", async function() { const waitTimeMs = 1500; - const retryDefer = Promise.defer(); + const retryDefer = defer(); retryFn = function() { retryDefer.resolve(); return waitTimeMs; @@ -88,9 +89,9 @@ describe("MatrixScheduler", function() { procCount += 1; if (procCount === 1) { expect(ev).toEqual(eventA); - return defer.promise; + return deferred.promise; } else if (procCount === 2) { - // don't care about this defer + // don't care about this deferred return new Promise(); } expect(procCount).toBeLessThan(3); @@ -101,7 +102,7 @@ describe("MatrixScheduler", function() { // wait just long enough before it does await Promise.resolve(); expect(procCount).toEqual(1); - defer.reject({}); + deferred.reject({}); await retryDefer.promise; expect(procCount).toEqual(1); jest.advanceTimersByTime(waitTimeMs); @@ -121,8 +122,8 @@ describe("MatrixScheduler", function() { return "yep"; }; - const deferA = Promise.defer(); - const deferB = Promise.defer(); + const deferA = defer(); + const deferB = defer(); let procCount = 0; scheduler.setProcessFunction(function(ev) { procCount += 1; @@ -177,14 +178,14 @@ describe("MatrixScheduler", function() { const expectOrder = [ eventA.getId(), eventB.getId(), eventD.getId(), ]; - const deferA = Promise.defer(); + const deferA = defer(); scheduler.setProcessFunction(function(event) { const id = expectOrder.shift(); expect(id).toEqual(event.getId()); if (expectOrder.length === 0) { done(); } - return id === eventA.getId() ? deferA.promise : defer.promise; + return id === eventA.getId() ? deferA.promise : deferred.promise; }); scheduler.queueEvent(eventA); scheduler.queueEvent(eventB); @@ -298,7 +299,7 @@ describe("MatrixScheduler", function() { scheduler.setProcessFunction(function(ev) { procCount += 1; expect(ev).toEqual(eventA); - return defer.promise; + return deferred.promise; }); // as queueing doesn't start processing synchronously anymore (see commit bbdb5ac) // wait just long enough before it does @@ -314,7 +315,7 @@ describe("MatrixScheduler", function() { let procCount = 0; scheduler.setProcessFunction(function(ev) { procCount += 1; - return defer.promise; + return deferred.promise; }); expect(procCount).toEqual(0); }); diff --git a/src/crypto/DeviceList.js b/src/crypto/DeviceList.js index 27b1a23e4..5ebd660dd 100644 --- a/src/crypto/DeviceList.js +++ b/src/crypto/DeviceList.js @@ -31,7 +31,7 @@ import DeviceInfo from './deviceinfo'; import {CrossSigningInfo} from './CrossSigning'; import olmlib from './olmlib'; import IndexedDBCryptoStore from './store/indexeddb-crypto-store'; -import {sleep} from '../utils'; +import {defer, sleep} from '../utils'; /* State transition diagram for DeviceList._deviceTrackingStatus @@ -711,7 +711,7 @@ class DeviceListUpdateSerialiser { }); if (!this._queuedQueryDeferred) { - this._queuedQueryDeferred = Promise.defer(); + this._queuedQueryDeferred = defer(); } // We always take the new sync token and just use the latest one we've From 733008cfc48aa8e66fc5d8a4b06cecd3c7d470fd Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 25 Nov 2019 14:48:45 +0000 Subject: [PATCH 04/25] delint and replace more defers --- spec/unit/crypto/DeviceList.spec.js | 2 -- src/http-api.js | 6 +++--- src/scheduler.js | 2 +- src/sync.js | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/spec/unit/crypto/DeviceList.spec.js b/spec/unit/crypto/DeviceList.spec.js index f86cbd1c5..170bc0cb6 100644 --- a/spec/unit/crypto/DeviceList.spec.js +++ b/spec/unit/crypto/DeviceList.spec.js @@ -20,8 +20,6 @@ import MemoryCryptoStore from '../../../lib/crypto/store/memory-crypto-store.js' import utils from '../../../lib/utils'; import logger from '../../../src/logger'; -import Promise from 'bluebird'; - const signedDeviceList = { "failures": {}, "device_keys": { diff --git a/src/http-api.js b/src/http-api.js index 4babe9f51..d863c8154 100644 --- a/src/http-api.js +++ b/src/http-api.js @@ -256,7 +256,7 @@ module.exports.MatrixHttpApi.prototype = { } if (global.XMLHttpRequest) { - const defer = Promise.defer(); + const defer = utils.defer(); const xhr = new global.XMLHttpRequest(); upload.xhr = xhr; const cb = requestCallback(defer, opts.callback, this.opts.onlyData); @@ -418,7 +418,7 @@ module.exports.MatrixHttpApi.prototype = { opts.headers['Authorization'] = `Bearer ${accessToken}`; } - const defer = Promise.defer(); + const defer = utils.defer(); this.opts.request( opts, requestCallback(defer, callback, this.opts.onlyData), @@ -682,7 +682,7 @@ module.exports.MatrixHttpApi.prototype = { } } - const defer = Promise.defer(); + const defer = utils.defer(); let timeoutId; let timedOut = false; diff --git a/src/scheduler.js b/src/scheduler.js index 1b8d46f67..e69bfb270 100644 --- a/src/scheduler.js +++ b/src/scheduler.js @@ -121,7 +121,7 @@ MatrixScheduler.prototype.queueEvent = function(event) { if (!this._queues[queueName]) { this._queues[queueName] = []; } - const defer = Promise.defer(); + const defer = utils.defer(); this._queues[queueName].push({ event: event, defer: defer, diff --git a/src/sync.js b/src/sync.js index a5e1ab12c..9a7bbc2aa 100644 --- a/src/sync.js +++ b/src/sync.js @@ -1383,7 +1383,7 @@ SyncApi.prototype._startKeepAlives = function(delay) { self._pokeKeepAlive(); } if (!this._connectionReturnedDefer) { - this._connectionReturnedDefer = Promise.defer(); + this._connectionReturnedDefer = utils.defer(); } return this._connectionReturnedDefer.promise; }; From 64bf145e4b8128d15a8b4df138d69c9e08de4771 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 25 Nov 2019 14:50:40 +0000 Subject: [PATCH 05/25] Replace rest of defers --- spec/test-utils.js | 8 ++++---- spec/unit/matrix-client.spec.js | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/test-utils.js b/spec/test-utils.js index 16ec18898..022f84e8c 100644 --- a/spec/test-utils.js +++ b/spec/test-utils.js @@ -256,7 +256,7 @@ HttpResponse.prototype.request = function HttpResponse( if (!next) { // no more things to return if (method === "GET" && path === "/sync" && this.ignoreUnhandledSync) { logger.log("MatrixClient[UT] Ignoring."); - return Promise.defer().promise; + return new Promise(() => {}); } if (this.pendingLookup) { if (this.pendingLookup.method === method @@ -271,7 +271,7 @@ HttpResponse.prototype.request = function HttpResponse( ); } this.pendingLookup = { - promise: Promise.defer().promise, + promise: new Promise(() => {}), method: method, path: path, }; @@ -308,10 +308,10 @@ HttpResponse.prototype.request = function HttpResponse( } else if (method === "GET" && path === "/sync" && this.ignoreUnhandledSync) { logger.log("MatrixClient[UT] Ignoring."); this.httpLookups.unshift(next); - return Promise.defer().promise; + return new Promise(() => {}); } expect(true).toBe(false, "Expected different request. " + logLine); - return Promise.defer().promise; + return new Promise(() => {}); }; HttpResponse.KEEP_ALIVE_PATH = "/_matrix/client/versions"; diff --git a/spec/unit/matrix-client.spec.js b/spec/unit/matrix-client.spec.js index 19f426609..bf752c3ca 100644 --- a/spec/unit/matrix-client.spec.js +++ b/spec/unit/matrix-client.spec.js @@ -83,7 +83,7 @@ describe("MatrixClient", function() { ); } pendingLookup = { - promise: Promise.defer().promise, + promise: new Promise(() => {}), method: method, path: path, }; @@ -119,7 +119,7 @@ describe("MatrixClient", function() { return Promise.resolve(next.data); } expect(true).toBe(false, "Expected different request. " + logLine); - return Promise.defer().promise; + return new Promise(() => {}); } beforeEach(function() { @@ -171,7 +171,7 @@ describe("MatrixClient", function() { // a DIFFERENT test (pollution between tests!) - we return unresolved // promises to stop the client from continuing to run. client._http.authedRequest.mockImplementation(function() { - return Promise.defer().promise; + return new Promise(() => {}); }); }); From 9faab093f7feb72710e0181b1c7b9b484fe6ddb4 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 25 Nov 2019 14:51:01 +0000 Subject: [PATCH 06/25] delint --- src/http-api.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/http-api.js b/src/http-api.js index d863c8154..0d6aecd1d 100644 --- a/src/http-api.js +++ b/src/http-api.js @@ -19,7 +19,6 @@ limitations under the License. * This is an internal module. See {@link MatrixHttpApi} for the public class. * @module http-api */ -import Promise from 'bluebird'; const parseContentType = require('content-type').parse; const utils = require("./utils"); From 1286007b2eb2e2cb117c7cdb24c72f266e6c30d1 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 25 Nov 2019 15:24:41 +0000 Subject: [PATCH 07/25] Rip out bluebird of a bunch of places, lots to go :( --- spec/integ/devicelist-integ-spec.js | 2 -- spec/integ/matrix-client-crypto.spec.js | 1 - .../integ/matrix-client-event-emitter.spec.js | 4 +--- .../matrix-client-event-timeline.spec.js | 3 +-- spec/integ/matrix-client-opts.spec.js | 16 ++++++-------- spec/integ/matrix-client-retrying.spec.js | 1 - .../integ/matrix-client-room-timeline.spec.js | 22 +++++++++---------- spec/integ/matrix-client-syncing.spec.js | 6 ++--- spec/integ/megolm-integ.spec.js | 1 - spec/unit/autodiscovery.spec.js | 1 - spec/unit/crypto/algorithms/megolm.spec.js | 10 ++++----- spec/unit/crypto/backup.spec.js | 2 -- spec/unit/event.spec.js | 1 - spec/unit/interactive-auth.spec.js | 1 - spec/unit/scheduler.spec.js | 1 - spec/unit/timeline-window.spec.js | 1 - src/crypto/algorithms/megolm.js | 2 +- src/store/indexeddb-local-backend.js | 1 - src/store/indexeddb.js | 1 - 19 files changed, 26 insertions(+), 51 deletions(-) diff --git a/spec/integ/devicelist-integ-spec.js b/spec/integ/devicelist-integ-spec.js index 1d033c2f0..4c73ea7c8 100644 --- a/spec/integ/devicelist-integ-spec.js +++ b/spec/integ/devicelist-integ-spec.js @@ -15,8 +15,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -import Promise from 'bluebird'; - import TestClient from '../TestClient'; import testUtils from '../test-utils'; import logger from '../../src/logger'; diff --git a/spec/integ/matrix-client-crypto.spec.js b/spec/integ/matrix-client-crypto.spec.js index d74009177..4845f6338 100644 --- a/spec/integ/matrix-client-crypto.spec.js +++ b/spec/integ/matrix-client-crypto.spec.js @@ -31,7 +31,6 @@ import 'source-map-support/register'; import '../olm-loader'; const sdk = require("../.."); -import Promise from 'bluebird'; const utils = require("../../lib/utils"); const testUtils = require("../test-utils"); const TestClient = require('../TestClient').default; diff --git a/spec/integ/matrix-client-event-emitter.spec.js b/spec/integ/matrix-client-event-emitter.spec.js index 90fa5db8f..62381171e 100644 --- a/spec/integ/matrix-client-event-emitter.spec.js +++ b/spec/integ/matrix-client-event-emitter.spec.js @@ -4,8 +4,6 @@ const sdk = require("../.."); const HttpBackend = require("matrix-mock-request"); const utils = require("../test-utils"); -import Promise from 'bluebird'; - describe("MatrixClient events", function() { const baseUrl = "http://localhost.or.something"; let client; @@ -162,7 +160,7 @@ describe("MatrixClient events", function() { }); client.startClient(); - httpBackend.flushAllExpected().done(function() { + httpBackend.flushAllExpected().then(function() { expect(fired).toBe(true, "User.presence didn't fire."); done(); }); diff --git a/spec/integ/matrix-client-event-timeline.spec.js b/spec/integ/matrix-client-event-timeline.spec.js index 86436c27d..04f9c72f2 100644 --- a/spec/integ/matrix-client-event-timeline.spec.js +++ b/spec/integ/matrix-client-event-timeline.spec.js @@ -1,6 +1,5 @@ "use strict"; import 'source-map-support/register'; -import Promise from 'bluebird'; const sdk = require("../.."); const HttpBackend = require("matrix-mock-request"); const utils = require("../test-utils"); @@ -356,7 +355,7 @@ describe("MatrixClient event timelines", function() { .toEqual("start_token"); // expect(tl.getPaginationToken(EventTimeline.FORWARDS)) // .toEqual("s_5_4"); - }).done(resolve, reject); + }).then(resolve, reject); }); }); diff --git a/spec/integ/matrix-client-opts.spec.js b/spec/integ/matrix-client-opts.spec.js index a4b3083ef..f1a45effa 100644 --- a/spec/integ/matrix-client-opts.spec.js +++ b/spec/integ/matrix-client-opts.spec.js @@ -5,8 +5,6 @@ const MatrixClient = sdk.MatrixClient; const HttpBackend = require("matrix-mock-request"); const utils = require("../test-utils"); -import Promise from 'bluebird'; - describe("MatrixClient opts", function() { const baseUrl = "http://localhost.or.something"; let client = null; @@ -86,7 +84,7 @@ describe("MatrixClient opts", function() { httpBackend.when("PUT", "/txn1").respond(200, { event_id: eventId, }); - client.sendTextMessage("!foo:bar", "a body", "txn1").done(function(res) { + client.sendTextMessage("!foo:bar", "a body", "txn1").then(function(res) { expect(res.event_id).toEqual(eventId); done(); }); @@ -139,7 +137,7 @@ describe("MatrixClient opts", function() { errcode: "M_SOMETHING", error: "Ruh roh", }); - client.sendTextMessage("!foo:bar", "a body", "txn1").done(function(res) { + client.sendTextMessage("!foo:bar", "a body", "txn1").then(function(res) { expect(false).toBe(true, "sendTextMessage resolved but shouldn't"); }, function(err) { expect(err.errcode).toEqual("M_SOMETHING"); @@ -157,16 +155,16 @@ describe("MatrixClient opts", function() { }); let sentA = false; let sentB = false; - client.sendTextMessage("!foo:bar", "a body", "txn1").done(function(res) { + client.sendTextMessage("!foo:bar", "a body", "txn1").then(function(res) { sentA = true; expect(sentB).toBe(true); }); - client.sendTextMessage("!foo:bar", "b body", "txn2").done(function(res) { + client.sendTextMessage("!foo:bar", "b body", "txn2").then(function(res) { sentB = true; expect(sentA).toBe(false); }); - httpBackend.flush("/txn2", 1).done(function() { - httpBackend.flush("/txn1", 1).done(function() { + httpBackend.flush("/txn2", 1).then(function() { + httpBackend.flush("/txn1", 1).then(function() { done(); }); }); @@ -176,7 +174,7 @@ describe("MatrixClient opts", function() { httpBackend.when("PUT", "/txn1").respond(200, { event_id: "foo", }); - client.sendTextMessage("!foo:bar", "a body", "txn1").done(function(res) { + client.sendTextMessage("!foo:bar", "a body", "txn1").then(function(res) { expect(res.event_id).toEqual("foo"); done(); }); diff --git a/spec/integ/matrix-client-retrying.spec.js b/spec/integ/matrix-client-retrying.spec.js index e266ea98b..949f153fc 100644 --- a/spec/integ/matrix-client-retrying.spec.js +++ b/spec/integ/matrix-client-retrying.spec.js @@ -1,6 +1,5 @@ "use strict"; import 'source-map-support/register'; -import Promise from 'bluebird'; const sdk = require("../.."); const HttpBackend = require("matrix-mock-request"); diff --git a/spec/integ/matrix-client-room-timeline.spec.js b/spec/integ/matrix-client-room-timeline.spec.js index b93ec1bc9..20e0d8d84 100644 --- a/spec/integ/matrix-client-room-timeline.spec.js +++ b/spec/integ/matrix-client-room-timeline.spec.js @@ -5,8 +5,6 @@ const EventStatus = sdk.EventStatus; const HttpBackend = require("matrix-mock-request"); const utils = require("../test-utils"); -import Promise from 'bluebird'; - describe("MatrixClient room timelines", function() { const baseUrl = "http://localhost.or.something"; let client = null; @@ -151,7 +149,7 @@ describe("MatrixClient room timelines", function() { expect(member.userId).toEqual(userId); expect(member.name).toEqual(userName); - httpBackend.flush("/sync", 1).done(function() { + httpBackend.flush("/sync", 1).then(function() { done(); }); }); @@ -177,10 +175,10 @@ describe("MatrixClient room timelines", function() { return; } const room = client.getRoom(roomId); - client.sendTextMessage(roomId, "I am a fish", "txn1").done( + client.sendTextMessage(roomId, "I am a fish", "txn1").then( function() { expect(room.timeline[1].getId()).toEqual(eventId); - httpBackend.flush("/sync", 1).done(function() { + httpBackend.flush("/sync", 1).then(function() { expect(room.timeline[1].getId()).toEqual(eventId); done(); }); @@ -210,10 +208,10 @@ describe("MatrixClient room timelines", function() { } const room = client.getRoom(roomId); const promise = client.sendTextMessage(roomId, "I am a fish", "txn1"); - httpBackend.flush("/sync", 1).done(function() { + httpBackend.flush("/sync", 1).then(function() { expect(room.timeline.length).toEqual(2); httpBackend.flush("/txn1", 1); - promise.done(function() { + promise.then(function() { expect(room.timeline.length).toEqual(2); expect(room.timeline[1].getId()).toEqual(eventId); done(); @@ -248,7 +246,7 @@ describe("MatrixClient room timelines", function() { const room = client.getRoom(roomId); expect(room.timeline.length).toEqual(1); - client.scrollback(room).done(function() { + client.scrollback(room).then(function() { expect(room.timeline.length).toEqual(1); expect(room.oldState.paginationToken).toBe(null); @@ -312,7 +310,7 @@ describe("MatrixClient room timelines", function() { // sync response expect(room.timeline.length).toEqual(1); - client.scrollback(room).done(function() { + client.scrollback(room).then(function() { expect(room.timeline.length).toEqual(5); const joinMsg = room.timeline[0]; expect(joinMsg.sender.name).toEqual("Old Alice"); @@ -350,7 +348,7 @@ describe("MatrixClient room timelines", function() { const room = client.getRoom(roomId); expect(room.timeline.length).toEqual(1); - client.scrollback(room).done(function() { + client.scrollback(room).then(function() { expect(room.timeline.length).toEqual(3); expect(room.timeline[0].event).toEqual(sbEvents[1]); expect(room.timeline[1].event).toEqual(sbEvents[0]); @@ -381,11 +379,11 @@ describe("MatrixClient room timelines", function() { const room = client.getRoom(roomId); expect(room.oldState.paginationToken).toBeTruthy(); - client.scrollback(room, 1).done(function() { + client.scrollback(room, 1).then(function() { expect(room.oldState.paginationToken).toEqual(sbEndTok); }); - httpBackend.flush("/messages", 1).done(function() { + httpBackend.flush("/messages", 1).then(function() { // still have a sync to flush httpBackend.flush("/sync", 1).then(() => { done(); diff --git a/spec/integ/matrix-client-syncing.spec.js b/spec/integ/matrix-client-syncing.spec.js index f015943c7..9e406ad50 100644 --- a/spec/integ/matrix-client-syncing.spec.js +++ b/spec/integ/matrix-client-syncing.spec.js @@ -6,8 +6,6 @@ const utils = require("../test-utils"); const MatrixEvent = sdk.MatrixEvent; const EventTimeline = sdk.EventTimeline; -import Promise from 'bluebird'; - describe("MatrixClient syncing", function() { const baseUrl = "http://localhost.or.something"; let client = null; @@ -51,7 +49,7 @@ describe("MatrixClient syncing", function() { client.startClient(); - httpBackend.flushAllExpected().done(function() { + httpBackend.flushAllExpected().then(function() { done(); }); }); @@ -65,7 +63,7 @@ describe("MatrixClient syncing", function() { client.startClient(); - httpBackend.flushAllExpected().done(function() { + httpBackend.flushAllExpected().then(function() { done(); }); }); diff --git a/spec/integ/megolm-integ.spec.js b/spec/integ/megolm-integ.spec.js index 1c1693bfc..45daa0d40 100644 --- a/spec/integ/megolm-integ.spec.js +++ b/spec/integ/megolm-integ.spec.js @@ -17,7 +17,6 @@ limitations under the License. "use strict"; const anotherjson = require('another-json'); -import Promise from 'bluebird'; const utils = require('../../lib/utils'); const testUtils = require('../test-utils'); diff --git a/spec/unit/autodiscovery.spec.js b/spec/unit/autodiscovery.spec.js index 980c2eece..760c03adc 100644 --- a/spec/unit/autodiscovery.spec.js +++ b/spec/unit/autodiscovery.spec.js @@ -16,7 +16,6 @@ limitations under the License. "use strict"; import 'source-map-support/register'; -import Promise from 'bluebird'; const sdk = require("../.."); const AutoDiscovery = sdk.AutoDiscovery; diff --git a/spec/unit/crypto/algorithms/megolm.spec.js b/spec/unit/crypto/algorithms/megolm.spec.js index 77b185b23..d8fd6b148 100644 --- a/spec/unit/crypto/algorithms/megolm.spec.js +++ b/spec/unit/crypto/algorithms/megolm.spec.js @@ -1,7 +1,5 @@ import '../../../olm-loader'; -import Promise from 'bluebird'; - import sdk from '../../../..'; import algorithms from '../../../../lib/crypto/algorithms'; import MemoryCryptoStore from '../../../../lib/crypto/store/memory-crypto-store.js'; @@ -136,11 +134,11 @@ describe("MegolmDecryption", function() { const deviceInfo = {}; mockCrypto.getStoredDevice.mockReturnValue(deviceInfo); - mockOlmLib.ensureOlmSessionsForDevices.mockReturnValue( - Promise.resolve({'@alice:foo': {'alidevice': { + mockOlmLib.ensureOlmSessionsForDevices.mockResolvedValue({ + '@alice:foo': {'alidevice': { sessionId: 'alisession', - }}}), - ); + }}, + }); const awaitEncryptForDevice = new Promise((res, rej) => { mockOlmLib.encryptMessageForDevice.mockImplementation(() => { diff --git a/spec/unit/crypto/backup.spec.js b/spec/unit/crypto/backup.spec.js index 6a7ed7e24..beea0a868 100644 --- a/spec/unit/crypto/backup.spec.js +++ b/spec/unit/crypto/backup.spec.js @@ -16,8 +16,6 @@ limitations under the License. import '../../olm-loader'; -import Promise from 'bluebird'; - import sdk from '../../..'; import algorithms from '../../../lib/crypto/algorithms'; import WebStorageSessionStore from '../../../lib/store/session/webstorage'; diff --git a/spec/unit/event.spec.js b/spec/unit/event.spec.js index cda4580f9..713a698e7 100644 --- a/spec/unit/event.spec.js +++ b/spec/unit/event.spec.js @@ -17,7 +17,6 @@ limitations under the License. import sdk from '../..'; const MatrixEvent = sdk.MatrixEvent; -import Promise from 'bluebird'; import logger from '../../src/logger'; describe("MatrixEvent", () => { diff --git a/spec/unit/interactive-auth.spec.js b/spec/unit/interactive-auth.spec.js index c4633f554..214a5de9a 100644 --- a/spec/unit/interactive-auth.spec.js +++ b/spec/unit/interactive-auth.spec.js @@ -16,7 +16,6 @@ limitations under the License. "use strict"; import 'source-map-support/register'; -import Promise from 'bluebird'; const sdk = require("../.."); const InteractiveAuth = sdk.InteractiveAuth; diff --git a/spec/unit/scheduler.spec.js b/spec/unit/scheduler.spec.js index cf41ceed4..d45e77bab 100644 --- a/spec/unit/scheduler.spec.js +++ b/spec/unit/scheduler.spec.js @@ -2,7 +2,6 @@ /* eslint new-cap: "off" */ import 'source-map-support/register'; -import Promise from 'bluebird'; import {defer} from '../../src/utils'; const sdk = require("../.."); const MatrixScheduler = sdk.MatrixScheduler; diff --git a/spec/unit/timeline-window.spec.js b/spec/unit/timeline-window.spec.js index 35520b1d7..2de036370 100644 --- a/spec/unit/timeline-window.spec.js +++ b/spec/unit/timeline-window.spec.js @@ -1,6 +1,5 @@ "use strict"; import 'source-map-support/register'; -import Promise from 'bluebird'; const sdk = require("../.."); const EventTimeline = sdk.EventTimeline; const TimelineWindow = sdk.TimelineWindow; diff --git a/src/crypto/algorithms/megolm.js b/src/crypto/algorithms/megolm.js index 286c29804..367ef6ae2 100644 --- a/src/crypto/algorithms/megolm.js +++ b/src/crypto/algorithms/megolm.js @@ -1036,7 +1036,7 @@ MegolmDecryption.prototype.shareKeysWithDevice = function(keyRequest) { // TODO: retries return this._baseApis.sendToDevice("m.room.encrypted", contentMap); }); - }).done(); + }); }; MegolmDecryption.prototype._buildKeyForwardingMessage = async function( diff --git a/src/store/indexeddb-local-backend.js b/src/store/indexeddb-local-backend.js index cbebb6c17..587382eb8 100644 --- a/src/store/indexeddb-local-backend.js +++ b/src/store/indexeddb-local-backend.js @@ -15,7 +15,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -import Promise from 'bluebird'; import SyncAccumulator from "../sync-accumulator"; import utils from "../utils"; import * as IndexedDBHelpers from "../indexeddb-helpers"; diff --git a/src/store/indexeddb.js b/src/store/indexeddb.js index f2f759de8..c8eec104c 100644 --- a/src/store/indexeddb.js +++ b/src/store/indexeddb.js @@ -17,7 +17,6 @@ limitations under the License. /* eslint-disable babel/no-invalid-this */ -import Promise from 'bluebird'; import {MemoryStore} from "./memory"; import utils from "../utils"; import {EventEmitter} from 'events'; From edcdeb31eada52c351e7dcdef754632a859c2d52 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 25 Nov 2019 15:38:52 +0000 Subject: [PATCH 08/25] Rip out bluebird of a bunch more places, not as much to go :| --- spec/TestClient.js | 1 - spec/integ/matrix-client-methods.spec.js | 2 +- src/autodiscovery.js | 1 - src/indexeddb-helpers.js | 2 -- src/interactive-auth.js | 1 - src/store/indexeddb-remote-backend.js | 1 - src/store/indexeddb-store-worker.js | 1 - src/store/memory.js | 1 - src/store/stub.js | 1 - src/timeline-window.js | 1 - 10 files changed, 1 insertion(+), 11 deletions(-) diff --git a/spec/TestClient.js b/spec/TestClient.js index 8aeb3c291..805e051d6 100644 --- a/spec/TestClient.js +++ b/spec/TestClient.js @@ -24,7 +24,6 @@ import './olm-loader'; import sdk from '..'; import testUtils from './test-utils'; import MockHttpBackend from 'matrix-mock-request'; -import Promise from 'bluebird'; import LocalStorageCryptoStore from '../lib/crypto/store/localStorage-crypto-store'; import logger from '../src/logger'; diff --git a/spec/integ/matrix-client-methods.spec.js b/spec/integ/matrix-client-methods.spec.js index d8d12e7e3..11d228ae5 100644 --- a/spec/integ/matrix-client-methods.spec.js +++ b/spec/integ/matrix-client-methods.spec.js @@ -181,7 +181,7 @@ describe("MatrixClient", function() { event_format: "client", }); store.storeFilter(filter); - client.getFilter(userId, filterId, true).done(function(gotFilter) { + client.getFilter(userId, filterId, true).then(function(gotFilter) { expect(gotFilter).toEqual(filter); done(); }); diff --git a/src/autodiscovery.js b/src/autodiscovery.js index c8dc8c661..2258eabf4 100644 --- a/src/autodiscovery.js +++ b/src/autodiscovery.js @@ -17,7 +17,6 @@ limitations under the License. /** @module auto-discovery */ -import Promise from 'bluebird'; import logger from './logger'; import { URL as NodeURL } from "url"; diff --git a/src/indexeddb-helpers.js b/src/indexeddb-helpers.js index 68e36d9f4..01123338d 100644 --- a/src/indexeddb-helpers.js +++ b/src/indexeddb-helpers.js @@ -14,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -import Promise from 'bluebird'; - /** * Check if an IndexedDB database exists. The only way to do so is to try opening it, so * we do that and then delete it did not exist before. diff --git a/src/interactive-auth.js b/src/interactive-auth.js index 756756a2e..eb9d9dbaa 100644 --- a/src/interactive-auth.js +++ b/src/interactive-auth.js @@ -18,7 +18,6 @@ limitations under the License. "use strict"; /** @module interactive-auth */ -import Promise from 'bluebird'; const url = require("url"); const utils = require("./utils"); diff --git a/src/store/indexeddb-remote-backend.js b/src/store/indexeddb-remote-backend.js index 270bef961..e17014fb2 100644 --- a/src/store/indexeddb-remote-backend.js +++ b/src/store/indexeddb-remote-backend.js @@ -15,7 +15,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -import Promise from 'bluebird'; import logger from '../logger'; import {defer} from '../utils'; diff --git a/src/store/indexeddb-store-worker.js b/src/store/indexeddb-store-worker.js index c47fcc176..5896cead0 100644 --- a/src/store/indexeddb-store-worker.js +++ b/src/store/indexeddb-store-worker.js @@ -15,7 +15,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -import Promise from 'bluebird'; import LocalIndexedDBStoreBackend from "./indexeddb-local-backend.js"; import logger from '../logger'; diff --git a/src/store/memory.js b/src/store/memory.js index 7a666d071..feeb56501 100644 --- a/src/store/memory.js +++ b/src/store/memory.js @@ -22,7 +22,6 @@ limitations under the License. */ const utils = require("../utils"); const User = require("../models/user"); -import Promise from 'bluebird'; /** * Construct a new in-memory data store for the Matrix Client. diff --git a/src/store/stub.js b/src/store/stub.js index f09dad6d7..2ab2256cd 100644 --- a/src/store/stub.js +++ b/src/store/stub.js @@ -16,7 +16,6 @@ See the License for the specific language governing permissions and limitations under the License. */ "use strict"; -import Promise from 'bluebird'; /** * This is an internal module. * @module store/stub diff --git a/src/timeline-window.js b/src/timeline-window.js index 9d845dd61..03e515c62 100644 --- a/src/timeline-window.js +++ b/src/timeline-window.js @@ -17,7 +17,6 @@ limitations under the License. /** @module timeline-window */ -import Promise from 'bluebird'; const EventTimeline = require("./models/event-timeline"); import logger from './logger'; From 6bba5ca25aed23c8ae77966504809734b99df13a Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 25 Nov 2019 15:45:27 +0000 Subject: [PATCH 09/25] Rip out some more bluebird --- spec/integ/matrix-client-methods.spec.js | 8 ++++---- src/client.js | 2 +- src/crypto/DeviceList.js | 2 +- src/sync.js | 6 +++--- src/utils.js | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/spec/integ/matrix-client-methods.spec.js b/spec/integ/matrix-client-methods.spec.js index 11d228ae5..6b2a83df0 100644 --- a/spec/integ/matrix-client-methods.spec.js +++ b/spec/integ/matrix-client-methods.spec.js @@ -202,7 +202,7 @@ describe("MatrixClient", function() { event_format: "client", }); store.storeFilter(storeFilter); - client.getFilter(userId, filterId, false).done(function(gotFilter) { + client.getFilter(userId, filterId, false).then(function(gotFilter) { expect(gotFilter.getDefinition()).toEqual(httpFilterDefinition); done(); }); @@ -220,7 +220,7 @@ describe("MatrixClient", function() { httpBackend.when( "GET", "/user/" + encodeURIComponent(userId) + "/filter/" + filterId, ).respond(200, httpFilterDefinition); - client.getFilter(userId, filterId, true).done(function(gotFilter) { + client.getFilter(userId, filterId, true).then(function(gotFilter) { expect(gotFilter.getDefinition()).toEqual(httpFilterDefinition); expect(store.getFilter(userId, filterId)).toBeTruthy(); done(); @@ -248,7 +248,7 @@ describe("MatrixClient", function() { filter_id: filterId, }); - client.createFilter(filterDefinition).done(function(gotFilter) { + client.createFilter(filterDefinition).then(function(gotFilter) { expect(gotFilter.getDefinition()).toEqual(filterDefinition); expect(store.getFilter(userId, filterId)).toEqual(gotFilter); done(); @@ -295,7 +295,7 @@ describe("MatrixClient", function() { }); }).respond(200, response); - httpBackend.flush().done(function() { + httpBackend.flush().then(function() { done(); }); }); diff --git a/src/client.js b/src/client.js index 715580d01..098b3ea6e 100644 --- a/src/client.js +++ b/src/client.js @@ -3224,7 +3224,7 @@ MatrixClient.prototype.scrollback = function(room, limit, callback) { room.oldState.paginationToken, limit, 'b'); - }).done(function(res) { + }).then(function(res) { const matrixEvents = utils.map(res.chunk, _PojoToMatrixEventMapper(self)); if (res.state) { const stateEvents = utils.map(res.state, _PojoToMatrixEventMapper(self)); diff --git a/src/crypto/DeviceList.js b/src/crypto/DeviceList.js index 5ebd660dd..8936c4ae3 100644 --- a/src/crypto/DeviceList.js +++ b/src/crypto/DeviceList.js @@ -776,7 +776,7 @@ class DeviceListUpdateSerialiser { } return prom; - }).done(() => { + }).then(() => { logger.log('Completed key download for ' + downloadUsers); this._downloadInProgress = false; diff --git a/src/sync.js b/src/sync.js index 9a7bbc2aa..c516cdcf9 100644 --- a/src/sync.js +++ b/src/sync.js @@ -360,7 +360,7 @@ SyncApi.prototype._peekPoll = function(peekRoom, token) { room_id: peekRoom.roomId, timeout: 30 * 1000, from: token, - }, undefined, 50 * 1000).done(function(res) { + }, undefined, 50 * 1000).then(function(res) { if (self._peekRoomId !== peekRoom.roomId) { debuglog("Stopped peeking in room %s", peekRoom.roomId); return; @@ -1417,7 +1417,7 @@ SyncApi.prototype._pokeKeepAlive = function(connDidFail) { prefix: '', localTimeoutMs: 15 * 1000, }, - ).done(function() { + ).then(function() { success(); }, function(err) { if (err.httpStatus == 400 || err.httpStatus == 404) { @@ -1541,7 +1541,7 @@ SyncApi.prototype._resolveInvites = function(room) { } else { promise = client.getProfileInfo(member.userId); } - promise.done(function(info) { + promise.then(function(info) { // slightly naughty by doctoring the invite event but this means all // the code paths remain the same between invite/join display name stuff // which is a worthy trade-off for some minor pollution. diff --git a/src/utils.js b/src/utils.js index 2cf2dc509..11887c801 100644 --- a/src/utils.js +++ b/src/utils.js @@ -21,7 +21,7 @@ limitations under the License. */ const unhomoglyph = require('unhomoglyph'); -import Promise from 'bluebird'; +// import Promise from 'bluebird'; /** * Encode a dictionary of query parameters. From 0170cb066d66500a4418d548e6422690cf9764e9 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 25 Nov 2019 15:46:45 +0000 Subject: [PATCH 10/25] add another clean-up to sas.spec.js --- spec/unit/crypto/verification/sas.spec.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/unit/crypto/verification/sas.spec.js b/spec/unit/crypto/verification/sas.spec.js index 3c9aa666e..638c48405 100644 --- a/spec/unit/crypto/verification/sas.spec.js +++ b/spec/unit/crypto/verification/sas.spec.js @@ -497,6 +497,12 @@ describe("SAS verification", function() { } }); }); + afterEach(async function() { + await Promise.all([ + alice.stop(), + bob.stop(), + ]); + }); it("should verify a key", async function() { await Promise.all([ From efcaadd0b4492f7e8ce5b0622910f96107ce7c83 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 25 Nov 2019 16:58:46 +0000 Subject: [PATCH 11/25] Rip out more bluebirds --- src/crypto/OutgoingRoomKeyRequestManager.js | 2 -- src/crypto/algorithms/base.js | 2 -- src/crypto/algorithms/megolm.js | 2 +- src/crypto/algorithms/olm.js | 3 --- src/crypto/olmlib.js | 1 - src/utils.js | 1 - 6 files changed, 1 insertion(+), 10 deletions(-) diff --git a/src/crypto/OutgoingRoomKeyRequestManager.js b/src/crypto/OutgoingRoomKeyRequestManager.js index 3af19f3c9..ef435e9c8 100644 --- a/src/crypto/OutgoingRoomKeyRequestManager.js +++ b/src/crypto/OutgoingRoomKeyRequestManager.js @@ -14,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -import Promise from 'bluebird'; - import logger from '../logger'; import utils from '../utils'; diff --git a/src/crypto/algorithms/base.js b/src/crypto/algorithms/base.js index 40c60a439..d5e38f477 100644 --- a/src/crypto/algorithms/base.js +++ b/src/crypto/algorithms/base.js @@ -20,8 +20,6 @@ limitations under the License. * @module */ -import Promise from 'bluebird'; - /** * map of registered encryption algorithm classes. A map from string to {@link * module:crypto/algorithms/base.EncryptionAlgorithm|EncryptionAlgorithm} class diff --git a/src/crypto/algorithms/megolm.js b/src/crypto/algorithms/megolm.js index 367ef6ae2..8fb7c7962 100644 --- a/src/crypto/algorithms/megolm.js +++ b/src/crypto/algorithms/megolm.js @@ -508,7 +508,7 @@ MegolmEncryption.prototype.reshareKeyWithDevice = async function( userId, device, payload, - ), + ); await this._baseApis.sendToDevice("m.room.encrypted", { [userId]: { diff --git a/src/crypto/algorithms/olm.js b/src/crypto/algorithms/olm.js index 93d651d49..25fb21d94 100644 --- a/src/crypto/algorithms/olm.js +++ b/src/crypto/algorithms/olm.js @@ -20,15 +20,12 @@ limitations under the License. * * @module crypto/algorithms/olm */ -import Promise from 'bluebird'; - import logger from '../../logger'; const utils = require("../../utils"); const olmlib = require("../olmlib"); const DeviceInfo = require("../deviceinfo"); const DeviceVerification = DeviceInfo.DeviceVerification; - const base = require("./base"); /** diff --git a/src/crypto/olmlib.js b/src/crypto/olmlib.js index 4af8e035d..47677b102 100644 --- a/src/crypto/olmlib.js +++ b/src/crypto/olmlib.js @@ -21,7 +21,6 @@ limitations under the License. * Utilities common to olm encryption algorithms */ -import Promise from 'bluebird'; const anotherjson = require('another-json'); import logger from '../logger'; diff --git a/src/utils.js b/src/utils.js index 11887c801..e50794cc7 100644 --- a/src/utils.js +++ b/src/utils.js @@ -21,7 +21,6 @@ limitations under the License. */ const unhomoglyph = require('unhomoglyph'); -// import Promise from 'bluebird'; /** * Encode a dictionary of query parameters. From 3a1de9fbdcaee0993ef3dc804c428e83140c4437 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 25 Nov 2019 17:15:11 +0000 Subject: [PATCH 12/25] Rip out more bluebirds AGAIN --- src/client.js | 6 ------ src/crypto/DeviceList.js | 1 - src/crypto/store/indexeddb-crypto-store-backend.js | 2 -- src/crypto/store/indexeddb-crypto-store.js | 2 -- src/scheduler.js | 1 - src/sync.js | 1 - 6 files changed, 13 deletions(-) diff --git a/src/client.js b/src/client.js index 098b3ea6e..7531694ff 100644 --- a/src/client.js +++ b/src/client.js @@ -26,7 +26,6 @@ import {sleep} from './utils'; * @module client */ const EventEmitter = require("events").EventEmitter; -import Promise from 'bluebird'; const url = require('url'); const httpApi = require("./http-api"); @@ -55,11 +54,6 @@ import { encodeRecoveryKey, decodeRecoveryKey } from './crypto/recoverykey'; import { keyFromPassphrase, keyFromAuthData } from './crypto/key_passphrase'; import { randomString } from './randomstring'; -// Disable warnings for now: we use deprecated bluebird functions -// and need to migrate, but they spam the console with warnings. -Promise.config({warnings: false}); - - const SCROLLBACK_DELAY_MS = 3000; const CRYPTO_ENABLED = isCryptoAvailable(); const CAPABILITIES_CACHE_MS = 21600000; // 6 hours - an arbitrary value diff --git a/src/crypto/DeviceList.js b/src/crypto/DeviceList.js index 8936c4ae3..705ad8ee9 100644 --- a/src/crypto/DeviceList.js +++ b/src/crypto/DeviceList.js @@ -23,7 +23,6 @@ limitations under the License. * Manages the list of other users' devices */ -import Promise from 'bluebird'; import {EventEmitter} from 'events'; import logger from '../logger'; diff --git a/src/crypto/store/indexeddb-crypto-store-backend.js b/src/crypto/store/indexeddb-crypto-store-backend.js index ede785d00..aeead378e 100644 --- a/src/crypto/store/indexeddb-crypto-store-backend.js +++ b/src/crypto/store/indexeddb-crypto-store-backend.js @@ -15,8 +15,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -import Promise from 'bluebird'; - import logger from '../../logger'; import utils from '../../utils'; diff --git a/src/crypto/store/indexeddb-crypto-store.js b/src/crypto/store/indexeddb-crypto-store.js index 2919fb9ca..68c10aec1 100644 --- a/src/crypto/store/indexeddb-crypto-store.js +++ b/src/crypto/store/indexeddb-crypto-store.js @@ -15,8 +15,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -import Promise from 'bluebird'; - import logger from '../../logger'; import LocalStorageCryptoStore from './localStorage-crypto-store'; import MemoryCryptoStore from './memory-crypto-store'; diff --git a/src/scheduler.js b/src/scheduler.js index e69bfb270..85ce50fd3 100644 --- a/src/scheduler.js +++ b/src/scheduler.js @@ -20,7 +20,6 @@ limitations under the License. * @module scheduler */ const utils = require("./utils"); -import Promise from 'bluebird'; import logger from './logger'; const DEBUG = false; // set true to enable console logging. diff --git a/src/sync.js b/src/sync.js index c516cdcf9..80302ec1e 100644 --- a/src/sync.js +++ b/src/sync.js @@ -25,7 +25,6 @@ limitations under the License. * an alternative syncing API, we may want to have a proper syncing interface * for HTTP and WS at some point. */ -import Promise from 'bluebird'; const User = require("./models/user"); const Room = require("./models/room"); const Group = require('./models/group'); From 053bc4973840568a61f03f54edb106f46ca4b24d Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 2 Dec 2019 22:55:05 +0000 Subject: [PATCH 13/25] simplify promiseTry Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/utils.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/utils.js b/src/utils.js index e50794cc7..e830a5daf 100644 --- a/src/utils.js +++ b/src/utils.js @@ -738,11 +738,5 @@ module.exports.promiseMapSeries = async (promises, fn) => { }; module.exports.promiseTry = (fn) => { - return new Promise((resolve, reject) => { - try { - fn().then(resolve, reject); - } catch (e) { - reject(e); - } - }); + return new Promise((resolve) => resolve(fn())); }; From a16cdb948ccf56508570ef38a3f08b40dda4dcb7 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 2 Dec 2019 22:30:34 +0000 Subject: [PATCH 14/25] Fix cross-signing.spec by waiting for right emit Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- spec/unit/crypto/cross-signing.spec.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/unit/crypto/cross-signing.spec.js b/spec/unit/crypto/cross-signing.spec.js index 06840b74a..900e9fa69 100644 --- a/spec/unit/crypto/cross-signing.spec.js +++ b/spec/unit/crypto/cross-signing.spec.js @@ -790,6 +790,9 @@ describe("Cross Signing", function() { }); alice._crypto._deviceList.emit("userCrossSigningUpdated", "@bob:example.com"); await upgradePromise; + await new Promise((resolve) => { + alice._crypto.on("userTrustStatusChanged", resolve); + }); const bobTrust3 = alice.checkUserTrust("@bob:example.com"); expect(bobTrust3.isCrossSigningVerified()).toBeTruthy(); From 1632ee3537e9e60646fb0e75a98f72dea4bdd67d Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 2 Dec 2019 23:18:26 +0000 Subject: [PATCH 15/25] fix order Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- spec/unit/crypto/cross-signing.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/unit/crypto/cross-signing.spec.js b/spec/unit/crypto/cross-signing.spec.js index 900e9fa69..a36c3bf70 100644 --- a/spec/unit/crypto/cross-signing.spec.js +++ b/spec/unit/crypto/cross-signing.spec.js @@ -789,10 +789,10 @@ describe("Cross Signing", function() { upgradeResolveFunc = resolve; }); alice._crypto._deviceList.emit("userCrossSigningUpdated", "@bob:example.com"); - await upgradePromise; await new Promise((resolve) => { alice._crypto.on("userTrustStatusChanged", resolve); }); + await upgradePromise; const bobTrust3 = alice.checkUserTrust("@bob:example.com"); expect(bobTrust3.isCrossSigningVerified()).toBeTruthy(); From f0267eae3686f0baa10f4b28d64762e5e9ec64ac Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 2 Dec 2019 23:38:55 +0000 Subject: [PATCH 16/25] fix undef Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/store/indexeddb-store-worker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/store/indexeddb-store-worker.js b/src/store/indexeddb-store-worker.js index 5896cead0..e652b9a4e 100644 --- a/src/store/indexeddb-store-worker.js +++ b/src/store/indexeddb-store-worker.js @@ -122,7 +122,7 @@ class IndexedDBStoreWorker { return; } - prom.done((ret) => { + prom.then((ret) => { this.postMessage.call(null, { command: 'cmd_success', seq: msg.seq, From 710ac6847d684cfb6504742d751ad962c04f173b Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 2 Dec 2019 23:39:47 +0000 Subject: [PATCH 17/25] fix undef2 Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client.js b/src/client.js index 7531694ff..094ba7e1e 100644 --- a/src/client.js +++ b/src/client.js @@ -4848,7 +4848,7 @@ function checkTurnServers(client) { return; // guests can't access TURN servers } - client.turnServer().done(function(res) { + client.turnServer().then(function(res) { if (res.uris) { logger.log("Got TURN URIs: " + res.uris + " refresh in " + res.ttl + " secs"); From c1e2d646b616832452899c83f6f3a70a9f13e025 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 2 Dec 2019 23:42:10 +0000 Subject: [PATCH 18/25] undo remove Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/utils.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils.js b/src/utils.js index e830a5daf..52ffe0bb7 100644 --- a/src/utils.js +++ b/src/utils.js @@ -21,6 +21,7 @@ limitations under the License. */ const unhomoglyph = require('unhomoglyph'); +import Promise from 'bluebird'; /** * Encode a dictionary of query parameters. From a6e40967733ef54e4174e8942cd509742954c4ec Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 2 Dec 2019 23:43:06 +0000 Subject: [PATCH 19/25] fix Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/store/indexeddb-store-worker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/store/indexeddb-store-worker.js b/src/store/indexeddb-store-worker.js index 5896cead0..e652b9a4e 100644 --- a/src/store/indexeddb-store-worker.js +++ b/src/store/indexeddb-store-worker.js @@ -122,7 +122,7 @@ class IndexedDBStoreWorker { return; } - prom.done((ret) => { + prom.then((ret) => { this.postMessage.call(null, { command: 'cmd_success', seq: msg.seq, From 8a8109272ad929e540135e0ea0df38be9b69db70 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 2 Dec 2019 23:45:12 +0000 Subject: [PATCH 20/25] fix undef3 Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client.js b/src/client.js index 094ba7e1e..9455c632b 100644 --- a/src/client.js +++ b/src/client.js @@ -1886,7 +1886,7 @@ MatrixClient.prototype.joinRoom = function(roomIdOrAlias, opts, callback) { // return syncApi.syncRoom(room); } return Promise.resolve(room); - }).done(function(room) { + }).then(function(room) { _resolve(callback, resolve, room); }, function(err) { _reject(callback, reject, err); From 4a47867e49cdcdc65d9f0a7b0fcb11cd41d86f1b Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 4 Dec 2019 19:17:58 +0000 Subject: [PATCH 21/25] Down to two test failures --- .babelrc | 5 ----- README.md | 8 ++++---- examples/node/app.js | 18 +++++++++--------- package.json | 2 -- spec/test-utils.js | 2 -- spec/unit/matrix-client.spec.js | 1 - src/client.js | 13 ++++++------- src/crypto/algorithms/megolm.js | 1 - src/crypto/index.js | 7 +++---- src/crypto/store/localStorage-crypto-store.js | 2 -- src/crypto/store/memory-crypto-store.js | 2 -- src/models/event.js | 1 - src/utils.js | 1 - 13 files changed, 22 insertions(+), 41 deletions(-) diff --git a/.babelrc b/.babelrc index 67eaa6718..078c4973f 100644 --- a/.babelrc +++ b/.babelrc @@ -3,11 +3,6 @@ "plugins": [ "transform-class-properties", - // this transforms async functions into generator functions, which - // are then made to use the regenerator module by babel's - // transform-regnerator plugin (which is enabled by es2015). - "transform-async-to-bluebird", - // This makes sure that the regenerator runtime is available to // the transpiled code. "transform-runtime", diff --git a/README.md b/README.md index 9081598dd..f9f6029cb 100644 --- a/README.md +++ b/README.md @@ -161,7 +161,7 @@ which will be fulfilled in the future. The typical usage is something like: ```javascript - matrixClient.someMethod(arg1, arg2).done(function(result) { + matrixClient.someMethod(arg1, arg2).then(function(result) { ... }); ``` @@ -206,7 +206,7 @@ core functionality of the SDK. These examples assume the SDK is setup like this: ```javascript matrixClient.on("RoomMember.membership", function(event, member) { if (member.membership === "invite" && member.userId === myUserId) { - matrixClient.joinRoom(member.roomId).done(function() { + matrixClient.joinRoom(member.roomId).then(function() { console.log("Auto-joined %s", member.roomId); }); } @@ -297,7 +297,7 @@ End-to-end encryption support ============================= The SDK supports end-to-end encryption via the Olm and Megolm protocols, using -[libolm](https://gitlab.matrix.org/matrix-org/olm). It is left up to the +[libolm](https://gitlab.matrix.org/matrix-org/olm). It is left up to the application to make libolm available, via the ``Olm`` global. It is also necessry to call ``matrixClient.initCrypto()`` after creating a new @@ -319,7 +319,7 @@ To provide the Olm library in a browser application: * download the transpiled libolm (from https://packages.matrix.org/npm/olm/). * load ``olm.js`` as a ``