Page MenuHomePhabricator

[lib] Introduce chat mention match and parse utilities

Authored by patryk on Aug 16 2023, 5:10 AM.
Referenced Files
Unknown Object (File)
Sat, Sep 16, 12:44 PM
Unknown Object (File)
Wed, Sep 6, 10:56 AM
Unknown Object (File)
Mon, Sep 4, 6:44 AM
Unknown Object (File)
Mon, Sep 4, 1:49 AM
Unknown Object (File)
Sun, Sep 3, 8:35 AM
Unknown Object (File)
Thu, Aug 31, 7:03 PM
Unknown Object (File)
Wed, Aug 30, 3:10 PM
Unknown Object (File)
Wed, Aug 30, 8:08 AM



Solution for ENG-4557.

This diff introduces decoding utilities which are going to be used in rules.react.js files both on web and native.

Depends on D8833.

Test Plan

Tested later in the stack.

Diff Detail

rCOMM Comm
No Lint Coverage
No Test Coverage

Event Timeline

patryk held this revision as a draft.

Add unescapeClosingSquareBrackets function

Introduce encoding and decoding utility functions

Remove encodeChatMentionText

patryk edited the test plan for this revision. (Show Details)
patryk added reviewers: tomek, inka, rohan.
patryk edited the test plan for this revision. (Show Details)

What if thread name contains escaped characters? Are these characters escaped on render? Example: Chat \name \\

No, these characters are not escaped on render. The only character which is going to be escaped is ], because there might be a chat name like this: Chat name ]] ]] and regex would not include all of closing brackets (that's why we need decodeChatMentionText and encodeChatMentionText, so when user clicks a chat in typeahead tooltip, before raw chat mention is saved, all ] characters are escaped (\])).

226 ↗(On Diff #30070)

Regex explanation:

  • (?<!\\\\) - Negative lookbehind assertion. It asserts that what precedes the current position in the string is not a backslash (\). This is used to ensure that there is no escaping backslash before the @ symbol.
  • (@\\[\\[([0-9,|]+):(${validChatNameRegexString}?)(?<!\\\\)\\]\\]) - Main part of the regex. Inner negative lookbehind makes sure that if the user escapes ] character, whole expression is not matched. For example this expression would not match: @[[123:test\]].
229–231 ↗(On Diff #30070)

Soon I will introduce encodeChatMentionText which will encode all ] in chat mention text when chat candidate is clicked in typeahead tooltip.

patryk published this revision for review.Aug 20 2023, 11:11 PM

Move regex and decode function to mention-utils.js

Match/parse seems good, just one comment inline that I won't block this diff on.

Could you also maybe add some unit tests for the regex in markdown.test.js alongside this diff since it's pretty difficult to review? They don't need to be super complicated but since the regex itself is pretty hard to understand, it'd be a good way to make sure all cases are accounted for

229–237 ↗(On Diff #30132)

For a relatively simple case like this, we could probably just handle it like the other simple cases directly in web/markdown/rules.react.js and native/markdown/rules.react.js using the SimpleMarkdown.inlineRegex(SharedMarkdown.chatMentionRegex) method

Going to cc @ashoat though since this was feedback he gave to me in D5346 and I'm not sure if it's worth blocking this diff for

This revision is now accepted and ready to land.Aug 21 2023, 5:32 PM
229–237 ↗(On Diff #30132)

Ah yeah, good call there – I agree

Change id detection regex

inka requested changes to this revision.Wed, Sep 6, 2:37 AM
inka added inline comments.

I don't think you want it to always be at the beginning of the line?
If I'm right please amend D9057 to test for a mention indie of a message

This revision now requires changes to proceed.Wed, Sep 6, 2:37 AM

Not sure if this is relevant, but simple-markdown always parses RegExps at the "start of the line". It process tokens at the start of the text, and then removes those tokens before processing the new set of tokens


@ashoat comment explains why this regex is checking if mention is at the beginning of the line. D9005 modifies chatMentionRegexString and removes ^. We do sth similar for user mentions, see markdownUserMentionRegex. I can rename chatMentionRegex to markdownChatMentionRegex to distinguish "global" chat mention regex from markdown regex.

This revision is now accepted and ready to land.Fri, Sep 22, 6:25 AM