Page MenuHomePhabricator

[native] Use chat mention candidates in markdown rules
ClosedPublic

Authored by patryk on Aug 17 2023, 6:22 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Oct 27, 2:57 PM
Unknown Object (File)
Sun, Oct 27, 2:57 PM
Unknown Object (File)
Sun, Oct 27, 2:57 PM
Unknown Object (File)
Sun, Oct 27, 2:57 PM
Unknown Object (File)
Sun, Oct 27, 2:57 PM
Unknown Object (File)
Sun, Oct 27, 2:57 PM
Unknown Object (File)
Sun, Oct 27, 2:57 PM
Unknown Object (File)
Sun, Oct 27, 2:57 PM
Subscribers

Details

Summary

This diff adds the chatMentionCandidates object to all functions that return textMessageRules in rules.react.js, and includes this object as a parameter in all occurrences of these functions.

Depends on D8871.

Test Plan

Before testing, please apply the entire native stack.

  1. Check if mentions are rendered correctly (see D8845).
  2. Check if mention content is not replaced to default text (@[[id:default text]]) when pending sidebar is created.

Diff Detail

Repository
rCOMM Comm
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

patryk held this revision as a draft.

Update useTextMessageRulesFunc args in message-list-types.js

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)
This revision is now accepted and ready to land.Aug 28 2023, 3:40 AM

Change getDefaultTextMessageRules

native/markdown/rules.react.js
406–416

You might be wondering, if this function is almost the same as getDefaultTextMessageRules in D8851, then it should be moved to lib. We could introduce a new function which accepts textMessageRules as an argument and executes this logic. However I see some issues: what to do with defaultTextMessageRules? Since textMessageRules returns different values on native and web what should be returned when we override this variable? Solution to this would be to pass defaultTextMessageRules as an argument but I feel like this will make getDefaultTextMessageRules function more complicated. Another issue is what if textMessageRules will have additional argument only on web?

That's why I've decided to duplicate this code in two places. If arguments in textMessageRules will change, then flow will probably indicate that textMessageRules must be modified in getDefaultTextMessageRules. If you still think that this should be refactored, please let me know!

It might make sense to introduce a new hook that:

  1. Get the candidates using useThreadChatMentionCandidates
  2. Computes the rules using getDefaultTextMessageRules
  3. Memoizes them using memo
native/markdown/rules.react.js
409–415

You can early return to reduce indentation

Early return textMessageRules

@tomek's improvement makes sense, but I'm not applying them right now because I don't believe it will bring significant improvements. If there will be any performance issues during testing, it might be worth wrapping default rules with memo.