Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/chilly-spoons-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"draupnir": patch
---

Make Room IDs in prompts issued by the ban command into matrix.to links
12 changes: 10 additions & 2 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 @@ -25,7 +26,6 @@ import {
} from "@the-draupnir-project/matrix-basic-types";
import {
BasicInvocationInformation,
MatrixRoomIDPresentationType,
MatrixRoomReferencePresentationSchema,
MatrixUserIDPresentationType,
StringPresentationType,
Expand All @@ -37,6 +37,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 +86,14 @@ 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
)
)
),
});
},
}
Expand Down
30 changes: 30 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,10 @@ 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 +36,31 @@ 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
)}`;
}

/**
* 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