Skip to content
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

Mentions shouldn't follow permalink_prefix #26002

Closed
gabrc52 opened this issue Aug 18, 2023 · 1 comment · Fixed by matrix-org/matrix-react-sdk#11726
Closed

Mentions shouldn't follow permalink_prefix #26002

gabrc52 opened this issue Aug 18, 2023 · 1 comment · Fixed by matrix-org/matrix-react-sdk#11726
Labels
A-Pills O-Uncommon Most users are unlikely to come across this or unexpected workflow S-Minor Impairs non-critical functionality or suitable workarounds exist T-Defect

Comments

@gabrc52
Copy link

gabrc52 commented Aug 18, 2023

Steps to reproduce

  1. Set permalink_prefix in config.json to the URL where your Element webapp is hosted.
  2. Mention someone in a room

Outcome

What did you expect?

Inline mentions should be Matrix URIs (i.e. matrix.to or matrix://) according to the spec

What happened instead?

The inline mention followed the URL format in permalink_prefix, which is problematic for several reasons:

mobile screenshot

Other clients (such as Element-Android or other Element-Web instances) render these mentions as links instead of proper pilled mentions. Most users on federated rooms are on a different homeserver and use a different config.json if not a different Matrix client.

In addition, config.md says the following about permalink_prefix:

permalink_prefix: An optional URL pointing to an Element Web deployment. For example, https://app.element.io. This will change all permalinks (via the "Share" menus) to point at the Element Web deployment rather than matrix.to.

When using the share button, permalink_prefix should be used to generate links, but not when pinging people, since these aren't permalinks and are in theory just fallback links for clients which don't know how to render mentions.

Other than spec compliance, this breaks bridges, since bridges only deal with inline mentions as stated in the spec. Trying to ping a bridged user would send a link to the Element web instance instead, so it would be unsuccessful at getting their attention and make it unnecessarily obvious that the person on the other side is using a Matrix bridge.

Operating system

No response

Browser information

No response

URL for webapp

No response

Application version

Element version: 1.11.45

Homeserver

No response

Will you send logs?

No

@gabrc52
Copy link
Author

gabrc52 commented Aug 19, 2023

Trying to give it a shot at fixing.

First attempt, no effect:
diff --git a/src/autocomplete/UserProvider.tsx b/src/autocomplete/UserProvider.tsx
index a934e9309a..a41b6ccbae 100644
--- a/src/autocomplete/UserProvider.tsx
+++ b/src/autocomplete/UserProvider.tsx
@@ -132,7 +132,7 @@ export default class UserProvider extends AutocompleteProvider {
                     completionId: user.userId,
                     type: "user",
                     suffix: selection.beginning && range!.start === 0 ? ": " : " ",
-                    href: makeUserPermalink(user.userId),
+                    href: makeUserPermalink(user.userId, true),
                     component: (
                         <PillCompletion title={displayName} description={description}>
                             <MemberAvatar member={user} width={24} height={24} />
diff --git a/src/utils/permalinks/Permalinks.ts b/src/utils/permalinks/Permalinks.ts
index 1a55b8408e..2629996d0c 100644
--- a/src/utils/permalinks/Permalinks.ts
+++ b/src/utils/permalinks/Permalinks.ts
@@ -273,8 +273,8 @@ export function makeGenericPermalink(entityId: string): string {
     return getPermalinkConstructor().forEntity(entityId);
 }
 
-export function makeUserPermalink(userId: string): string {
-    return getPermalinkConstructor().forUser(userId);
+export function makeUserPermalink(userId: string, isMention: boolean = false): string {
+    return getPermalinkConstructor(isMention).forUser(userId);
 }
 
 export function makeRoomPermalink(matrixClient: MatrixClient, roomId: string): string {
@@ -409,9 +409,9 @@ export function getPrimaryPermalinkEntity(permalink: string): string | null {
     return null;
 }
 
-function getPermalinkConstructor(): PermalinkConstructor {
+function getPermalinkConstructor(forceMatrixTo: boolean = false): PermalinkConstructor {
     const elementPrefix = SdkConfig.get("permalink_prefix");
-    if (elementPrefix && elementPrefix !== matrixtoBaseUrl) {
+    if (!forceMatrixTo && elementPrefix && elementPrefix !== matrixtoBaseUrl) {
         return new ElementPermalinkConstructor(elementPrefix);
     }

@weeman1337 weeman1337 added S-Minor Impairs non-critical functionality or suitable workarounds exist O-Uncommon Most users are unlikely to come across this or unexpected workflow A-Pills labels Aug 22, 2023
herkulessi pushed a commit to herkulessi/matrix-react-sdk that referenced this issue Oct 3, 2023
fixes element-hq/element-web/issues/26002

During serialization of messages, pills were wrongfully serialized to a URL
starting with `permalink_prefix`. This is against the Spec (which mandates
https://matrix.to/#/ links) and the resulting pills were not recognized as
pills in other clients.

[Spec-Appendendix concerning matrix.to link](https://spec.matrix.org/v1.8/appendices/#matrixto-navigation)
herkulessi pushed a commit to herkulessi/matrix-react-sdk that referenced this issue Oct 3, 2023
fixes element-hq/element-web/issues/26002

During serialization of messages, pills were wrongfully serialized to a URL
starting with `permalink_prefix`. This is against the Spec (which mandates
https://matrix.to/#/ links) and the resulting pills were not recognized as
pills in other clients.

Spec-Appendix concerning matrix.to links: https://spec.matrix.org/v1.8/appendices/#matrixto-navigation
herkulessi pushed a commit to herkulessi/matrix-react-sdk that referenced this issue Oct 9, 2023
fixes element-hq/element-web/issues/26002

During serialization of messages, pills were wrongfully serialized to a URL
starting with `permalink_prefix`. This is against the Spec (which mandates
https://matrix.to/#/ links) and the resulting pills were not recognized as
pills in other clients.

Spec-Appendix concerning matrix.to links: https://spec.matrix.org/v1.8/appendices/#matrixto-navigation

Signed-off-by: Lars Wickel <git@herkulessi.de>
herkulessi pushed a commit to herkulessi/matrix-react-sdk that referenced this issue Jun 8, 2024
fixes element-hq/element-web/issues/26002

During serialization of messages, pills were wrongfully serialized to a URL
starting with `permalink_prefix`. This is against the Spec (which mandates
https://matrix.to/#/ links) and the resulting pills were not recognized as
pills in other clients.

Spec-Appendix concerning matrix.to links: https://spec.matrix.org/v1.8/appendices/#matrixto-navigation

Signed-off-by: Lars Wickel <git@herkulessi.de>
github-merge-queue bot pushed a commit to matrix-org/matrix-react-sdk that referenced this issue Aug 1, 2024
* Ignore permalink_prefix when serializing Markdown

fixes element-hq/element-web/issues/26002

During serialization of messages, pills were wrongfully serialized to a URL
starting with `permalink_prefix`. This is against the Spec (which mandates
https://matrix.to/#/ links) and the resulting pills were not recognized as
pills in other clients.

Spec-Appendix concerning matrix.to links: https://spec.matrix.org/v1.8/appendices/#matrixto-navigation

Signed-off-by: Lars Wickel <git@herkulessi.de>

* Test for pill serialization with permalink_prefix set

Signed-off-by: Lars Wickel <git@herkulessi.de>

* Test that permalink_prefix is used for permalink creation

Signed-off-by: Lars Wickel <git@herkulessi.de>

* Fix lint issues introduced

Signed-off-by: Lars Wickel <git@herkulessi.de>

* Incorporate requested changes

Signed-off-by: Lars Wickel <git@herkulessi.de>

---------

Signed-off-by: Lars Wickel <git@herkulessi.de>
Co-authored-by: herkulessi <git@herkulessi.de>
Co-authored-by: David Baker <dbkr@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Pills O-Uncommon Most users are unlikely to come across this or unexpected workflow S-Minor Impairs non-critical functionality or suitable workarounds exist T-Defect
Projects
None yet
2 participants