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

Canonical alias #174

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Canonical alias #174

wants to merge 2 commits into from

Conversation

aofn
Copy link
Member

@aofn aofn commented Jun 20, 2022

Add canonical alias when publishing an item.
As of now it looks like this is needed to be able to join a space from a different server.

@aofn aofn marked this pull request as draft June 20, 2022 09:16
// as of now spaces need a canonical alias and be listed in the room direcotry in order to be joinable via federation
// we create the alias with the title of the item seperated by dashes and in lower case.
// @TODO sanitise for special characters which might be allowed in room name but not for the alias
const alias = '#' + space.name.replace(/\s+/g, '-').toLowerCase() + '-' + localStorage.getItem('mx_user_id').substring(1)
Copy link
Member

Choose a reason for hiding this comment

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

Should we also add a random 4-digit number or so in case someone adds two content items with the very same name?

if (config.medienhaus.createCanonicalAliasOnPublish) {
// as of now spaces need a canonical alias and be listed in the room direcotry in order to be joinable via federation
// we create the alias with the title of the item seperated by dashes and in lower case.
// @TODO sanitise for special characters which might be allowed in room name but not for the alias
Copy link
Member

Choose a reason for hiding this comment

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

I think lodash's kebabCase() would help here:
image

if (config.medienhaus.createCanonicalAliasOnPublish) {
await matrixClient.setRoomDirectoryVisibility(roomId, 'private')
.catch(console.debug)
await matrixClient.deleteAlias('#' + space.rooms[0].name.replace(/\s+/g, '-').toLowerCase() + '-' + localStorage.getItem('mx_user_id').substring(1))
Copy link
Member

Choose a reason for hiding this comment

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

-If- we ever decide to change the "algorithm" how we generate those aliases, the code wouldn't work for projects anymore, that were created with the "old syntax".

Instead maybe we can make use of the unstableGetLocalAliases function, and then just delete all aliases for the given room at once:
image

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

Successfully merging this pull request may close these issues.

2 participants