From 7e0cf5c7832a46243f4b145a06c7ac821eda4e14 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 29 Dec 2020 12:35:48 -0700 Subject: [PATCH 1/3] Wire up MSC2931 widget navigation Fixes https://github.com/vector-im/element-web/issues/16006 **Requires https://github.com/matrix-org/matrix-widget-api/pull/27** --- src/i18n/strings/en_EN.json | 1 + src/stores/widgets/ElementWidgetActions.ts | 7 +++++++ src/stores/widgets/ElementWidgetCapabilities.ts | 3 +++ src/stores/widgets/StopGapWidgetDriver.ts | 9 +++++++++ src/widgets/CapabilityText.tsx | 3 +++ 5 files changed, 23 insertions(+) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index c0939871e2..4dad7a97f1 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -584,6 +584,7 @@ "Send stickers into this room": "Send stickers into this room", "Send stickers into your active room": "Send stickers into your active room", "Change which room you're viewing": "Change which room you're viewing", + "Change which room you're viewing and use permalinks": "Change which room you're viewing and use permalinks", "Change the topic of this room": "Change the topic of this room", "See when the topic changes in this room": "See when the topic changes in this room", "Change the topic of your active room": "Change the topic of your active room", diff --git a/src/stores/widgets/ElementWidgetActions.ts b/src/stores/widgets/ElementWidgetActions.ts index 76390086ab..de48746a74 100644 --- a/src/stores/widgets/ElementWidgetActions.ts +++ b/src/stores/widgets/ElementWidgetActions.ts @@ -20,9 +20,16 @@ export enum ElementWidgetActions { ClientReady = "im.vector.ready", HangupCall = "im.vector.hangup", OpenIntegrationManager = "integration_manager_open", + + /** + * @deprecated Use MSC2931 instead + */ ViewRoom = "io.element.view_room", } +/** + * @deprecated Use MSC2931 instead + */ export interface IViewRoomApiRequest extends IWidgetApiRequest { data: { room_id: string; // eslint-disable-line camelcase diff --git a/src/stores/widgets/ElementWidgetCapabilities.ts b/src/stores/widgets/ElementWidgetCapabilities.ts index 3f17d27909..e493d5618f 100644 --- a/src/stores/widgets/ElementWidgetCapabilities.ts +++ b/src/stores/widgets/ElementWidgetCapabilities.ts @@ -15,5 +15,8 @@ */ export enum ElementWidgetCapabilities { + /** + * @deprecated Use MSC2931 instead. + */ CanChangeViewedRoom = "io.element.view_room", } diff --git a/src/stores/widgets/StopGapWidgetDriver.ts b/src/stores/widgets/StopGapWidgetDriver.ts index 2d2d1fcbdb..8baea97fe0 100644 --- a/src/stores/widgets/StopGapWidgetDriver.ts +++ b/src/stores/widgets/StopGapWidgetDriver.ts @@ -43,6 +43,7 @@ import { EventType } from "matrix-js-sdk/src/@types/event"; import { CHAT_EFFECTS } from "../../effects"; import { containsEmoji } from "../../effects/utils"; import dis from "../../dispatcher/dispatcher"; +import {tryTransformPermalinkToLocalHref} from "../../utils/permalinks/Permalinks"; // TODO: Purge this from the universe @@ -171,4 +172,12 @@ export class StopGapWidgetDriver extends WidgetDriver { }, }); } + + public async navigate(uri: string): Promise { + const localUri = tryTransformPermalinkToLocalHref(uri); + if (!localUri || localUri === uri) { // parse failure can lead to an unmodified URL + throw new Error("Failed to transform URI"); + } + window.location.hash = localUri; // it'll just be a fragment + } } diff --git a/src/widgets/CapabilityText.tsx b/src/widgets/CapabilityText.tsx index 834ea3ec37..044b7701ba 100644 --- a/src/widgets/CapabilityText.tsx +++ b/src/widgets/CapabilityText.tsx @@ -60,6 +60,9 @@ export class CapabilityText { [ElementWidgetCapabilities.CanChangeViewedRoom]: { [GENERIC_WIDGET_KIND]: _td("Change which room you're viewing"), }, + [MatrixCapabilities.MSC2931Navigate]: { + [GENERIC_WIDGET_KIND]: _td("Change which room you're viewing and use permalinks"), + }, }; private static stateSendRecvCaps: ISendRecvStaticCapText = { From ea61c979f91f323d6806f4044bb95808c5794074 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Sat, 16 Jan 2021 23:29:27 -0700 Subject: [PATCH 2/3] Try a different string --- src/i18n/strings/en_EN.json | 2 +- src/widgets/CapabilityText.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index b53bb90c92..384f6d04e9 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -584,7 +584,7 @@ "Send stickers into this room": "Send stickers into this room", "Send stickers into your active room": "Send stickers into your active room", "Change which room you're viewing": "Change which room you're viewing", - "Change which room you're viewing and use permalinks": "Change which room you're viewing and use permalinks", + "Change which room, message, or user you're viewing": "Change which room, message, or user you're viewing", "Change the topic of this room": "Change the topic of this room", "See when the topic changes in this room": "See when the topic changes in this room", "Change the topic of your active room": "Change the topic of your active room", diff --git a/src/widgets/CapabilityText.tsx b/src/widgets/CapabilityText.tsx index 044b7701ba..273d22dc81 100644 --- a/src/widgets/CapabilityText.tsx +++ b/src/widgets/CapabilityText.tsx @@ -61,7 +61,7 @@ export class CapabilityText { [GENERIC_WIDGET_KIND]: _td("Change which room you're viewing"), }, [MatrixCapabilities.MSC2931Navigate]: { - [GENERIC_WIDGET_KIND]: _td("Change which room you're viewing and use permalinks"), + [GENERIC_WIDGET_KIND]: _td("Change which room, message, or user you're viewing"), }, }; From f6a328a55b44ca508a6aaed7ef7f63f5759d110c Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Sat, 16 Jan 2021 23:34:16 -0700 Subject: [PATCH 3/3] Update widget api --- package.json | 2 +- yarn.lock | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 92b574da34..cb70541f99 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,7 @@ "linkifyjs": "^2.1.9", "lodash": "^4.17.19", "matrix-js-sdk": "github:matrix-org/matrix-js-sdk#develop", - "matrix-widget-api": "^0.1.0-beta.10", + "matrix-widget-api": "0.1.0-beta.11", "minimist": "^1.2.5", "pako": "^1.0.11", "parse5": "^5.1.1", diff --git a/yarn.lock b/yarn.lock index b0769c2c04..e2292d66ff 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1809,6 +1809,11 @@ resolved "https://registry.yarnpkg.com/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#1ee30d79544ca84d68d4b3cdb0af4f205663dd2d" integrity sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag== +"@types/events@^3.0.0": + version "3.0.0" + resolved "https://registry.yarnpkg.com/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7" + integrity sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g== + "@types/fbemitter@*": version "2.0.32" resolved "https://registry.yarnpkg.com/@types/fbemitter/-/fbemitter-2.0.32.tgz#8ed204da0f54e9c8eaec31b1eec91e25132d082c" @@ -6580,11 +6585,12 @@ matrix-react-test-utils@^0.2.2: resolved "https://registry.yarnpkg.com/matrix-react-test-utils/-/matrix-react-test-utils-0.2.2.tgz#c87144d3b910c7edc544a6699d13c7c2bf02f853" integrity sha512-49+7gfV6smvBIVbeloql+37IeWMTD+fiywalwCqk8Dnz53zAFjKSltB3rmWHso1uecLtQEcPtCijfhzcLXAxTQ== -matrix-widget-api@^0.1.0-beta.10: - version "0.1.0-beta.10" - resolved "https://registry.yarnpkg.com/matrix-widget-api/-/matrix-widget-api-0.1.0-beta.10.tgz#2e4d658d90ff3152c5567089b4ddd21fb44ec1dd" - integrity sha512-yX2UURjM1zVp7snPiOFcH9+FDBdHfAdt5HEAyDUHGJ7w/F2zOtcK/y0dMlZ1+XhxY7Wv0IBZH0US8X/ioJRX1A== +matrix-widget-api@0.1.0-beta.11: + version "0.1.0-beta.11" + resolved "https://registry.yarnpkg.com/matrix-widget-api/-/matrix-widget-api-0.1.0-beta.11.tgz#3658e244bf82eebea36e64475ebfce86b778b476" + integrity sha512-RxIghopRKTQdmYMJzZg/QR+wcPcKe9S1pZZ31zN/M1LKsvTLThBYdMcP1idKh7MkhpO9eCdCVjJOMJTrqxNzbQ== dependencies: + "@types/events" "^3.0.0" events "^3.2.0" mdast-util-compact@^1.0.0: