Skip to content

Add handling short mentions tags to ExpensiMark - #824

Merged
puneetlath merged 3 commits into
Expensify:mainfrom
software-mansion-labs:kicu/38025-short-mentions
Feb 24, 2025
Merged

puneetlath merged 3 commits into
Expensify:mainfrom
software-mansion-labs:kicu/38025-short-mentions

Conversation

@Kicu

@Kicu Kicu commented Dec 21, 2024 •

Copy link
Copy Markdown
Contributor

Details

This is part of allowing to style and highlight short-mentions inside live-markdown when user is writing/editing their message. More details here: Expensify/App#38025 (comment)

The purpose of this PR is to add handling of (possible) short mention tags to ExpensiMark.
In this PR we define "short-mention" as anything after @ character that would be a valid email prefix.
Examples:

Why "possible" short mentions

The only way for us to actually render short-mentions inside react-native-live-markdown (and other code using ExpensiMark) is to somehow have the list of all possible user logins, and then checking whether the user typed mention matches any of them.

However such list should not and cannot be shared in any way to ExpensiMark, as this is just a simple parser. But we still need to some kind of output from ExpensiMark, to understand that there are mentions inside parsed text, so that we can later try and match them to user onyx data.

This creates some changes in how ExpensiMark interprets text, because something that in the past would be considered just normal text, might now be a short mention.

Example of parser output that changed (based on tests)

  • test@gmail.com@gmail.com
    • prev: <a href=\"mailto:test@gmail.com\">test@gmail.com</a>@gmail.com
    • now: <a href=\"mailto:test@gmail.com\">test@gmail.com</a><mention-short>@gmail.com</mention-short> - @gmail.com is a correct mention

In total I had to edit ~5 tests, all the other ones are passing correctly.

CC @puneetlath @tomekzaw @BartoszGrajdek

Fixed Issues

$ Expensify/App#38025

Tests

I made sure all existing unit tests pass, and added specific tests for short mentions

QA

  1. What does QA need to do to validate your changes?
  2. What areas to they need to test for regressions?

@github-actions

github-actions Bot commented Dec 21, 2024 •

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@Kicu

Kicu commented Dec 21, 2024

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@Kicu
Kicu force-pushed the kicu/38025-short-mentions branch from 275cc20 to c9e41a1 Compare December 30, 2024 09:44
CLABotify added a commit to Expensify/CLA that referenced this pull request Dec 30, 2024
@Kicu
Kicu force-pushed the kicu/38025-short-mentions branch from c9e41a1 to bb4cc97 Compare January 7, 2025 14:17
@Kicu
Kicu force-pushed the kicu/38025-short-mentions branch from e7b887c to 206d18c Compare January 8, 2025 12:59
@Kicu Kicu changed the title [WIP] Add handling possible short mentions tags to ExpensiMark Add handling possible short mentions tags to ExpensiMark Jan 8, 2025
@Kicu Kicu changed the title Add handling possible short mentions tags to ExpensiMark Add handling short mentions tags to ExpensiMark Jan 8, 2025
@Kicu
Kicu force-pushed the kicu/38025-short-mentions branch from 206d18c to f7e27c7 Compare January 8, 2025 13:13
@Kicu
Kicu marked this pull request as ready for review January 8, 2025 13:14
@Kicu
Kicu requested a review from a team as a code owner January 8, 2025 13:14
@melvin-bot
melvin-bot Bot requested review from arosiclair and removed request for a team January 8, 2025 13:14
@arosiclair
arosiclair requested review from puneetlath and thienlnam and removed request for arosiclair January 8, 2025 16:10
@shubham1206agra

Copy link
Copy Markdown

Commenting here for assignment.

Comment on lines 1671 to 1681
test('Test for email with test+1@gmail.com@gmail.com', () => {
const testString = 'test+1@gmail.com@gmail.com';
const resultString = '<a href="mailto:test+1@gmail.com">test+1@gmail.com</a>@gmail.com';
const resultString = '<a href="mailto:test+1@gmail.com">test+1@gmail.com</a><mention-short>@gmail.com</mention-short>';
expect(parser.replace(testString)).toBe(resultString);
});

test('Test for email with test@gmail.com@gmail.com', () => {
const testString = 'test@gmail.com@gmail.com';
const resultString = '<a href="mailto:test@gmail.com">test@gmail.com</a>@gmail.com';
const resultString = '<a href="mailto:test@gmail.com">test@gmail.com</a><mention-short>@gmail.com</mention-short>';
expect(parser.replace(testString)).toBe(resultString);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah indeed test+1@gmail.com@gmail.com looks like invalid email.
But I thought the reasoning was that the parser should treat it as a separate email (1st part) and then just text @gmail.com which now becomes a short mention.

Do you want me to change anything related to this?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No.

@shubham1206agra

shubham1206agra commented Jan 27, 2025 •

Copy link
Copy Markdown

@Kicu I was trying this PR along with Expensify/App#55509 and Expensify/App#54037. But RN Live Markdown does not seem to be highlighting short mentions. Is there some additional logic missing which I needed to make this work correctly?

@shubham1206agra

Copy link
Copy Markdown
Screenshot 2025-01-27 at 2 05 27 PM

@Kicu

Kicu commented Jan 28, 2025

Copy link
Copy Markdown
Contributor Author

hey @shubham1206agra I will take another look at this, because some time has passed and perhaps things broke.
I will provide a more detailed description of testing this in a few days.

I'm currently busy working on the bugs on navigation updates which take priority over this. Once navi (Expensify/App#49539) is in a better spot I will come back to this one.
Sorry for any confusion :)

CC @puneetlath

@Kicu

Kicu commented Feb 6, 2025

Copy link
Copy Markdown
Contributor Author

@shubham1206agra update with description how to test this here: Expensify/App#38025 (comment)

Comment thread lib/ExpensiMark.ts
Comment on lines +516 to +520
{
name: 'hereMentionAfterShortMentions',
regex: /(<\/mention-short>)(@here)(?=\b)/gm,
replacement: '$1<mention-here>$2</mention-here>',
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@Kicu Is this still needed? Since patch does not have this code and it works fine for me.

@Kicu Kicu Feb 21, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes I verified this is still needed.
Without it such string don't work: @mateusz.titz@here

It's a mistake I didn't add it to the patch, sorry.

Without this:
Screenshot 2025-02-21 at 14 31 37
With this:
Screenshot 2025-02-21 at 14 31 52

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

you should be able to test by yourself, you can just copy-paste this block and add it to the same file that patch modifies

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@Kicu One improvement note: Add some border radius so that we know these are separate mentions in RN Live Markdown.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Adding rounded borders is quite a complicated feature on which we are already working, and for now we cannot implement it for native, only for web.
Please refer to this issue: Expensify/App#56560 which adds it only for web.
And this an even older issue related to rounded corners: Expensify/App#19299

In short: for now we can have it only on web, and a colleague is working on this. So I won't be touching styles in this PR

@shubham1206agra

Copy link
Copy Markdown

@puneetlath All yours.

@puneetlath
puneetlath merged commit c73d705 into Expensify:main Feb 24, 2025
Comment thread lib/ExpensiMark.ts
name: 'shortMentions',

regex: new RegExp(
`${Constants.CONST.REG_EXP.PRE_MENTION_TEXT_PART}(@(?=((?=[\\w]+[\\w'#%+-]+(?:\\.[\\w'#%+-]+)*)[\\w\\.'#%+-]{1,64}(?= |_|\\b))(?!([:\\/\\\\]))(?<end>.*))(?!here)\\S{3,254}(?=\\k<end>$))(?!((?:(?!<a).)+)?<\\/a>|[^<]*(<\\/pre>|<\\/code>|<\\/mention-user>|<\\/mention-here>))`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This regex was causing at-mentions to not work when user's handle started with a single character then a dot, we fixed this in #881.

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.

4 participants