Skip to content

Commit a19bea8

Browse files
committed
Make the frontend parse the stable scope as well
1 parent fe75448 commit a19bea8

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

frontend/src/utils/deviceIdFromScope.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@ import { describe, expect, it } from "vitest";
1010
import { getDeviceIdFromScope } from "./deviceIdFromScope";
1111

1212
describe("getDeviceIdFromScope()", () => {
13-
it("returns deviceid when device is part of scope", () => {
13+
it("returns deviceid when device is part of scope (unstable)", () => {
1414
const scope =
1515
"openid urn:matrix:org.matrix.msc2967.client:api:* urn:matrix:org.matrix.msc2967.client:device:abcd1234";
1616
expect(getDeviceIdFromScope(scope)).toEqual("abcd1234");
1717
});
1818

19+
it("returns deviceid when device is part of scope (stable)", () => {
20+
const scope =
21+
"openid urn:matrix:client:api:* urn:matrix:client:device:abcd1234";
22+
expect(getDeviceIdFromScope(scope)).toEqual("abcd1234");
23+
});
24+
1925
it("returns undefined when device not part of scope", () => {
2026
const scope = "openid some:other:scope ";
2127
expect(getDeviceIdFromScope(scope)).toBeUndefined();

frontend/src/utils/deviceIdFromScope.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
* Please see LICENSE in the repository root for full details.
66
*/
77

8-
const DEVICE_PREFIX = "urn:matrix:org.matrix.msc2967.client:device:";
8+
const UNSTABLE_DEVICE_PREFIX = "urn:matrix:org.matrix.msc2967.client:device:";
9+
const STABLE_DEVICE_PREFIX = "urn:matrix:client:device:";
910

1011
/**
1112
* Device scopes are suffixed with the deviceId
@@ -14,6 +15,7 @@ const DEVICE_PREFIX = "urn:matrix:org.matrix.msc2967.client:device:";
1415
* @returns deviceId, or undefined when not a device scope
1516
*/
1617
export const getDeviceIdFromScope = (scope: string): string | undefined => {
17-
const [, deviceId] = scope.split(DEVICE_PREFIX);
18-
return deviceId;
18+
const [, stableDeviceId] = scope.split(STABLE_DEVICE_PREFIX);
19+
const [, unstableDeviceId] = scope.split(UNSTABLE_DEVICE_PREFIX);
20+
return stableDeviceId || unstableDeviceId;
1921
};

0 commit comments

Comments
 (0)