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

Use localpart in plaintext so we get highlighted for pills #658

Merged
merged 23 commits into from
Aug 23, 2018

Conversation

Half-Shot
Copy link
Contributor

@Half-Shot Half-Shot commented Aug 22, 2018

This PR has a soft dependency on matrix-org/matrix-appservice-bridge#83, where we will only cache if the bridge-sdk is setup to do so. Otherwise, we won't.

@Half-Shot Half-Shot requested a review from a team August 22, 2018 17:58
@@ -64,10 +64,18 @@ MatrixAction.prototype.formatMentions = function(nickUserIdMap) {
this.htmlText = this.text;
}
userId = ircFormatting.escapeHtmlChars(userId);
/* Due to how Riot and friends do push notifications, we need the plain text to match something.
Modern client's will pill-ify and will show a displayname, so we can use the localpart so it
matches and doesn't degrade too badly on limited clients.*/
Copy link
Member

Choose a reason for hiding this comment

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

minor: double space after matches

/* Due to how Riot and friends do push notifications, we need the plain text to match something.
Modern client's will pill-ify and will show a displayname, so we can use the localpart so it
matches and doesn't degrade too badly on limited clients.*/
const localpart = userId.substr(1, userId.indexOf(":")-1);
Copy link
Member

Choose a reason for hiding this comment

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

we should be using the display name, as per matrix-org/matrix-spec-proposals#1547

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You really want to do a displayname lookup for every match? The localparts already match.

Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer it if the cached display name was used, given we already know about the member event.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think we do know about the mem...OH you mean the member cache thingatron?

@Half-Shot
Copy link
Contributor Author

Half-Shot commented Aug 22, 2018

Continuing on #658 (comment)

We don't store displaynames in the membership we don't even store membership for non-virtual users because we don't really care about them, we could do a profile fetch on mention though and keep our own cache?

@turt2live
Copy link
Member

We already pull members out of the room for the purpose of figuring out mentions. Including partial profiles for those users doesn't seem terribly bad.

If we cache miss on the display name, fall back to the complete user ID, not localpart.

@Half-Shot
Copy link
Contributor Author

We already pull members out of the room for the purpose of figuring out mentions

We don't? We could, but we don't currently.

Copy link
Member

@turt2live turt2live left a comment

Choose a reason for hiding this comment

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

otherwise lgtm


const regex = MentionRegex(escapeStringRegexp(matchName));
this.htmlText = this.htmlText.replace(regex,
`$1<a href="https://matrix.to/#/${userId}">${ircFormatting.escapeHtmlChars(identifier)}</a>`
Copy link
Member

Choose a reason for hiding this comment

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

this should be indented

});
expect(action.text).toEqual("Go to http://JCDenton.com");
expect(action.htmlText).toEqual(
"Go to <a href='http://JCDenton.com'>my website</a>"
);
Copy link
Member

Choose a reason for hiding this comment

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

a test for making sure it also actually uses the profile where possible would be nice

@turt2live turt2live removed their assignment Aug 23, 2018
@Half-Shot Half-Shot merged commit 4789667 into develop Aug 23, 2018
@Half-Shot Half-Shot deleted the hs/mentions-use-displaynames branch August 23, 2018 18:24
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