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**
This commit is contained in:
Travis Ralston 2020-12-29 12:35:48 -07:00
parent 461b569278
commit 7e0cf5c783
5 changed files with 23 additions and 0 deletions

View file

@ -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",

View file

@ -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

View file

@ -15,5 +15,8 @@
*/
export enum ElementWidgetCapabilities {
/**
* @deprecated Use MSC2931 instead.
*/
CanChangeViewedRoom = "io.element.view_room",
}

View file

@ -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<void> {
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
}
}

View file

@ -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 = {