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

Add support for room aliases #107

Merged
merged 9 commits into from
Oct 27, 2022

Conversation

MadLittleMods
Copy link
Contributor

@MadLittleMods MadLittleMods commented Oct 24, 2022

Add support for room aliases. Also does friendly redirects if you don't exactly use the right URL pattern. For example, if you paste the full room ID with the ! like /roomid/!foo:bar, it will properly redirect you to /roomid/foo:bar. It also does this sort of thing for URL encoded room ID's and aliases.

Fix #25

[...] we can use a schemaless Matrix URI (matrix://) which doesn't include the sigils so there is no URL encoding issue.

The URL's for the archive end up looking like:

  • Room alias: /r/matrix:matrix.org/date/2022/06/28
  • Room ID: /roomid/OGEhHVWSdvArJzumhm:matrix.org/date/2022/06/28

Todo

  • Update links on room directory to reflect alias usage now
  • Add client-side redirects when someone just pastes a room alias on the end of the domain
  • If someone visits via /roomid/..., we shouldn't switch them over to room alias or vice versa
  • Add tests for visiting room by room ID or room alias
  • Add tests for room ID honest mistake redirects:
    • /roomid/!HBehERstyQBxyJDLfR:my.synapse.server -> /roomid/HBehERstyQBxyJDLfR:my.synapse.server
    • /roomid/!HBehERstyQBxyJDLfR:my.synapse.server/date/2022/09/20?via=my.synapse.server -> /roomid/HBehERstyQBxyJDLfR:my.synapse.server/date/2022/09/20?via=my.synapse.server
    • /!HBehERstyQBxyJDLfR:my.synapse.server -> /roomid/HBehERstyQBxyJDLfR:my.synapse.server
    • We can't test room alias honest mistakes because those redirects happen client-side
  • Test with URI encoded values %23test-room1%3Amy.synapse.server, !HBehERstyQBxyJDLfR%3Amy.synapse.server

Dev notes

const nowDate = new Date();

// Warn if it's close to the end of the UTC day. This test could be a flakey
// and cause a failure if the room was created just before midnight (UTC) and
// this timestamp comes after midnight. The redirect would want to go to the
// day before when the latest event was created instead of the `nowDate` we
// expected in the URL's.
//
// We could lookup the date of the latest event to use the `origin_server_ts`
// from ourselves which may be less faff than this big warning but 🤷
const utcMidnightOfNowDay = Date.UTC(
  nowDate.getUTCFullYear(),
  nowDate.getUTCMonth(),
  nowDate.getUTCDate() + 1
);
if (utcMidnightOfNowDay - nowDate.getTime() < 30 * 1000 /* 30 seconds */) {
  // eslint-disable-next-line no-console
  console.warn(
    `Test is being run at the end of the UTC day. This could result in a flakey ` +
      `failure where the room was created before midnight (UTC) but the \`nowDate\` ` +
      `was after midnight meaning our expected URL's would be a day ahead. Since ` +
      `this is an e2e test we can't control the date/time exactly.`
  );
}

@MadLittleMods MadLittleMods added the T-Enhancement New feature or request label Oct 24, 2022
@MadLittleMods MadLittleMods marked this pull request as ready for review October 27, 2022 06:05
@MadLittleMods MadLittleMods merged commit 7a88ea0 into main Oct 27, 2022
MadLittleMods added a commit that referenced this pull request Oct 27, 2022
MadLittleMods added a commit that referenced this pull request Oct 28, 2022
…ect URL (#111)

This helps when someone just pastes a room alias on the end of the domain,

 - `/#room-alias:server` -> `/r/room-alias:server`
 - `/r/#room-alias:server/date/2022/10/27` -> `/r/room-alias:server/date/2022/10/27`

Since these redirects happen on the client, we can't write any e2e tests. Those e2e tests do everything but run client-side JavaScript.

Follow-up to #107

Part of #25
@MadLittleMods MadLittleMods deleted the madlittlemods/25-add-support-for-room-aliases branch April 26, 2023 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for room aliases
1 participant