Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Support local permalinks for unfederated instances #3500

Merged
merged 21 commits into from
Oct 1, 2019

Conversation

turt2live
Copy link
Member

@turt2live turt2live commented Oct 1, 2019

Fixes element-hq/element-web#8149

Reviewer: This is a complicated changeset (sorry). My best suggestion is for the code to be reviewed commit by commit, and to bear in mind that a concern you have early in the review process may be solved later in a later commit (there's at least 3 rounds of refactoring done throughout the commits).

Also there's a brain dump of information below which might be useful. Or not. You're welcome.

There's no screenshots because there's no visual changes here. A bunch of testing information is included at the end of the description if you're interested though.


This exposes a new config option (documented here: element-hq/element-web#11007) to allow self-hosted instances of Riot to use local URLs instead of matrix.to for permalinks. This is primarily intended for instances which aren't federated, as matrix.to is unlikely to work or be happy. This may cause incompatibility with the mobile apps due to the potential for random web servers to be hosting "permalinks" (ie: mobile will have no idea what to do with https://riot.custom.example.org/#/room/!example:example.org).

This is strictly not intended for use on riot.im/app or /develop (etc) or any other federated instance.


Code overview (because it's complicated)

There's two types of permalinks we support: Spec (matrix.to) and Riot (whatever you've configured that as). These are represented by their own respective PermalinkConstructor classes (with PermalinkConstructor itself being a stub for a future TypeScript interface). These classes have all the meat in them for handling permalinks, and Permalinks.js (RoomPermalinkCreator) just forwards it's request for permalink stuff over to the appropriate PermalinkConstructor. This lends itself to a potential third permalink type, if we're ever crazy enough to do that, as well as easier maintenance on our existing permalink types.

Previously we just had a bunch of regular expressions laying around and executed those when we needed to, making the change to support Riot permalinks harder. This has now been centralized into the Permalinks class as parsePermalink.

All told, the changes aren't that complex when looking at the stuff from a high level point of view. They get complicated with the parsing and usage pattern of the new system, particularly when compared to the old way of doing things.


Testing (for future adventurers in this area)

As of writing, the major test cases to cover when changing how permalinks are:

  • Timestamps next to messages have the right href
  • Clicking timestamps next to messages works (activates permalink)
  • Opening the share dialog for a message has the right permalink URL
    • Copying it to the clipboard copies the right thing
    • QR code and share buttons also use the right thing
  • Receiving a plain (non-pill) link with matrix.to has a rewritten href, and works
  • Receiving a permalink to riot.im/app has a rewritten href, and works
  • Receiving a pill has a rewritten href, and works
  • Autocompleting a user/room/group creates a pill (if you don't get a pill, it's probably broken)
  • Autocompleting a user/room/group pill and sending the message hardcodes the right permalink
  • Sharing a link to a user uses the right URL
  • Sharing a link to a room uses the right URL
  • Sharing a link to a group uses the right URL
  • Typing /goto https://matrix.to/... works as expected
  • Typing /goto <custom permalink> works as expected
  • Clicking timestamps in the FilePanel works as expected
  • Usernames with only emoji are not made BigEmoji when pinged
  • The tests pass

The manual tests may also need to be repeated for the Desktop app.

Just a little bit of refactoring to make the feature of custom prefixes a bit easier.
This allows for Riot permalinks to be introduced without if-else ladders everywhere.
Without the requirement for a room to work
Originally we were planning on using the current location as the permalink prefix, but that doesn't work if the user is a desktop user.
Also adds some safety around the Riot URL to ensure it mostly looks like a URL
They might not be matrix.to anymore, so parse them more correctly.
Now that permalinks could be not-matrix.to we should be safer in what we'll allow.
The file handles more than just a RoomPermalinkCreator, so we should name it accordingly.
@turt2live turt2live requested a review from a team October 1, 2019 03:21
@dbkr dbkr requested review from dbkr and removed request for a team October 1, 2019 14:12
Copy link
Member

@dbkr dbkr left a comment

Choose a reason for hiding this comment

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

This also looks much better in terms of general code hygiene and keeping all the permalink stuff in one place rather than scattered over the SDK - thanks!

@turt2live turt2live merged commit 7d1a04c into develop Oct 1, 2019
@turt2live turt2live deleted the travis/permalinks branch October 1, 2019 14:41
@martindale
Copy link

🙌

@BloodyIron
Copy link

Woot! :D This should also address an earlier #7659

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

matrix.to permalinks don't work for self-hosted instance
4 participants