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

Decorate matrix.to anchor tags as mx_UserPill and mx_RoomPill #1227

Merged
merged 3 commits into from
Jul 19, 2017

Conversation

lukebarnard1
Copy link
Contributor

@lukebarnard1 lukebarnard1 commented Jul 17, 2017

Requires element-hq/element-web#4597 to look OK

Luke Barnard added 2 commits July 17, 2017 14:27
These have since been replaced by decorators that operator whether in MD mode or otherwise. This might not be optimal because LINK entities do not appear in MD mode at all at the moment, but instead you see the ()[] md notation version.
@lukebarnard1 lukebarnard1 changed the title Luke/feature matrixto timeline pills Decorate matrix.to anchor tags as mx_UserPill and mx_RoomPill Jul 17, 2017
if (node.tagName === "A" && node.getAttribute("href")) {
const href = node.getAttribute("href");
// HtmlUtils transforms `matrix.to` links to local links, so match against
// user or room app links.
Copy link
Member

Choose a reason for hiding this comment

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

Well, it looks like your code is right, although I'm failing to find where this happens. It probably should not, and leave the href as matrix.to but override the onclick like we do with permalinks and linkified users / rooms.

Copy link
Member

Choose a reason for hiding this comment

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

oh, transformTags

const href = node.getAttribute("href");
// HtmlUtils transforms `matrix.to` links to local links, so match against
// user or room app links.
const match = /^#\/(user|room)\/(.*)$/.exec(href);
Copy link
Member

Choose a reason for hiding this comment

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

When doing this it's quite nice to expand out the matches into named variables and refer to those, which I think makes the code a bit easier to understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Weird that I did this with the other PR and not this one..

room = match[2][0] === '#' ?
MatrixClientPeg.get().getRooms().find((r) => {
return r.getCanonicalAlias() === match[2];
}) : MatrixClientPeg.get().getRoom(match[2]);
Copy link
Member

Choose a reason for hiding this comment

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

Non-canonical aliases should surely work too? This will probably involve a server round-trip to look up the alias though :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As a first cut I guess this isn't too bad? The RTE does it this way so I suppose it'd be best to factor this out and then do all the async stuff? Likewise for hitting /profile for getting user avatars etc.?

@dbkr dbkr assigned lukebarnard1 and unassigned dbkr Jul 17, 2017
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

lgtm

@lukebarnard1 lukebarnard1 merged commit d179398 into develop Jul 19, 2017
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.

3 participants