1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-28 05:03:59 +03:00

nothing works anymore :((

This commit is contained in:
Michael Telatynski
2019-11-23 12:18:39 +00:00
parent 04fca16420
commit 5e0ba9971c
5 changed files with 86 additions and 86 deletions

View File

@@ -279,16 +279,17 @@ function sendMessage(client) {
function expectSendMessageRequest(httpBackend) { function expectSendMessageRequest(httpBackend) {
const path = "/send/m.room.encrypted/"; const path = "/send/m.room.encrypted/";
const deferred = Promise.defer(); const prom = new Promise((resolve) => {
httpBackend.when("PUT", path).respond(200, function(path, content) { httpBackend.when("PUT", path).respond(200, function(path, content) {
deferred.resolve(content); resolve(content);
return { return {
event_id: "asdfgh", event_id: "asdfgh",
}; };
}); });
});
// it can take a while to process the key query // it can take a while to process the key query
return httpBackend.flush(path, 1).then(() => deferred.promise); return httpBackend.flush(path, 1).then(() => prom);
} }
function aliRecvMessage() { function aliRecvMessage() {

View File

@@ -83,18 +83,19 @@ 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 = Promise.defer(); const prom = new Promise((resolve) => {
client.on("sync", function(state) { client.on("sync", function(state) {
logger.log("sync", state); logger.log("sync", state);
if (state != "SYNCING") { if (state != "SYNCING") {
return; return;
} }
deferred.resolve(); resolve();
});
}); });
return Promise.all([ return Promise.all([
httpBackend.flushAllExpected(), httpBackend.flushAllExpected(),
deferred.promise, prom,
]); ]);
} }
@@ -343,7 +344,7 @@ describe("MatrixClient event timelines", function() {
}; };
}); });
const deferred = Promise.defer(); const prom = new Promise((resolve, reject) => {
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) {
@@ -355,13 +356,13 @@ describe("MatrixClient event timelines", function() {
.toEqual("start_token"); .toEqual("start_token");
// expect(tl.getPaginationToken(EventTimeline.FORWARDS)) // expect(tl.getPaginationToken(EventTimeline.FORWARDS))
// .toEqual("s_5_4"); // .toEqual("s_5_4");
}).done(() => deferred.resolve(), }).done(resolve, reject);
(e) => deferred.reject(e)); });
}); });
return Promise.all([ return Promise.all([
httpBackend.flushAllExpected(), httpBackend.flushAllExpected(),
deferred.promise, prom,
]); ]);
}); });

View File

@@ -691,12 +691,12 @@ describe("MatrixClient syncing", function() {
include_leave: true }}); include_leave: true }});
}).respond(200, { filter_id: "another_id" }); }).respond(200, { filter_id: "another_id" });
const defer = Promise.defer(); const prom = new Promise((resolve) => {
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");
defer.resolve(); resolve();
}).respond(200, {}); }).respond(200, {});
});
client.syncLeftRooms(); client.syncLeftRooms();
@@ -707,7 +707,7 @@ describe("MatrixClient syncing", function() {
// flush the syncs // flush the syncs
return httpBackend.flushAllExpected(); return httpBackend.flushAllExpected();
}), }),
defer.promise, prom,
]); ]);
}); });

View File

@@ -3886,26 +3886,26 @@ MatrixClient.prototype.setRoomMutePushRule = function(scope, roomId, mute) {
} }
if (deferred) { if (deferred) {
return new Promise((resolve, reject) => {
// Update this.pushRules when the operation completes // Update this.pushRules when the operation completes
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;
ruleRefreshDeferred.resolve(); resolve();
}, function(err) { }, function(err) {
ruleRefreshDeferred.reject(err); reject(err);
}); });
}, function(err) { }, function(err) {
// Update it even if the previous operation fails. This can help the // Update it even if the previous operation fails. This can help the
// app to recover when push settings has been modifed from another client // app to recover when push settings has been modifed from another client
self.getPushRules().done(function(result) { self.getPushRules().done(function(result) {
self.pushRules = result; self.pushRules = result;
ruleRefreshDeferred.reject(err); reject(err);
}, function(err2) { }, function(err2) {
ruleRefreshDeferred.reject(err); reject(err);
});
}); });
}); });
return ruleRefreshDeferred.promise;
} }
}; };

View File

@@ -58,9 +58,9 @@ export class Backend {
getOrAddOutgoingRoomKeyRequest(request) { getOrAddOutgoingRoomKeyRequest(request) {
const requestBody = request.requestBody; const requestBody = request.requestBody;
const deferred = Promise.defer(); return new Promise((resolve, reject) => {
const txn = this._db.transaction("outgoingRoomKeyRequests", "readwrite"); const txn = this._db.transaction("outgoingRoomKeyRequests", "readwrite");
txn.onerror = deferred.reject; txn.onerror = reject;
// first see if we already have an entry for this request. // first see if we already have an entry for this request.
this._getOutgoingRoomKeyRequest(txn, requestBody, (existing) => { this._getOutgoingRoomKeyRequest(txn, requestBody, (existing) => {
@@ -71,7 +71,7 @@ export class Backend {
`${requestBody.room_id} / ${requestBody.session_id}: ` + `${requestBody.room_id} / ${requestBody.session_id}: ` +
`not sending another`, `not sending another`,
); );
deferred.resolve(existing); resolve(existing);
return; return;
} }
@@ -81,12 +81,11 @@ export class Backend {
`enqueueing key request for ${requestBody.room_id} / ` + `enqueueing key request for ${requestBody.room_id} / ` +
requestBody.session_id, requestBody.session_id,
); );
txn.oncomplete = () => { deferred.resolve(request); }; txn.oncomplete = () => { resolve(request); };
const store = txn.objectStore("outgoingRoomKeyRequests"); const store = txn.objectStore("outgoingRoomKeyRequests");
store.add(request); store.add(request);
}); });
});
return deferred.promise;
} }
/** /**
@@ -100,15 +99,14 @@ export class Backend {
* not found * not found
*/ */
getOutgoingRoomKeyRequest(requestBody) { getOutgoingRoomKeyRequest(requestBody) {
const deferred = Promise.defer(); return new Promise((resolve, reject) => {
const txn = this._db.transaction("outgoingRoomKeyRequests", "readonly"); const txn = this._db.transaction("outgoingRoomKeyRequests", "readonly");
txn.onerror = deferred.reject; txn.onerror = reject;
this._getOutgoingRoomKeyRequest(txn, requestBody, (existing) => { this._getOutgoingRoomKeyRequest(txn, requestBody, (existing) => {
deferred.resolve(existing); resolve(existing);
});
}); });
return deferred.promise;
} }
/** /**