Open linkified room aliases and permalinks in the app rather than the browser (#34507)
This commit is contained in:
@@ -9,7 +9,6 @@ import React, { type MouseEvent } from "react";
|
|||||||
import { MatrixEventEvent, MsgType, type MatrixEvent } from "matrix-js-sdk/src/matrix";
|
import { MatrixEventEvent, MsgType, type MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||||
import {
|
import {
|
||||||
BaseViewModel,
|
BaseViewModel,
|
||||||
LINKIFIED_DATA_ATTRIBUTE,
|
|
||||||
TextualBodyViewBodyWrapperKind,
|
TextualBodyViewBodyWrapperKind,
|
||||||
TextualBodyViewKind,
|
TextualBodyViewKind,
|
||||||
type TextualBodyViewModel as TextualBodyViewModelInterface,
|
type TextualBodyViewModel as TextualBodyViewModelInterface,
|
||||||
@@ -278,10 +277,6 @@ export class TextualBodyViewModel
|
|||||||
public onRootClick = (event: MouseEvent<HTMLDivElement>): void => {
|
public onRootClick = (event: MouseEvent<HTMLDivElement>): void => {
|
||||||
let target: HTMLLinkElement | null = event.target as HTMLLinkElement;
|
let target: HTMLLinkElement | null = event.target as HTMLLinkElement;
|
||||||
|
|
||||||
if (target.dataset?.[LINKIFIED_DATA_ATTRIBUTE]) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (target.nodeName !== "A") {
|
if (target.nodeName !== "A") {
|
||||||
target = target.closest<HTMLLinkElement>("a");
|
target = target.closest<HTMLLinkElement>("a");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -213,10 +213,29 @@ describe("TextualBodyViewModel", () => {
|
|||||||
).toThrow("TextualBodyViewModel should only render pending moderation for hidden messages");
|
).toThrow("TextualBodyViewModel should only render pending moderation for hidden messages");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("ignores linkified root clicks", () => {
|
it("rewrites linkified permalink clicks to local hashes", () => {
|
||||||
|
const vm = createVm();
|
||||||
|
const preventDefault = jest.fn();
|
||||||
|
jest.spyOn(permalinkUtils, "tryTransformPermalinkToLocalHref").mockReturnValue("#/room/#room:example.org");
|
||||||
|
|
||||||
|
vm.onRootClick({
|
||||||
|
preventDefault,
|
||||||
|
target: {
|
||||||
|
dataset: {
|
||||||
|
[LINKIFIED_DATA_ATTRIBUTE]: "true",
|
||||||
|
},
|
||||||
|
href: "https://matrix.to/#/#room:example.org",
|
||||||
|
nodeName: "A",
|
||||||
|
},
|
||||||
|
} as any);
|
||||||
|
|
||||||
|
expect(preventDefault).toHaveBeenCalled();
|
||||||
|
expect(window.location.hash).toBe("#/room/#room:example.org");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("leaves linkified ordinary links alone", () => {
|
||||||
const vm = createVm();
|
const vm = createVm();
|
||||||
const preventDefault = jest.fn();
|
const preventDefault = jest.fn();
|
||||||
const transformSpy = jest.spyOn(permalinkUtils, "tryTransformPermalinkToLocalHref");
|
|
||||||
|
|
||||||
vm.onRootClick({
|
vm.onRootClick({
|
||||||
preventDefault,
|
preventDefault,
|
||||||
@@ -229,8 +248,8 @@ describe("TextualBodyViewModel", () => {
|
|||||||
},
|
},
|
||||||
} as any);
|
} as any);
|
||||||
|
|
||||||
expect(transformSpy).not.toHaveBeenCalled();
|
|
||||||
expect(preventDefault).not.toHaveBeenCalled();
|
expect(preventDefault).not.toHaveBeenCalled();
|
||||||
|
expect(window.location.hash).toBe("");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("rewrites permalink clicks to local hashes", () => {
|
it("rewrites permalink clicks to local hashes", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user