-
-
Notifications
You must be signed in to change notification settings - Fork 28
Fix Ban command renderer giving useless results. #1120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
@@ -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, | ||
|
|
@@ -37,6 +33,7 @@ import { | |
| DraupnirContextToCommandContextTranslator, | ||
| DraupnirInterfaceAdaptor, | ||
| } from "./DraupnirCommandPrerequisites"; | ||
| import { matrixToPermalinkFromClientUser } from "../utils"; | ||
| import { ResultError } from "@gnuxie/typescript-result"; | ||
|
|
||
| export async function findPolicyRoomEditorFromRoomReference( | ||
|
|
@@ -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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In that case, the problem just is simply that when rendering the suggestions to matrix we use the plain text renderer instead of the |
||
| }); | ||
| }, | ||
| } | ||
|
|
||
| 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 | ||
|
|
@@ -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"; | ||
|
|
@@ -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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should use the |
||
|
|
||
| /** | ||
| * 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly there is |
||
|
|
||
| export function setToArray<T>(set: Set<T>): T[] { | ||
| const arr: T[] = []; | ||
| for (const v of set) { | ||
|
|
||
| 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for this if you use matrix-basic-types mew |
||
There was a problem hiding this comment.
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?