Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions apps/draupnir/src/commands/Ban.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2022 - 2025 Gnuxie <Gnuxie@protonmail.com>
// SPDX-FileCopyrightText: 2026 Catalan Lover <catalanlover@protonmail.com>
// Copyright 2019 - 2021 The Matrix.org Foundation C.I.C.
//
// SPDX-License-Identifier: Apache-2.0
Expand All @@ -18,14 +19,9 @@ import {
RoomResolver,
WatchedPolicyRooms,
} from "matrix-protection-suite";
import {
MatrixRoomReference,
MatrixUserID,
StringUserID,
} from "@the-draupnir-project/matrix-basic-types";
import { MatrixRoomReference, MatrixUserID, StringUserID } from "@the-draupnir-project/matrix-basic-types";
import {
BasicInvocationInformation,
MatrixRoomIDPresentationType,
MatrixRoomReferencePresentationSchema,
MatrixUserIDPresentationType,
StringPresentationType,
Expand All @@ -37,6 +33,7 @@ import {
DraupnirContextToCommandContextTranslator,
DraupnirInterfaceAdaptor,
} from "./DraupnirCommandPrerequisites";
import { matrixToPermalinkFromClientUser } from "../utils";
import { ResultError } from "@gnuxie/typescript-result";

export async function findPolicyRoomEditorFromRoomReference(
Expand Down Expand Up @@ -85,7 +82,11 @@ export const DraupnirBanCommand = describeCommand({
return Ok({
suggestions: policyRoomManager
.getEditablePolicyRoomIDs(clientUserID, PolicyRuleType.User)
.map((room) => MatrixRoomIDPresentationType.wrap(room)),
.map((room) =>
StringPresentationType.wrap(
matrixToPermalinkFromClientUser(room.toRoomIDOrAlias(), clientUserID)
)
),
Comment on lines -88 to +89

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use room.toPermalink() i think?

Comment on lines -88 to +89

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this is a good idea. Some clients will show this as a pill yes, But the presentation renderer for MatrixRoomID should really be fixed if it isn't forming pills that clients like.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isnt forming ANYTHING. its spitting bare room IDs and thats it. This PR improves that by spitting bare matrix.to links something clients atleast handle. Atleast Element Web does.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isnt forming ANYTHING. its spitting bare room IDs and thats it. This PR improves that by spitting bare matrix.to links something clients atleast handle. Atleast Element Web does.

In that case, the problem just is simply that when rendering the suggestions to matrix we use the plain text renderer instead of the DeadDocument one

});
},
}
Expand Down
24 changes: 24 additions & 0 deletions apps/draupnir/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2022 Gnuxie <Gnuxie@protonmail.com>
// SPDX-FileCopyrightText: 2026 Catalan Lover <catalanlover@protonmail.com>
// Copyright 2019 - 2021 The Matrix.org Foundation C.I.C.
//
// SPDX-License-Identifier: Apache-2.0
Expand All @@ -16,6 +17,7 @@ import {
setRequestFn,
MatrixError,
} from "@vector-im/matrix-bot-sdk";
import { StringUserID, userServerName } from "@the-draupnir-project/matrix-basic-types";
import { ClientRequest, IncomingMessage } from "http";
import * as Sentry from "@sentry/node";
import ManagementRoomOutput from "./managementroom/ManagementRoomOutput";
Expand All @@ -31,6 +33,28 @@ export function htmlEscape(input: string): string {
return input.replace(/[<&"']/g, (c) => "&#" + c.charCodeAt(0) + ";");
}

/**
* Build a matrix.to permalink for a room id or alias using a single via server.
* Example: https://matrix.to/#/%21room%3Aexample.com?via=example.com
*/
export function matrixToPermalink(roomIdOrAlias: string, viaServer: string): string {
return `https://matrix.to/#/${encodeURIComponent(roomIdOrAlias)}?via=${encodeURIComponent(
viaServer
)}`;
}
Comment on lines +40 to +44

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use the MatrixRoomID, MatrixRoomAlias or Permalinks utilities from matrix-basic-types for this.


/**
* Build a matrix.to permalink for a room id or alias using the bot's homeserver derived
* from the provided client MXID.
*/
export function matrixToPermalinkFromClientUser(
roomIdOrAlias: string,
clientUserID: StringUserID
): string {
const via = userServerName(clientUserID);
return matrixToPermalink(roomIdOrAlias, via);
}
Comment on lines +46 to +56

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly there is MatrixUserID and Permalinks


export function setToArray<T>(set: Set<T>): T[] {
const arr: T[] = [];
for (const v of set) {
Expand Down
18 changes: 18 additions & 0 deletions apps/draupnir/test/unit/utils/matrixToPermalink.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-FileCopyrightText: 2026 Catalan Lover <catalanlover@protonmail.com>
// SPDX-License-Identifier: Apache-2.0

import expect from "expect";
import { matrixToPermalink } from "../../../src/utils";

describe("matrixToPermalink", function () {
it("builds a matrix.to link with a single via", function () {
const room = "!wJbHKdEdDUKQRGGImO:feline.support";
const via = "feline.support";
const result = matrixToPermalink(room, via);
expect(result).toBe(
`https://matrix.to/#/${encodeURIComponent(room)}?via=${encodeURIComponent(
via
)}`
);
});
});
Comment on lines +4 to +18

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this if you use matrix-basic-types mew

Loading