1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-05 00:42:10 +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() { TestClient.prototype.flushSync = function() {
console.log(`${this}: flushSync`); console.log(`${this}: flushSync`);
return q.all([ return Promise.all([
this.httpBackend.flush('/sync', 1), this.httpBackend.flush('/sync', 1),
testUtils.syncPromise(this.client), testUtils.syncPromise(this.client),
]); ]);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -506,7 +506,7 @@ describe("megolm", function() {
200, getTestKeysQueryResponse('@bob:xyz'), 200, getTestKeysQueryResponse('@bob:xyz'),
); );
return q.all([ return Promise.all([
aliceTestClient.client.sendTextMessage(ROOM_ID, 'test').then(() => { aliceTestClient.client.sendTextMessage(ROOM_ID, 'test').then(() => {
throw new Error("sendTextMessage failed on an unknown device"); throw new Error("sendTextMessage failed on an unknown device");
}, (e) => { }, (e) => {
@@ -552,7 +552,7 @@ describe("megolm", function() {
const room = aliceTestClient.client.getRoom(ROOM_ID); const room = aliceTestClient.client.getRoom(ROOM_ID);
const pendingMsg = room.getPendingEvents()[0]; const pendingMsg = room.getPendingEvents()[0];
return q.all([ return Promise.all([
aliceTestClient.client.resendEvent(pendingMsg, room), aliceTestClient.client.resendEvent(pendingMsg, room),
aliceTestClient.httpBackend.flushAllExpected(), aliceTestClient.httpBackend.flushAllExpected(),
]); ]);
@@ -574,7 +574,7 @@ describe("megolm", function() {
}, },
}); });
return q.all([ return Promise.all([
aliceTestClient.client.downloadKeys(['@bob:xyz']), aliceTestClient.client.downloadKeys(['@bob:xyz']),
aliceTestClient.httpBackend.flush('/keys/query', 1), aliceTestClient.httpBackend.flush('/keys/query', 1),
]); ]);
@@ -587,7 +587,7 @@ describe("megolm", function() {
event_id: '$event_id', event_id: '$event_id',
}); });
return q.all([ return Promise.all([
aliceTestClient.client.sendTextMessage(ROOM_ID, 'test'), aliceTestClient.client.sendTextMessage(ROOM_ID, 'test'),
aliceTestClient.httpBackend.flushAllExpected(), aliceTestClient.httpBackend.flushAllExpected(),
]); ]);
@@ -619,7 +619,7 @@ describe("megolm", function() {
200, getTestKeysQueryResponse('@bob:xyz'), 200, getTestKeysQueryResponse('@bob:xyz'),
); );
return q.all([ return Promise.all([
aliceTestClient.client.downloadKeys(['@bob:xyz']), aliceTestClient.client.downloadKeys(['@bob:xyz']),
aliceTestClient.httpBackend.flush('/keys/query', 1), aliceTestClient.httpBackend.flush('/keys/query', 1),
]); ]);
@@ -634,7 +634,7 @@ describe("megolm", function() {
event_id: '$event_id', event_id: '$event_id',
}); });
return q.all([ return Promise.all([
aliceTestClient.client.sendTextMessage(ROOM_ID, 'test'), aliceTestClient.client.sendTextMessage(ROOM_ID, 'test'),
aliceTestClient.httpBackend.flushAllExpected(), aliceTestClient.httpBackend.flushAllExpected(),
]); ]);
@@ -670,7 +670,7 @@ describe("megolm", function() {
200, getTestKeysQueryResponse('@bob:xyz'), 200, getTestKeysQueryResponse('@bob:xyz'),
); );
return q.all([ return Promise.all([
aliceTestClient.client.downloadKeys(['@bob:xyz']), aliceTestClient.client.downloadKeys(['@bob:xyz']),
aliceTestClient.httpBackend.flushAllExpected(), aliceTestClient.httpBackend.flushAllExpected(),
]).then((keys) => { ]).then((keys) => {
@@ -703,7 +703,7 @@ describe("megolm", function() {
}; };
}); });
return q.all([ return Promise.all([
aliceTestClient.client.sendTextMessage(ROOM_ID, 'test'), aliceTestClient.client.sendTextMessage(ROOM_ID, 'test'),
aliceTestClient.httpBackend.flushAllExpected(), aliceTestClient.httpBackend.flushAllExpected(),
]); ]);
@@ -722,7 +722,7 @@ describe("megolm", function() {
}; };
}); });
return q.all([ return Promise.all([
aliceTestClient.client.sendTextMessage(ROOM_ID, 'test2'), aliceTestClient.client.sendTextMessage(ROOM_ID, 'test2'),
aliceTestClient.httpBackend.flushAllExpected(), aliceTestClient.httpBackend.flushAllExpected(),
]); ]);
@@ -824,7 +824,7 @@ describe("megolm", function() {
}; };
}); });
return q.all([ return Promise.all([
aliceTestClient.client.sendTextMessage(ROOM_ID, 'test'), aliceTestClient.client.sendTextMessage(ROOM_ID, 'test'),
aliceTestClient.httpBackend.flushAllExpected(), aliceTestClient.httpBackend.flushAllExpected(),
]); ]);
@@ -875,7 +875,7 @@ describe("megolm", function() {
return aliceTestClient.httpBackend.flushAllExpected(); return aliceTestClient.httpBackend.flushAllExpected();
}).then(function() { }).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( aliceTestClient.httpBackend.when('PUT', '/send/').respond(
200, {event_id: '$event1'}); 200, {event_id: '$event1'});
return q.all([ return Promise.all([
aliceTestClient.client.sendTextMessage(ROOM_ID, 'test'), aliceTestClient.client.sendTextMessage(ROOM_ID, 'test'),
aliceTestClient.httpBackend.flush('/keys/query', 1).then( aliceTestClient.httpBackend.flush('/keys/query', 1).then(
() => aliceTestClient.httpBackend.flush('/send/', 1), () => 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 * @return {Promise} Resolves once the client has emitted a SYNCING event
*/ */
module.exports.syncPromise = function(client) { module.exports.syncPromise = function(client) {
const def = q.defer(); const def = Promise.defer();
const cb = (state) => { const cb = (state) => {
if (state == 'SYNCING') { if (state == 'SYNCING') {
def.resolve(); def.resolve();

View File

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

View File

@@ -136,7 +136,7 @@ describe("MegolmDecryption", function() {
megolmDecryption.shareKeysWithDevice(keyRequest); megolmDecryption.shareKeysWithDevice(keyRequest);
// it's asynchronous, so we have to wait a bit // 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 // check that it called encryptMessageForDevice with
// appropriate args. // appropriate args.
expect(mockOlmLib.encryptMessageForDevice.calls.length) expect(mockOlmLib.encryptMessageForDevice.calls.length)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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