Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions spec/integ/matrix-client-syncing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,16 @@ describe("MatrixClient syncing", () => {

expect(fires).toBe(1);
});

it("should work when all network calls fail", async () => {
httpBackend!.expectedRequests = [];
httpBackend!.when("GET", "").fail(0, new Error("CORS or something"));
const prom = client!.startClient();
await Promise.all([
expect(prom).resolves.toBeUndefined(),
httpBackend!.flushAllExpected(),
]);
});
});

describe("initial sync", () => {
Expand Down
33 changes: 21 additions & 12 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1193,16 +1193,18 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
this.syncApi.stop();
}

const serverVersions = await this.getVersions();
this.canSupport = await buildFeatureSupportMap(serverVersions);

const support = this.canSupport.get(Feature.ThreadUnreadNotifications);
UNREAD_THREAD_NOTIFICATIONS.setPreferUnstable(support === ServerSupport.Unstable);

const { threads, list, fwdPagination } = await this.doesServerSupportThread();
Thread.setServerSideSupport(threads);
Thread.setServerSideListSupport(list);
Thread.setServerSideFwdPaginationSupport(fwdPagination);
try {
await this.getVersions();

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

// shallow-copy the opts dict before modifying and storing it
this.clientOpts = Object.assign({}, opts) as IStoredClientOpts;
Expand Down Expand Up @@ -6712,7 +6714,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* unstable APIs it supports
* @return {Promise<object>} The server /versions response
*/
public getVersions(): Promise<IServerVersions> {
public async getVersions(): Promise<IServerVersions> {
if (this.serverVersionsPromise) {
return this.serverVersionsPromise;
}
Expand All @@ -6724,13 +6726,20 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
{
prefix: '',
},
).catch((e: Error) => {
).catch(e => {
// Need to unset this if it fails, otherwise we'll never retry
this.serverVersionsPromise = undefined;
// but rethrow the exception to anything that was waiting
throw e;
});

const serverVersions = await this.serverVersionsPromise;
this.canSupport = await buildFeatureSupportMap(serverVersions);

// We can set flag values to use their stable or unstable version
const support = this.canSupport.get(Feature.ThreadUnreadNotifications);
UNREAD_THREAD_NOTIFICATIONS.setPreferUnstable(support === ServerSupport.Unstable);

return this.serverVersionsPromise;
}

Expand Down