1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-06 12:02:40 +03:00

replace q method calls with bluebird ones

```
find src spec -name '*.js' |
    xargs perl -i -pe 's/q\.(all|defer|reject|delay|try)\(/Promise.$1(/'
```
This commit is contained in:
Richard van der Hoff
2017-07-10 16:55:29 +01:00
parent b58d84fba1
commit cfffbc4a09
21 changed files with 107 additions and 107 deletions

View File

@@ -195,7 +195,7 @@ TestClient.prototype.getSigningKey = function() {
*/
TestClient.prototype.flushSync = function() {
console.log(`${this}: flushSync`);
return q.all([
return Promise.all([
this.httpBackend.flush('/sync', 1),
testUtils.syncPromise(this.client),
]);

View File

@@ -50,7 +50,7 @@ let bobMessages;
function bobUploadsDeviceKeys() {
bobTestClient.expectDeviceKeyUpload();
return q.all([
return Promise.all([
bobTestClient.client.uploadKeys(),
bobTestClient.httpBackend.flush(),
]).then(() => {
@@ -157,7 +157,7 @@ function aliDownloadsKeys() {
// check that the localStorage is updated as we expect (not sure this is
// an integration test, but meh)
return q.all([p1, p2]).then(function() {
return Promise.all([p1, p2]).then(function() {
const devices = aliTestClient.storage.getEndToEndDevicesForUser(bobUserId);
expect(devices[bobDeviceId].keys).toEqual(bobTestClient.deviceKeys.keys);
expect(devices[bobDeviceId].verified).
@@ -188,7 +188,7 @@ function bobEnablesEncryption() {
* @return {promise} which resolves to the ciphertext for Bob's device.
*/
function aliSendsFirstMessage() {
return q.all([
return Promise.all([
sendMessage(aliTestClient.client),
expectAliQueryKeys()
.then(expectAliClaimKeys)
@@ -205,7 +205,7 @@ function aliSendsFirstMessage() {
* @return {promise} which resolves to the ciphertext for Bob's device.
*/
function aliSendsMessage() {
return q.all([
return Promise.all([
sendMessage(aliTestClient.client),
expectAliSendMessageRequest(),
]).spread(function(_, ciphertext) {
@@ -220,7 +220,7 @@ function aliSendsMessage() {
* @return {promise} which resolves to the ciphertext for Ali's device.
*/
function bobSendsReplyMessage() {
return q.all([
return Promise.all([
sendMessage(bobTestClient.client),
expectBobQueryKeys()
.then(expectBobSendMessageRequest),
@@ -269,7 +269,7 @@ function sendMessage(client) {
function expectSendMessageRequest(httpBackend) {
const path = "/send/m.room.encrypted/";
const deferred = q.defer();
const deferred = Promise.defer();
httpBackend.when("PUT", path).respond(200, function(path, content) {
deferred.resolve(content);
return {
@@ -317,7 +317,7 @@ function recvMessage(httpBackend, client, sender, message) {
},
};
httpBackend.when("GET", "/sync").respond(200, syncData);
const deferred = q.defer();
const deferred = Promise.defer();
const onEvent = function(event) {
console.log(client.credentials.userId + " received event",
event);
@@ -426,7 +426,7 @@ describe("MatrixClient crypto", function() {
expect(bobDeviceKeys.keys["curve25519:" + bobDeviceId]).toBeTruthy();
bobDeviceKeys.keys["curve25519:" + bobDeviceId] += "abc";
return q.all([
return Promise.all([
aliTestClient.client.downloadKeys([bobUserId]),
expectAliQueryKeys(),
]);
@@ -467,7 +467,7 @@ describe("MatrixClient crypto", function() {
return {device_keys: result};
});
q.all([
Promise.all([
aliTestClient.client.downloadKeys([bobUserId, eveUserId]),
aliTestClient.httpBackend.flush("/keys/query", 1),
]).then(function() {
@@ -504,7 +504,7 @@ describe("MatrixClient crypto", function() {
return {device_keys: result};
});
q.all([
Promise.all([
aliTestClient.client.downloadKeys([bobUserId]),
aliTestClient.httpBackend.flush("/keys/query", 1),
]).then(function() {
@@ -576,7 +576,7 @@ describe("MatrixClient crypto", function() {
};
bobTestClient.httpBackend.when("GET", "/sync").respond(200, syncData);
const deferred = q.defer();
const deferred = Promise.defer();
const onEvent = function(event) {
console.log(bobUserId + " received event",
event);
@@ -617,7 +617,7 @@ describe("MatrixClient crypto", function() {
// no unblocked devices, so the ciphertext should be empty
expect(sentContent.ciphertext).toEqual({});
});
return q.all([p1, p2]);
return Promise.all([p1, p2]);
}).nodeify(done);
});

View File

@@ -82,7 +82,7 @@ function startClient(httpBackend, client) {
client.startClient();
// set up a promise which will resolve once the client is initialised
const deferred = q.defer();
const deferred = Promise.defer();
client.on("sync", function(state) {
console.log("sync", state);
if (state != "SYNCING") {
@@ -91,7 +91,7 @@ function startClient(httpBackend, client) {
deferred.resolve();
});
return q.all([
return Promise.all([
httpBackend.flushAllExpected(),
deferred.promise,
]);
@@ -205,7 +205,7 @@ describe("getEventTimeline support", function() {
}).then(() => {
// the sync isn't processed immediately; give the promise chain
// a chance to complete.
return q.delay(0);
return Promise.delay(0);
}).then(function() {
expect(room.timeline.length).toEqual(1);
expect(room.timeline[0].event).toEqual(EVENTS[1]);
@@ -266,7 +266,7 @@ describe("MatrixClient event timelines", function() {
};
});
return q.all([
return Promise.all([
client.getEventTimeline(timelineSet, "event1:bar").then(function(tl) {
expect(tl.getEvents().length).toEqual(4);
for (let i = 0; i < 4; i++) {
@@ -346,7 +346,7 @@ describe("MatrixClient event timelines", function() {
};
});
const deferred = q.defer();
const deferred = Promise.defer();
client.on("sync", function() {
client.getEventTimeline(timelineSet, EVENTS[2].event_id,
).then(function(tl) {
@@ -362,7 +362,7 @@ describe("MatrixClient event timelines", function() {
(e) => deferred.reject(e));
});
return q.all([
return Promise.all([
httpBackend.flushAllExpected(),
deferred.promise,
]);
@@ -429,7 +429,7 @@ describe("MatrixClient event timelines", function() {
let tl0;
let tl3;
return q.all([
return Promise.all([
client.getEventTimeline(timelineSet, EVENTS[0].event_id,
).then(function(tl) {
expect(tl.getEvents().length).toEqual(1);
@@ -480,7 +480,7 @@ describe("MatrixClient event timelines", function() {
};
});
return q.all([
return Promise.all([
client.getEventTimeline(timelineSet, "event1",
).then(function(tl) {
// could do with a fail()
@@ -525,7 +525,7 @@ describe("MatrixClient event timelines", function() {
});
let tl;
return q.all([
return Promise.all([
client.getEventTimeline(timelineSet, EVENTS[0].event_id,
).then(function(tl0) {
tl = tl0;
@@ -577,7 +577,7 @@ describe("MatrixClient event timelines", function() {
});
let tl;
return q.all([
return Promise.all([
client.getEventTimeline(timelineSet, EVENTS[0].event_id,
).then(function(tl0) {
tl = tl0;
@@ -634,7 +634,7 @@ describe("MatrixClient event timelines", function() {
const room = client.getRoom(roomId);
const timelineSet = room.getTimelineSets()[0];
return q.all([
return Promise.all([
client.sendTextMessage(roomId, "a body", TXN_ID).then(function(res) {
expect(res.event_id).toEqual(event.event_id);
return client.getEventTimeline(timelineSet, event.event_id);
@@ -644,7 +644,7 @@ describe("MatrixClient event timelines", function() {
expect(tl.getEvents()[1].getContent().body).toEqual("a body");
// now let the sync complete, and check it again
return q.all([
return Promise.all([
httpBackend.flush("/sync", 1),
utils.syncPromise(client),
]);
@@ -663,7 +663,7 @@ describe("MatrixClient event timelines", function() {
const room = client.getRoom(roomId);
const timelineSet = room.getTimelineSets()[0];
return q.all([
return Promise.all([
// initiate the send, and set up checks to be done when it completes
// - but note that it won't complete until after the /sync does, below.
client.sendTextMessage(roomId, "a body", TXN_ID).then(function(res) {
@@ -676,7 +676,7 @@ describe("MatrixClient event timelines", function() {
expect(tl.getEvents()[1].getContent().body).toEqual("a body");
}),
q.all([
Promise.all([
httpBackend.flush("/sync", 1),
utils.syncPromise(client),
]).then(function() {

View File

@@ -114,7 +114,7 @@ describe("MatrixClient opts", function() {
httpBackend.flush("/pushrules", 1).then(function() {
return httpBackend.flush("/filter", 1);
}).then(function() {
return q.all([
return Promise.all([
httpBackend.flush("/sync", 1),
utils.syncPromise(client),
]);

View File

@@ -394,7 +394,7 @@ describe("MatrixClient room timelines", function() {
];
setNextSyncData(eventData);
return q.all([
return Promise.all([
httpBackend.flush("/sync", 1),
utils.syncPromise(client),
]).then(() => {
@@ -409,7 +409,7 @@ describe("MatrixClient room timelines", function() {
});
httpBackend.flush("/messages", 1);
return q.all([
return Promise.all([
httpBackend.flush("/sync", 1),
utils.syncPromise(client),
]).then(function() {
@@ -436,12 +436,12 @@ describe("MatrixClient room timelines", function() {
eventData[1].__prev_event = USER_MEMBERSHIP_EVENT;
setNextSyncData(eventData);
return q.all([
return Promise.all([
httpBackend.flush("/sync", 1),
utils.syncPromise(client),
]).then(() => {
const room = client.getRoom(roomId);
return q.all([
return Promise.all([
httpBackend.flush("/sync", 1),
utils.syncPromise(client),
]).then(function() {
@@ -462,7 +462,7 @@ describe("MatrixClient room timelines", function() {
secondRoomNameEvent.__prev_event = ROOM_NAME_EVENT;
setNextSyncData([secondRoomNameEvent]);
return q.all([
return Promise.all([
httpBackend.flush("/sync", 1),
utils.syncPromise(client),
]).then(() => {
@@ -472,7 +472,7 @@ describe("MatrixClient room timelines", function() {
nameEmitCount += 1;
});
return q.all([
return Promise.all([
httpBackend.flush("/sync", 1),
utils.syncPromise(client),
]).then(function() {
@@ -487,7 +487,7 @@ describe("MatrixClient room timelines", function() {
thirdRoomNameEvent.__prev_event = secondRoomNameEvent;
setNextSyncData([thirdRoomNameEvent]);
httpBackend.when("GET", "/sync").respond(200, NEXT_SYNC_DATA);
return q.all([
return Promise.all([
httpBackend.flush("/sync", 1),
utils.syncPromise(client),
]);
@@ -513,12 +513,12 @@ describe("MatrixClient room timelines", function() {
eventData[1].__prev_event = null;
setNextSyncData(eventData);
return q.all([
return Promise.all([
httpBackend.flush("/sync", 1),
utils.syncPromise(client),
]).then(() => {
const room = client.getRoom(roomId);
return q.all([
return Promise.all([
httpBackend.flush("/sync", 1),
utils.syncPromise(client),
]).then(function() {
@@ -544,14 +544,14 @@ describe("MatrixClient room timelines", function() {
setNextSyncData(eventData);
NEXT_SYNC_DATA.rooms.join[roomId].timeline.limited = true;
return q.all([
return Promise.all([
httpBackend.flush("/sync", 1),
utils.syncPromise(client),
]).then(() => {
const room = client.getRoom(roomId);
httpBackend.flush("/messages", 1);
return q.all([
return Promise.all([
httpBackend.flush("/sync", 1),
utils.syncPromise(client),
]).then(function() {
@@ -577,7 +577,7 @@ describe("MatrixClient room timelines", function() {
setNextSyncData(eventData);
NEXT_SYNC_DATA.rooms.join[roomId].timeline.limited = true;
return q.all([
return Promise.all([
httpBackend.flush("/sync", 1),
utils.syncPromise(client),
]).then(() => {
@@ -590,7 +590,7 @@ describe("MatrixClient room timelines", function() {
});
httpBackend.flush("/messages", 1);
return q.all([
return Promise.all([
httpBackend.flush("/sync", 1),
utils.syncPromise(client),
]).then(function() {

View File

@@ -634,7 +634,7 @@ describe("MatrixClient syncing", function() {
include_leave: true }});
}).respond(200, { filter_id: "another_id" });
const defer = q.defer();
const defer = Promise.defer();
httpBackend.when("GET", "/sync").check(function(req) {
expect(req.queryParams.filter).toEqual("another_id");
@@ -645,7 +645,7 @@ describe("MatrixClient syncing", function() {
// first flush the filter request; this will make syncLeftRooms
// make its /sync call
return q.all([
return Promise.all([
httpBackend.flush("/filter").then(function() {
// flush the syncs
return httpBackend.flushAllExpected();
@@ -679,7 +679,7 @@ describe("MatrixClient syncing", function() {
httpBackend.when("GET", "/sync").respond(200, syncData);
return q.all([
return Promise.all([
client.syncLeftRooms().then(function() {
const room = client.getRoom(roomTwo);
const tok = room.getLiveTimeline().getPaginationToken(

View File

@@ -506,7 +506,7 @@ describe("megolm", function() {
200, getTestKeysQueryResponse('@bob:xyz'),
);
return q.all([
return Promise.all([
aliceTestClient.client.sendTextMessage(ROOM_ID, 'test').then(() => {
throw new Error("sendTextMessage failed on an unknown device");
}, (e) => {
@@ -552,7 +552,7 @@ describe("megolm", function() {
const room = aliceTestClient.client.getRoom(ROOM_ID);
const pendingMsg = room.getPendingEvents()[0];
return q.all([
return Promise.all([
aliceTestClient.client.resendEvent(pendingMsg, room),
aliceTestClient.httpBackend.flushAllExpected(),
]);
@@ -574,7 +574,7 @@ describe("megolm", function() {
},
});
return q.all([
return Promise.all([
aliceTestClient.client.downloadKeys(['@bob:xyz']),
aliceTestClient.httpBackend.flush('/keys/query', 1),
]);
@@ -587,7 +587,7 @@ describe("megolm", function() {
event_id: '$event_id',
});
return q.all([
return Promise.all([
aliceTestClient.client.sendTextMessage(ROOM_ID, 'test'),
aliceTestClient.httpBackend.flushAllExpected(),
]);
@@ -619,7 +619,7 @@ describe("megolm", function() {
200, getTestKeysQueryResponse('@bob:xyz'),
);
return q.all([
return Promise.all([
aliceTestClient.client.downloadKeys(['@bob:xyz']),
aliceTestClient.httpBackend.flush('/keys/query', 1),
]);
@@ -634,7 +634,7 @@ describe("megolm", function() {
event_id: '$event_id',
});
return q.all([
return Promise.all([
aliceTestClient.client.sendTextMessage(ROOM_ID, 'test'),
aliceTestClient.httpBackend.flushAllExpected(),
]);
@@ -670,7 +670,7 @@ describe("megolm", function() {
200, getTestKeysQueryResponse('@bob:xyz'),
);
return q.all([
return Promise.all([
aliceTestClient.client.downloadKeys(['@bob:xyz']),
aliceTestClient.httpBackend.flushAllExpected(),
]).then((keys) => {
@@ -703,7 +703,7 @@ describe("megolm", function() {
};
});
return q.all([
return Promise.all([
aliceTestClient.client.sendTextMessage(ROOM_ID, 'test'),
aliceTestClient.httpBackend.flushAllExpected(),
]);
@@ -722,7 +722,7 @@ describe("megolm", function() {
};
});
return q.all([
return Promise.all([
aliceTestClient.client.sendTextMessage(ROOM_ID, 'test2'),
aliceTestClient.httpBackend.flushAllExpected(),
]);
@@ -824,7 +824,7 @@ describe("megolm", function() {
};
});
return q.all([
return Promise.all([
aliceTestClient.client.sendTextMessage(ROOM_ID, 'test'),
aliceTestClient.httpBackend.flushAllExpected(),
]);
@@ -875,7 +875,7 @@ describe("megolm", function() {
return aliceTestClient.httpBackend.flushAllExpected();
}).then(function() {
return q.all([downloadPromise, sendPromise]);
return Promise.all([downloadPromise, sendPromise]);
});
});
@@ -903,7 +903,7 @@ describe("megolm", function() {
aliceTestClient.httpBackend.when('PUT', '/send/').respond(
200, {event_id: '$event1'});
return q.all([
return Promise.all([
aliceTestClient.client.sendTextMessage(ROOM_ID, 'test'),
aliceTestClient.httpBackend.flush('/keys/query', 1).then(
() => aliceTestClient.httpBackend.flush('/send/', 1),

View File

@@ -15,7 +15,7 @@ const MatrixEvent = sdk.MatrixEvent;
* @return {Promise} Resolves once the client has emitted a SYNCING event
*/
module.exports.syncPromise = function(client) {
const def = q.defer();
const def = Promise.defer();
const cb = (state) => {
if (state == 'SYNCING') {
def.resolve();

View File

@@ -64,7 +64,7 @@ describe('DeviceList', function() {
dl.startTrackingDeviceList('@test1:sw1v.org');
const queryDefer1 = q.defer();
const queryDefer1 = Promise.defer();
downloadSpy.andReturn(queryDefer1.promise);
const prom1 = dl.refreshOutdatedDeviceLists();
@@ -83,7 +83,7 @@ describe('DeviceList', function() {
dl.startTrackingDeviceList('@test1:sw1v.org');
const queryDefer1 = q.defer();
const queryDefer1 = Promise.defer();
downloadSpy.andReturn(queryDefer1.promise);
const prom1 = dl.refreshOutdatedDeviceLists();
@@ -91,7 +91,7 @@ describe('DeviceList', function() {
downloadSpy.reset();
// outdated notif arrives while the request is in flight.
const queryDefer2 = q.defer();
const queryDefer2 = Promise.defer();
downloadSpy.andReturn(queryDefer2.promise);
dl.invalidateUserDeviceList('@test1:sw1v.org');
@@ -110,7 +110,7 @@ describe('DeviceList', function() {
console.log("Creating new devicelist to simulate app reload");
downloadSpy.reset();
const dl2 = createTestDeviceList();
const queryDefer3 = q.defer();
const queryDefer3 = Promise.defer();
downloadSpy.andReturn(queryDefer3.promise);
const prom3 = dl2.refreshOutdatedDeviceLists();

View File

@@ -136,7 +136,7 @@ describe("MegolmDecryption", function() {
megolmDecryption.shareKeysWithDevice(keyRequest);
// it's asynchronous, so we have to wait a bit
return q.delay(1).then(() => {
return Promise.delay(1).then(() => {
// check that it called encryptMessageForDevice with
// appropriate args.
expect(mockOlmLib.encryptMessageForDevice.calls.length)

View File

@@ -84,7 +84,7 @@ describe("MatrixClient", function() {
);
}
pendingLookup = {
promise: q.defer().promise,
promise: Promise.defer().promise,
method: method,
path: path,
};
@@ -109,7 +109,7 @@ describe("MatrixClient", function() {
}
if (next.error) {
return q.reject({
return Promise.reject({
errcode: next.error.errcode,
httpStatus: next.error.httpStatus,
name: next.error.errcode,
@@ -120,7 +120,7 @@ describe("MatrixClient", function() {
return Promise.resolve(next.data);
}
expect(true).toBe(false, "Expected different request. " + logLine);
return q.defer().promise;
return Promise.defer().promise;
}
beforeEach(function() {
@@ -174,10 +174,10 @@ describe("MatrixClient", function() {
// a DIFFERENT test (pollution between tests!) - we return unresolved
// promises to stop the client from continuing to run.
client._http.authedRequest.andCall(function() {
return q.defer().promise;
return Promise.defer().promise;
});
client._http.authedRequestWithPrefix.andCall(function() {
return q.defer().promise;
return Promise.defer().promise;
});
});

View File

@@ -41,7 +41,7 @@ describe("MatrixScheduler", function() {
});
retryFn = null;
queueFn = null;
defer = q.defer();
defer = Promise.defer();
});
afterEach(function() {
@@ -55,8 +55,8 @@ describe("MatrixScheduler", function() {
queueFn = function() {
return "one_big_queue";
};
const deferA = q.defer();
const deferB = q.defer();
const deferA = Promise.defer();
const deferB = Promise.defer();
let resolvedA = false;
scheduler.setProcessFunction(function(event) {
if (resolvedA) {
@@ -80,7 +80,7 @@ describe("MatrixScheduler", function() {
it("should invoke the retryFn on failure and wait the amount of time specified",
function(done) {
const waitTimeMs = 1500;
const retryDefer = q.defer();
const retryDefer = Promise.defer();
retryFn = function() {
retryDefer.resolve();
return waitTimeMs;
@@ -97,7 +97,7 @@ describe("MatrixScheduler", function() {
return defer.promise;
} else if (procCount === 2) {
// don't care about this defer
return q.defer().promise;
return Promise.defer().promise;
}
expect(procCount).toBeLessThan(3);
});
@@ -125,8 +125,8 @@ describe("MatrixScheduler", function() {
return "yep";
};
const deferA = q.defer();
const deferB = q.defer();
const deferA = Promise.defer();
const deferB = Promise.defer();
let procCount = 0;
scheduler.setProcessFunction(function(ev) {
procCount += 1;
@@ -177,7 +177,7 @@ describe("MatrixScheduler", function() {
const expectOrder = [
eventA.getId(), eventB.getId(), eventD.getId(),
];
const deferA = q.defer();
const deferA = Promise.defer();
scheduler.setProcessFunction(function(event) {
const id = expectOrder.shift();
expect(id).toEqual(event.getId());

View File

@@ -198,7 +198,7 @@ MatrixClient.prototype.clearStores = function() {
if (this._cryptoStore) {
promises.push(this._cryptoStore.deleteAllData());
}
return q.all(promises);
return Promise.all(promises);
};
/**
@@ -368,7 +368,7 @@ MatrixClient.prototype.uploadKeys = function() {
*/
MatrixClient.prototype.downloadKeys = function(userIds, forceDownload) {
if (this._crypto === null) {
return q.reject(new Error("End-to-end encryption disabled"));
return Promise.reject(new Error("End-to-end encryption disabled"));
}
return this._crypto.downloadKeys(userIds, forceDownload);
};
@@ -577,7 +577,7 @@ MatrixClient.prototype.isRoomEncrypted = function(roomId) {
*/
MatrixClient.prototype.exportRoomKeys = function() {
if (!this._crypto) {
return q.reject(new Error("End-to-end encryption disabled"));
return Promise.reject(new Error("End-to-end encryption disabled"));
}
return this._crypto.exportRoomKeys();
};
@@ -742,7 +742,7 @@ MatrixClient.prototype.joinRoom = function(roomIdOrAlias, opts, callback) {
);
}
const defer = q.defer();
const defer = Promise.defer();
const self = this;
sign_promise.then(function(signed_invite_object) {
@@ -1402,7 +1402,7 @@ MatrixClient.prototype.inviteByThreePid = function(roomId, medium, address, call
let identityServerUrl = this.getIdentityServerUrl();
if (!identityServerUrl) {
return q.reject(new MatrixError({
return Promise.reject(new MatrixError({
error: "No supplied identity server URL",
errcode: "ORG.MATRIX.JSSDK_MISSING_PARAM",
}));
@@ -1761,7 +1761,7 @@ MatrixClient.prototype.scrollback = function(room, limit, callback) {
limit: limit,
dir: 'b',
};
const defer = q.defer();
const defer = Promise.defer();
info = {
promise: defer.promise,
errorTs: null,
@@ -1769,7 +1769,7 @@ MatrixClient.prototype.scrollback = function(room, limit, callback) {
const self = this;
// wait for a time before doing this request
// (which may be 0 in order not to special case the code paths)
q.delay(timeToWaitMs).then(function() {
Promise.delay(timeToWaitMs).then(function() {
return self._http.authedRequest(callback, "GET", path, params);
}).done(function(res) {
const matrixEvents = utils.map(res.chunk, _PojoToMatrixEventMapper(self));
@@ -1812,7 +1812,7 @@ MatrixClient.prototype.paginateEventContext = function(eventContext, opts) {
const token = eventContext.getPaginateToken(backwards);
if (!token) {
// no more results.
return q.reject(new Error("No paginate token"));
return Promise.reject(new Error("No paginate token"));
}
const dir = backwards ? 'b' : 'f';
@@ -2153,7 +2153,7 @@ MatrixClient.prototype.setGuestAccess = function(roomId, opts) {
});
}
return q.all([readPromise, writePromise]);
return Promise.all([readPromise, writePromise]);
};
// Registration/Login operations
@@ -2421,7 +2421,7 @@ MatrixClient.prototype.setRoomMutePushRule = function(scope, roomId, mute) {
} else if (!hasDontNotifyRule) {
// Remove the existing one before setting the mute push rule
// This is a workaround to SYN-590 (Push rule update fails)
deferred = q.defer();
deferred = Promise.defer();
this.deletePushRule(scope, "room", roomPushRule.rule_id)
.done(function() {
self.addPushRule(scope, "room", roomId, {
@@ -2441,7 +2441,7 @@ MatrixClient.prototype.setRoomMutePushRule = function(scope, roomId, mute) {
if (deferred) {
// Update this.pushRules when the operation completes
const ruleRefreshDeferred = q.defer();
const ruleRefreshDeferred = Promise.defer();
deferred.done(function() {
self.getPushRules().done(function(result) {
self.pushRules = result;
@@ -2555,7 +2555,7 @@ MatrixClient.prototype.backPaginateRoomEventsSearch = function(searchResults) {
// nicely with HTTP errors.
if (!searchResults.next_batch) {
return q.reject(new Error("Cannot backpaginate event search any further"));
return Promise.reject(new Error("Cannot backpaginate event search any further"));
}
if (searchResults.pendingRequest) {

View File

@@ -96,7 +96,7 @@ export default class DeviceList {
console.log("downloadKeys: already have all necessary keys");
}
return q.all(promises).then(() => {
return Promise.all(promises).then(() => {
return this._getDevicesFromStore(userIds);
});
}
@@ -416,7 +416,7 @@ class DeviceListUpdateSerialiser {
this._nextSyncToken = syncToken;
if (!this._queuedQueryDeferred) {
this._queuedQueryDeferred = q.defer();
this._queuedQueryDeferred = Promise.defer();
}
if (this._downloadInProgress) {

View File

@@ -39,7 +39,7 @@ export class Backend {
getOrAddOutgoingRoomKeyRequest(request) {
const requestBody = request.requestBody;
const deferred = q.defer();
const deferred = Promise.defer();
const txn = this._db.transaction("outgoingRoomKeyRequests", "readwrite");
txn.onerror = deferred.reject;
@@ -81,7 +81,7 @@ export class Backend {
* not found
*/
getOutgoingRoomKeyRequest(requestBody) {
const deferred = q.defer();
const deferred = Promise.defer();
const txn = this._db.transaction("outgoingRoomKeyRequests", "readonly");
txn.onerror = deferred.reject;

View File

@@ -219,7 +219,7 @@ module.exports.MatrixHttpApi.prototype = {
}
if (global.XMLHttpRequest) {
const defer = q.defer();
const defer = Promise.defer();
const xhr = new global.XMLHttpRequest();
upload.xhr = xhr;
const cb = requestCallback(defer, opts.callback, this.opts.onlyData);
@@ -343,7 +343,7 @@ module.exports.MatrixHttpApi.prototype = {
opts.form = params;
}
const defer = q.defer();
const defer = Promise.defer();
this.opts.request(
opts,
requestCallback(defer, callback, this.opts.onlyData),
@@ -676,7 +676,7 @@ module.exports.MatrixHttpApi.prototype = {
}
}
const defer = q.defer();
const defer = Promise.defer();
let timeoutId;
let timedOut = false;

View File

@@ -115,7 +115,7 @@ InteractiveAuth.prototype = {
* no suitable authentication flow can be found
*/
attemptAuth: function() {
this._completionDeferred = q.defer();
this._completionDeferred = Promise.defer();
// wrap in a promise so that if _startNextAuthStage
// throws, it rejects the promise in a consistent way
@@ -263,7 +263,7 @@ InteractiveAuth.prototype = {
try {
prom = this._requestCallback(auth, background);
} catch (e) {
prom = q.reject(e);
prom = Promise.reject(e);
}
prom = prom.then(

View File

@@ -118,7 +118,7 @@ MatrixScheduler.prototype.queueEvent = function(event) {
if (!this._queues[queueName]) {
this._queues[queueName] = [];
}
const defer = q.defer();
const defer = Promise.defer();
this._queues[queueName].push({
event: event,
defer: defer,

View File

@@ -143,7 +143,7 @@ LocalIndexedDBStoreBackend.prototype = {
* @return {Promise} Resolves on success
*/
_init: function() {
return q.all([
return Promise.all([
this._loadAccountData(),
this._loadSyncData(),
]).then(([accountData, syncData]) => {
@@ -223,7 +223,7 @@ LocalIndexedDBStoreBackend.prototype = {
syncToDatabase: function(userTuples) {
const syncData = this._syncAccumulator.getJSON();
return q.all([
return Promise.all([
this._persistUserPresenceEvents(userTuples),
this._persistAccountData(syncData.accountData),
this._persistSyncData(syncData.nextBatch, syncData.roomsData),
@@ -238,7 +238,7 @@ LocalIndexedDBStoreBackend.prototype = {
*/
_persistSyncData: function(nextBatch, roomsData) {
console.log("Persisting sync data up to ", nextBatch);
return q.try(() => {
return Promise.try(() => {
const txn = this.db.transaction(["sync"], "readwrite");
const store = txn.objectStore("sync");
store.put({
@@ -257,7 +257,7 @@ LocalIndexedDBStoreBackend.prototype = {
* @return {Promise} Resolves if the events were persisted.
*/
_persistAccountData: function(accountData) {
return q.try(() => {
return Promise.try(() => {
const txn = this.db.transaction(["accountData"], "readwrite");
const store = txn.objectStore("accountData");
for (let i = 0; i < accountData.length; i++) {
@@ -276,7 +276,7 @@ LocalIndexedDBStoreBackend.prototype = {
* @return {Promise} Resolves if the users were persisted.
*/
_persistUserPresenceEvents: function(tuples) {
return q.try(() => {
return Promise.try(() => {
const txn = this.db.transaction(["users"], "readwrite");
const store = txn.objectStore("users");
for (const tuple of tuples) {
@@ -296,7 +296,7 @@ LocalIndexedDBStoreBackend.prototype = {
* @return {Promise<Object[]>} A list of presence events in their raw form.
*/
getUserPresenceEvents: function() {
return q.try(() => {
return Promise.try(() => {
const txn = this.db.transaction(["users"], "readonly");
const store = txn.objectStore("users");
return selectQuery(store, undefined, (cursor) => {
@@ -310,7 +310,7 @@ LocalIndexedDBStoreBackend.prototype = {
* @return {Promise<Object[]>} A list of raw global account events.
*/
_loadAccountData: function() {
return q.try(() => {
return Promise.try(() => {
const txn = this.db.transaction(["accountData"], "readonly");
const store = txn.objectStore("accountData");
return selectQuery(store, undefined, (cursor) => {
@@ -324,7 +324,7 @@ LocalIndexedDBStoreBackend.prototype = {
* @return {Promise<Object>} An object with "roomsData" and "nextBatch" keys.
*/
_loadSyncData: function() {
return q.try(() => {
return Promise.try(() => {
const txn = this.db.transaction(["sync"], "readonly");
const store = txn.objectStore("sync");
return selectQuery(store, undefined, (cursor) => {

View File

@@ -98,7 +98,7 @@ RemoteIndexedDBStoreBackend.prototype = {
// the promise automatically gets rejected
return Promise.resolve().then(() => {
const seq = this._nextSeq++;
const def = q.defer();
const def = Promise.defer();
this._inFlight[seq] = def;

View File

@@ -1009,7 +1009,7 @@ SyncApi.prototype._startKeepAlives = function(delay) {
self._pokeKeepAlive();
}
if (!this._connectionReturnedDefer) {
this._connectionReturnedDefer = q.defer();
this._connectionReturnedDefer = Promise.defer();
}
return this._connectionReturnedDefer.promise;
};