-
-
Notifications
You must be signed in to change notification settings - Fork 676
Fix sync init when thread unread notif is not supported #2739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
476f2c9
0ab369b
5da1d7f
5c7f471
6e6d730
ef6e5fa
bfadf01
b2d5f79
32ac04c
9c8cac8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| Copyright 2022 The Matrix.org Foundation C.I.C. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| import { buildFeatureSupportMap, Feature, ServerSupport } from "../../src/feature"; | ||
|
|
||
| describe("Feature detection", () => { | ||
| it("checks the matrix version", async () => { | ||
| const support = await buildFeatureSupportMap({ | ||
| versions: ["v1.3"], | ||
| unstable_features: {}, | ||
| }); | ||
|
|
||
| expect(support.get(Feature.Thread)).toBe(ServerSupport.Stable); | ||
| expect(support.get(Feature.ThreadUnreadNotifications)).toBe(ServerSupport.Unsupported); | ||
| }); | ||
|
|
||
| it("checks the matrix msc number", async () => { | ||
| const support = await buildFeatureSupportMap({ | ||
| versions: ["v1.2"], | ||
| unstable_features: { | ||
| "org.matrix.msc3771": true, | ||
| "org.matrix.msc3773": true, | ||
| }, | ||
| }); | ||
| expect(support.get(Feature.ThreadUnreadNotifications)).toBe(ServerSupport.Unstable); | ||
| }); | ||
|
|
||
| it("requires two MSCs to pass", async () => { | ||
| const support = await buildFeatureSupportMap({ | ||
| versions: ["v1.2"], | ||
| unstable_features: { | ||
| "org.matrix.msc3771": false, | ||
| "org.matrix.msc3773": true, | ||
| }, | ||
| }); | ||
| expect(support.get(Feature.ThreadUnreadNotifications)).toBe(ServerSupport.Unsupported); | ||
| }); | ||
|
|
||
| it("requires two MSCs OR matrix versions to pass", async () => { | ||
| const support = await buildFeatureSupportMap({ | ||
| versions: ["v1.4"], | ||
| unstable_features: { | ||
| "org.matrix.msc3771": false, | ||
| "org.matrix.msc3773": true, | ||
| }, | ||
| }); | ||
| expect(support.get(Feature.ThreadUnreadNotifications)).toBe(ServerSupport.Stable); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| Copyright 2022 The Matrix.org Foundation C.I.C. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| import { IServerVersions } from "./client"; | ||
|
|
||
| export enum ServerSupport { | ||
| Stable, | ||
| Unstable, | ||
| Unsupported | ||
| } | ||
|
|
||
| export enum Feature { | ||
| Thread = "Thread", | ||
| ThreadUnreadNotifications = "ThreadUnreadNotifications", | ||
| } | ||
|
|
||
| type FeatureSupportCondition = { | ||
| unstablePrefixes?: string[]; | ||
| matrixVersion?: string; | ||
| }; | ||
|
|
||
| const featureSupportResolver: Record<string, FeatureSupportCondition> = { | ||
| [Feature.Thread]: { | ||
| unstablePrefixes: ["org.matrix.msc3440"], | ||
| matrixVersion: "v1.3", | ||
| }, | ||
| [Feature.ThreadUnreadNotifications]: { | ||
| unstablePrefixes: ["org.matrix.msc3771", "org.matrix.msc3773"], | ||
| matrixVersion: "v1.4", | ||
| }, | ||
| }; | ||
|
|
||
| export async function buildFeatureSupportMap(versions: IServerVersions): Promise<Map<Feature, ServerSupport>> { | ||
| const supportMap = new Map<Feature, ServerSupport>(); | ||
| for (const [feature, supportCondition] of Object.entries(featureSupportResolver)) { | ||
| const supportMatrixVersion = versions.versions?.includes(supportCondition.matrixVersion || "") ?? false; | ||
| const supportUnstablePrefixes = supportCondition.unstablePrefixes?.every(unstablePrefix => { | ||
| return versions.unstable_features?.[unstablePrefix] === true; | ||
| }) ?? false; | ||
| if (supportMatrixVersion) { | ||
| supportMap.set(feature as Feature, ServerSupport.Stable); | ||
| } else if (supportUnstablePrefixes) { | ||
| supportMap.set(feature as Feature, ServerSupport.Unstable); | ||
| } else { | ||
| supportMap.set(feature as Feature, ServerSupport.Unsupported); | ||
| } | ||
| } | ||
| return supportMap; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,6 +59,7 @@ import { BeaconEvent } from "./models/beacon"; | |
| import { IEventsResponse } from "./@types/requests"; | ||
| import { IAbortablePromise } from "./@types/partials"; | ||
| import { UNREAD_THREAD_NOTIFICATIONS } from "./@types/sync"; | ||
| import { Feature, ServerSupport } from "./feature"; | ||
|
|
||
| const DEBUG = true; | ||
|
|
||
|
|
@@ -562,7 +563,11 @@ export class SyncApi { | |
| }; | ||
|
|
||
| private buildDefaultFilter = () => { | ||
| return new Filter(this.client.credentials.userId); | ||
| const filter = new Filter(this.client.credentials.userId); | ||
| if (this.client.canSupport.get(Feature.ThreadUnreadNotifications) !== ServerSupport.Unsupported) { | ||
| filter.setUnreadThreadNotifications(true); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! I've changed the code to use
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should update |
||
| } | ||
| return filter; | ||
| }; | ||
|
|
||
| private checkLazyLoadStatus = async () => { | ||
|
|
@@ -706,10 +711,6 @@ export class SyncApi { | |
| const initialFilter = this.buildDefaultFilter(); | ||
| initialFilter.setDefinition(filter.getDefinition()); | ||
| initialFilter.setTimelineLimit(this.opts.initialSyncLimit); | ||
| const supportsThreadNotifications = | ||
| await this.client.doesServerSupportUnstableFeature("org.matrix.msc3773") | ||
| || await this.client.isVersionSupported("v1.4"); | ||
| initialFilter.setUnreadThreadNotifications(supportsThreadNotifications); | ||
| // Use an inline filter, no point uploading it for a single usage | ||
| firstSyncFilter = JSON.stringify(initialFilter.getDefinition()); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.