Skip to content

Commit 679ba69

Browse files
committed
Merge tag 'v21.0.1' into sc
* Fix default behavior of Room.getBlacklistUnverifiedDevices ([\matrix-org#2830](matrix-org#2830)). Contributed by @duxovni. * Catch server versions API call exception when starting the client ([\matrix-org#2828](matrix-org#2828)). Fixes element-hq/element-web#23634. * Fix authedRequest including `Authorization: Bearer undefined` for password resets ([\matrix-org#2822](matrix-org#2822)). Fixes element-hq/element-web#23655.
2 parents 9b20f5c + 81c3668 commit 679ba69

File tree

10 files changed

+79
-45
lines changed

10 files changed

+79
-45
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Changes in [21.0.1](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v21.0.1) (2022-11-01)
2+
==================================================================================================
3+
4+
## 🐛 Bug Fixes
5+
* Fix default behavior of Room.getBlacklistUnverifiedDevices ([\#2830](https://github.com/matrix-org/matrix-js-sdk/pull/2830)). Contributed by @duxovni.
6+
* Catch server versions API call exception when starting the client ([\#2828](https://github.com/matrix-org/matrix-js-sdk/pull/2828)). Fixes vector-im/element-web#23634.
7+
* Fix authedRequest including `Authorization: Bearer undefined` for password resets ([\#2822](https://github.com/matrix-org/matrix-js-sdk/pull/2822)). Fixes vector-im/element-web#23655.
8+
19
Changes in [21.0.0](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v21.0.0) (2022-10-25)
210
==================================================================================================
311

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "matrix-js-sdk",
3-
"version": "21.0.0",
3+
"version": "21.0.1",
44
"description": "Matrix Client-Server SDK for Javascript",
55
"engines": {
66
"node": ">=16.0.0"

spec/integ/matrix-client-syncing.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,16 @@ describe("MatrixClient syncing", () => {
274274

275275
expect(fires).toBe(1);
276276
});
277+
278+
it("should work when all network calls fail", async () => {
279+
httpBackend!.expectedRequests = [];
280+
httpBackend!.when("GET", "").fail(0, new Error("CORS or something"));
281+
const prom = client!.startClient();
282+
await Promise.all([
283+
expect(prom).resolves.toBeUndefined(),
284+
httpBackend!.flushAllExpected(),
285+
]);
286+
});
277287
});
278288

279289
describe("initial sync", () => {

spec/unit/http-api/fetch.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,14 @@ describe("FetchHttpApi", () => {
220220
expect(api.authedRequest(Method.Get, "/path")).rejects.toThrow("Ye shall ask for consent"),
221221
]);
222222
});
223+
224+
describe("authedRequest", () => {
225+
it("should not include token if unset", () => {
226+
const fetchFn = jest.fn();
227+
const emitter = new TypedEventEmitter<HttpApiEvent, HttpApiEventHandlerMap>();
228+
const api = new FetchHttpApi(emitter, { baseUrl, prefix, fetchFn });
229+
api.authedRequest(Method.Post, "/account/password");
230+
expect(fetchFn.mock.calls[0][1].headers.Authorization).toBeUndefined();
231+
});
232+
});
223233
});

spec/unit/room.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2737,4 +2737,15 @@ describe("Room", function() {
27372737
expect(room.getPendingEvent(ev.getId())).toBe(ev);
27382738
}
27392739
});
2740+
2741+
describe("getBlacklistUnverifiedDevices", () => {
2742+
it("defaults to null", () => {
2743+
expect(room.getBlacklistUnverifiedDevices()).toBeNull();
2744+
});
2745+
2746+
it("is updated by setBlacklistUnverifiedDevices", () => {
2747+
room.setBlacklistUnverifiedDevices(false);
2748+
expect(room.getBlacklistUnverifiedDevices()).toBe(false);
2749+
});
2750+
});
27402751
});

src/client.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,15 +1192,17 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
11921192
this.syncApi.stop();
11931193
}
11941194

1195-
const serverVersions = await this.getVersions();
1196-
this.canSupport = await buildFeatureSupportMap(serverVersions);
1197-
1198-
const support = this.canSupport.get(Feature.ThreadUnreadNotifications);
1199-
UNREAD_THREAD_NOTIFICATIONS.setPreferUnstable(support === ServerSupport.Unstable);
1195+
try {
1196+
await this.getVersions();
12001197

1201-
const { threads, list } = await this.doesServerSupportThread();
1202-
Thread.setServerSideSupport(threads);
1203-
Thread.setServerSideListSupport(list);
1198+
// This should be done with `canSupport`
1199+
// TODO: https://github.com/vector-im/element-web/issues/23643
1200+
const { threads, list } = await this.doesServerSupportThread();
1201+
Thread.setServerSideSupport(threads);
1202+
Thread.setServerSideListSupport(list);
1203+
} catch (e) {
1204+
logger.error("Can't fetch server versions, continuing to initialise sync, this will be retried later", e);
1205+
}
12041206

12051207
// shallow-copy the opts dict before modifying and storing it
12061208
this.clientOpts = Object.assign({}, opts) as IStoredClientOpts;
@@ -6518,7 +6520,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
65186520
* unstable APIs it supports
65196521
* @return {Promise<object>} The server /versions response
65206522
*/
6521-
public getVersions(): Promise<IServerVersions> {
6523+
public async getVersions(): Promise<IServerVersions> {
65226524
if (this.serverVersionsPromise) {
65236525
return this.serverVersionsPromise;
65246526
}
@@ -6530,13 +6532,20 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
65306532
{
65316533
prefix: '',
65326534
},
6533-
).catch((e: Error) => {
6535+
).catch(e => {
65346536
// Need to unset this if it fails, otherwise we'll never retry
65356537
this.serverVersionsPromise = null;
65366538
// but rethrow the exception to anything that was waiting
65376539
throw e;
65386540
});
65396541

6542+
const serverVersions = await this.serverVersionsPromise;
6543+
this.canSupport = await buildFeatureSupportMap(serverVersions);
6544+
6545+
// We can set flag values to use their stable or unstable version
6546+
const support = this.canSupport.get(Feature.ThreadUnreadNotifications);
6547+
UNREAD_THREAD_NOTIFICATIONS.setPreferUnstable(support === ServerSupport.Unstable);
6548+
65406549
return this.serverVersionsPromise;
65416550
}
65426551

@@ -7703,15 +7712,6 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
77037712
* @param {string=} opts.type Content-type for the upload. Defaults to
77047713
* <tt>file.type</tt>, or <tt>applicaton/octet-stream</tt>.
77057714
*
7706-
* @param {boolean=} opts.rawResponse Return the raw body, rather than
7707-
* parsing the JSON. Defaults to false (except on node.js, where it
7708-
* defaults to true for backwards compatibility).
7709-
*
7710-
* @param {boolean=} opts.onlyContentUri Just return the content URI,
7711-
* rather than the whole body. Defaults to false (except on browsers,
7712-
* where it defaults to true for backwards compatibility). Ignored if
7713-
* opts.rawResponse is true.
7714-
*
77157715
* @param {Function=} opts.progressHandler Optional. Called when a chunk of
77167716
* data has been uploaded, with an object containing the fields `loaded`
77177717
* (number of bytes transferred) and `total` (total size, if known).
@@ -7884,7 +7884,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
78847884
* @return {module:http-api.MatrixError} Rejects: with an error response.
78857885
*/
78867886
public setPassword(
7887-
authDict: any,
7887+
authDict: IAuthDict,
78887888
newPassword: string,
78897889
logoutDevices?: boolean,
78907890
): Promise<{}> {

src/crypto/algorithms/megolm.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,8 +1134,9 @@ class MegolmEncryption extends EncryptionAlgorithm {
11341134

11351135
// The global value is treated as a default for when rooms don't specify a value.
11361136
let isBlacklisting = this.crypto.getGlobalBlacklistUnverifiedDevices();
1137-
if (typeof room.getBlacklistUnverifiedDevices() === 'boolean') {
1138-
isBlacklisting = room.getBlacklistUnverifiedDevices();
1137+
const isRoomBlacklisting = room.getBlacklistUnverifiedDevices();
1138+
if (typeof isRoomBlacklisting === 'boolean') {
1139+
isBlacklisting = isRoomBlacklisting;
11391140
}
11401141

11411142
// We are happy to use a cached version here: we assume that if we already

src/http-api/fetch.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,20 @@ export class FetchHttpApi<O extends IHttpOpts> {
143143
): Promise<ResponseType<T, O>> {
144144
if (!queryParams) queryParams = {};
145145

146-
if (this.opts.useAuthorizationHeader) {
147-
if (!opts.headers) {
148-
opts.headers = {};
146+
if (this.opts.accessToken) {
147+
if (this.opts.useAuthorizationHeader) {
148+
if (!opts.headers) {
149+
opts.headers = {};
150+
}
151+
if (!opts.headers.Authorization) {
152+
opts.headers.Authorization = "Bearer " + this.opts.accessToken;
153+
}
154+
if (queryParams.access_token) {
155+
delete queryParams.access_token;
156+
}
157+
} else if (!queryParams.access_token) {
158+
queryParams.access_token = this.opts.accessToken;
149159
}
150-
if (!opts.headers.Authorization) {
151-
opts.headers.Authorization = "Bearer " + this.opts.accessToken;
152-
}
153-
if (queryParams.access_token) {
154-
delete queryParams.access_token;
155-
}
156-
} else if (!queryParams.access_token) {
157-
queryParams.access_token = this.opts.accessToken;
158160
}
159161

160162
const requestPromise = this.request<T>(method, path, queryParams, body, opts);

src/http-api/index.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,6 @@ export class MatrixHttpApi<O extends IHttpOpts> extends FetchHttpApi<O> {
5151
* @param {string=} opts.type Content-type for the upload. Defaults to
5252
* <tt>file.type</tt>, or <tt>application/octet-stream</tt>.
5353
*
54-
* @param {boolean=} opts.rawResponse Return the raw body, rather than
55-
* parsing the JSON. Defaults to false (except on node.js, where it
56-
* defaults to true for backwards compatibility).
57-
*
58-
* @param {boolean=} opts.onlyContentUri Just return the content URI,
59-
* rather than the whole body. Defaults to false (except on browsers,
60-
* where it defaults to true for backwards compatibility). Ignored if
61-
* opts.rawResponse is true.
62-
*
6354
* @param {Function=} opts.progressHandler Optional. Called when a chunk of
6455
* data has been uploaded, with an object containing the fields `loaded`
6556
* (number of bytes transferred) and `total` (total size, if known).

src/models/room.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,8 +1325,9 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
13251325
* @return {Boolean} true if blacklisting unverified devices, null
13261326
* if the global value should be used for this room.
13271327
*/
1328-
public getBlacklistUnverifiedDevices(): boolean {
1329-
return !!this.blacklistUnverifiedDevices;
1328+
public getBlacklistUnverifiedDevices(): boolean | null {
1329+
if (this.blacklistUnverifiedDevices === undefined) return null;
1330+
return this.blacklistUnverifiedDevices;
13301331
}
13311332

13321333
/**

0 commit comments

Comments
 (0)