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