Skip to content

Commit f6f4a0a

Browse files
committed
Remove deprecated callbacks support
1 parent e36d41a commit f6f4a0a

File tree

10 files changed

+300
-692
lines changed

10 files changed

+300
-692
lines changed

spec/unit/crypto/backup.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ describe("MegolmBackup", function() {
299299
let numCalls = 0;
300300
return new Promise<void>((resolve, reject) => {
301301
client.http.authedRequest = function(
302-
callback, method, path, queryParams, data, opts,
302+
method, path, queryParams, data, opts,
303303
) {
304304
++numCalls;
305305
expect(numCalls).toBeLessThanOrEqual(1);
@@ -382,7 +382,7 @@ describe("MegolmBackup", function() {
382382
let numCalls = 0;
383383
return new Promise<void>((resolve, reject) => {
384384
client.http.authedRequest = function(
385-
callback, method, path, queryParams, data, opts,
385+
method, path, queryParams, data, opts,
386386
) {
387387
++numCalls;
388388
expect(numCalls).toBeLessThanOrEqual(1);
@@ -439,7 +439,7 @@ describe("MegolmBackup", function() {
439439
new Promise<void>((resolve, reject) => {
440440
let backupInfo;
441441
client.http.authedRequest = function(
442-
callback, method, path, queryParams, data, opts,
442+
method, path, queryParams, data, opts,
443443
) {
444444
++numCalls;
445445
expect(numCalls).toBeLessThanOrEqual(2);
@@ -543,7 +543,7 @@ describe("MegolmBackup", function() {
543543

544544
await new Promise<void>((resolve, reject) => {
545545
client.http.authedRequest = function(
546-
callback, method, path, queryParams, data, opts,
546+
method, path, queryParams, data, opts,
547547
) {
548548
++numCalls;
549549
expect(numCalls).toBeLessThanOrEqual(2);

spec/unit/crypto/cross-signing.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ describe("Cross Signing", function() {
141141
};
142142
alice.uploadKeySignatures = async () => ({ failures: {} });
143143
alice.setAccountData = async () => ({});
144-
alice.getAccountDataFromServer = async <T extends {[k: string]: any}>(): Promise<T> => ({} as T);
144+
alice.getAccountDataFromServer = async <T extends {[k: string]: any}>(): Promise<T | null> => ({} as T);
145145
const authUploadDeviceSigningKeys = async func => await func({});
146146

147147
// Try bootstrap, expecting `authUploadDeviceSigningKeys` to pass

spec/unit/crypto/secrets.spec.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,13 @@ describe("Secrets", function() {
109109
const secretStorage = alice.crypto.secretStorage;
110110

111111
jest.spyOn(alice, 'setAccountData').mockImplementation(
112-
async function(eventType, contents, callback) {
112+
async function(eventType, contents) {
113113
alice.store.storeAccountDataEvents([
114114
new MatrixEvent({
115115
type: eventType,
116116
content: contents,
117117
}),
118118
]);
119-
if (callback) {
120-
callback(undefined, undefined);
121-
}
122119
return {};
123120
});
124121

@@ -192,7 +189,7 @@ describe("Secrets", function() {
192189
},
193190
},
194191
);
195-
alice.setAccountData = async function(eventType, contents, callback) {
192+
alice.setAccountData = async function(eventType, contents) {
196193
alice.store.storeAccountDataEvents([
197194
new MatrixEvent({
198195
type: eventType,
@@ -332,7 +329,7 @@ describe("Secrets", function() {
332329
);
333330
bob.uploadDeviceSigningKeys = async () => ({});
334331
bob.uploadKeySignatures = jest.fn().mockResolvedValue(undefined);
335-
bob.setAccountData = async function(eventType, contents, callback) {
332+
bob.setAccountData = async function(eventType, contents) {
336333
const event = new MatrixEvent({
337334
type: eventType,
338335
content: contents,

spec/unit/matrix-client.spec.ts

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ describe("MatrixClient", function() {
103103
];
104104
let acceptKeepalives: boolean;
105105
let pendingLookup = null;
106-
function httpReq(cb, method, path, qp, data, prefix) {
106+
function httpReq(method, path, qp, data, prefix) {
107107
if (path === KEEP_ALIVE_PATH && acceptKeepalives) {
108108
return Promise.resolve({
109109
unstable_features: {
@@ -1153,8 +1153,7 @@ describe("MatrixClient", function() {
11531153

11541154
// event type combined
11551155
const expectedEventType = M_BEACON_INFO.name;
1156-
const [callback, method, path, queryParams, requestContent] = client.http.authedRequest.mock.calls[0];
1157-
expect(callback).toBeFalsy();
1156+
const [method, path, queryParams, requestContent] = client.http.authedRequest.mock.calls[0];
11581157
expect(method).toBe('PUT');
11591158
expect(path).toEqual(
11601159
`/rooms/${encodeURIComponent(roomId)}/state/` +
@@ -1168,7 +1167,7 @@ describe("MatrixClient", function() {
11681167
await client.unstable_setLiveBeacon(roomId, content);
11691168

11701169
// event type combined
1171-
const [, , path, , requestContent] = client.http.authedRequest.mock.calls[0];
1170+
const [, path, , requestContent] = client.http.authedRequest.mock.calls[0];
11721171
expect(path).toEqual(
11731172
`/rooms/${encodeURIComponent(roomId)}/state/` +
11741173
`${encodeURIComponent(M_BEACON_INFO.name)}/${encodeURIComponent(userId)}`,
@@ -1229,7 +1228,7 @@ describe("MatrixClient", function() {
12291228
it("is called with plain text topic and callback and sends state event", async () => {
12301229
const sendStateEvent = createSendStateEventMock("pizza");
12311230
client.sendStateEvent = sendStateEvent;
1232-
await client.setRoomTopic(roomId, "pizza", () => {});
1231+
await client.setRoomTopic(roomId, "pizza");
12331232
expect(sendStateEvent).toHaveBeenCalledTimes(1);
12341233
});
12351234

@@ -1244,15 +1243,9 @@ describe("MatrixClient", function() {
12441243
describe("setPassword", () => {
12451244
const auth = { session: 'abcdef', type: 'foo' };
12461245
const newPassword = 'newpassword';
1247-
const callback = () => {};
1248-
1249-
const passwordTest = (expectedRequestContent: any, expectedCallback?: Function) => {
1250-
const [callback, method, path, queryParams, requestContent] = client.http.authedRequest.mock.calls[0];
1251-
if (expectedCallback) {
1252-
expect(callback).toBe(expectedCallback);
1253-
} else {
1254-
expect(callback).toBeFalsy();
1255-
}
1246+
1247+
const passwordTest = (expectedRequestContent: any) => {
1248+
const [method, path, queryParams, requestContent] = client.http.authedRequest.mock.calls[0];
12561249
expect(method).toBe('POST');
12571250
expect(path).toEqual('/account/password');
12581251
expect(queryParams).toBeFalsy();
@@ -1269,8 +1262,8 @@ describe("MatrixClient", function() {
12691262
});
12701263

12711264
it("no logout_devices specified + callback", async () => {
1272-
await client.setPassword(auth, newPassword, callback);
1273-
passwordTest({ auth, new_password: newPassword }, callback);
1265+
await client.setPassword(auth, newPassword);
1266+
passwordTest({ auth, new_password: newPassword });
12741267
});
12751268

12761269
it("overload logoutDevices=true", async () => {
@@ -1279,8 +1272,8 @@ describe("MatrixClient", function() {
12791272
});
12801273

12811274
it("overload logoutDevices=true + callback", async () => {
1282-
await client.setPassword(auth, newPassword, true, callback);
1283-
passwordTest({ auth, new_password: newPassword, logout_devices: true }, callback);
1275+
await client.setPassword(auth, newPassword, true);
1276+
passwordTest({ auth, new_password: newPassword, logout_devices: true });
12841277
});
12851278

12861279
it("overload logoutDevices=false", async () => {
@@ -1289,8 +1282,8 @@ describe("MatrixClient", function() {
12891282
});
12901283

12911284
it("overload logoutDevices=false + callback", async () => {
1292-
await client.setPassword(auth, newPassword, false, callback);
1293-
passwordTest({ auth, new_password: newPassword, logout_devices: false }, callback);
1285+
await client.setPassword(auth, newPassword, false);
1286+
passwordTest({ auth, new_password: newPassword, logout_devices: false });
12941287
});
12951288
});
12961289

@@ -1305,8 +1298,7 @@ describe("MatrixClient", function() {
13051298
const result = await client.getLocalAliases(roomId);
13061299

13071300
// Current version of the endpoint we support is v3
1308-
const [callback, method, path, queryParams, data, opts] = client.http.authedRequest.mock.calls[0];
1309-
expect(callback).toBeFalsy();
1301+
const [method, path, queryParams, data, opts] = client.http.authedRequest.mock.calls[0];
13101302
expect(data).toBeFalsy();
13111303
expect(method).toBe('GET');
13121304
expect(path).toEqual(`/rooms/${encodeURIComponent(roomId)}/aliases`);

src/@types/requests.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { Callback } from "../client";
1817
import { IContent, IEvent } from "../models/event";
1918
import { Preset, Visibility } from "./partials";
2019
import { IEventWithRoomId, SearchKey } from "./search";
@@ -125,7 +124,6 @@ export interface IUploadOpts {
125124
type?: string;
126125
rawResponse?: boolean;
127126
onlyContentUri?: boolean;
128-
callback?: Callback;
129127
progressHandler?: (state: {loaded: number, total: number}) => void;
130128
}
131129

0 commit comments

Comments
 (0)