Skip to content

Conversation

@chohongm
Copy link
Contributor

@chohongm chohongm commented May 31, 2024

Fixes: AC-2156

Changelogs

  • Added enableMarkdownForUserMessage to UIKitOptions. When enabled, user messages that include markdowns syntaxes are now being applied to the original text

Side note

In future we need to apply the rest of markdowns:
https://www.markdownguide.org/cheat-sheet/

Also we have issue with nested markdown case: Handled!
case 1: **text[google](www.google.com)** => only url is applied
case 2: text[**google**](www.google.com) => only url is applied

In this PR, i will replace markdown logic with marking logic to cover above case.

After

Screenshot 2024-06-03 at 1 56 28 PM
Screenshot 2024-06-03 at 1 56 35 PM

@chohongm chohongm requested review from AhyoungRyu, HoonBaek and bang9 May 31, 2024 09:01
@chohongm chohongm self-assigned this May 31, 2024
@netlify
Copy link

netlify bot commented May 31, 2024

Deploy Preview for sendbird-uikit-react ready!

Name Link
🔨 Latest commit f80e1a8
🔍 Latest deploy log https://app.netlify.com/sites/sendbird-uikit-react/deploys/66724dbefb247d0008ea0f75
😎 Deploy Preview https://deploy-preview-1120--sendbird-uikit-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@chohongm chohongm requested a review from bang9 June 3, 2024 05:00
@chohongm chohongm requested a review from bang9 June 7, 2024 01:20
const text = value[0];
const start = value.index ?? 0;
const end = start + text.length;
return { text, start, end, groups: value.filter((val: any) => typeof val === 'string') };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

요거 filter 안해주면 아주 이상한 data structure 가 나오는데 요게 any[] 로 취급이 안되서 필터를 해줘야 합니다.
이상한 data struture (array 에 key value 가 들어감):

[
          '[here](https://example.com)',
          'here',
          'https://example.com',
          index: 112,
          input: '! This is a test for **tokenizeMessage**. Followings are urls with different syntaxes: https://example.com, and [here](https://example.com).',
          groups: undefined
        ]

@chohongm chohongm requested a review from bang9 June 7, 2024 05:05
@bang9
Copy link
Contributor

bang9 commented Jun 7, 2024

test: https://deploy-preview-1120--sendbird-uikit-react.netlify.app/group_channel?groupChannel_enableMarkdownForUserMessage=true

groups,
};
newTokens.push(mid);
restText = rawStr.slice(end);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed:
past: restText = restText.slice(end);
now: restText = rawStr.slice(end);

@chohongm chohongm added v3.14.11 and removed v3.14.9 labels Jun 7, 2024
Copy link
Contributor

Choose a reason for hiding this comment

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

이 컴포넌트는 현재 이 PR 에서 사용되지 않는것 같은데, 변경 안하는게 낫지 않을까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

음 버그 였던것 같은데 다시 확인해서 아니면 돌려놓겠습니다.

@chohongm
Copy link
Contributor Author

@bang9 요거 알고리듬을 바꿔야 될 것 같습니다. 현재 token 으로 나눠서 하기 때문에 하나의 토큰 안에 한가지만 적용하다는 limitation 이 있기 때문입니다. token 으로 나누지 않고 오리지날 스트링에 range mapping 을 사용하면 해결 될것 같습니다. from x to y is url, from a to b is markdown bold, ... etc.

@bang9
Copy link
Contributor

bang9 commented Jun 13, 2024

@bang9 요거 알고리듬을 바꿔야 될 것 같습니다. 현재 token 으로 나눠서 하기 때문에 하나의 토큰 안에 한가지만 적용하다는 limitation 이 있기 때문입니다. token 으로 나누지 않고 오리지날 스트링에 range mapping 을 사용하면 해결 될것 같습니다. from x to y is url, from a to b is markdown bold, ... etc.

네 변경되면 리뷰요청 주세요

@chohongm chohongm requested a review from bang9 June 18, 2024 05:16
@chohongm
Copy link
Contributor Author

@bang9 can you test again?
Screenshot 2024-06-18 at 2 16 42 PM

@bang9
Copy link
Contributor

bang9 commented Jun 18, 2024

@liamcho could you check the failed test? And it is good to add test for the nested cases when you have room!

@chohongm
Copy link
Contributor Author

@bang9 can you review again please~

Copy link
Contributor

@AhyoungRyu AhyoungRyu left a comment

Choose a reason for hiding this comment

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

Left some minor comments but not blockers. LGTM

@@ -0,0 +1,18 @@
export function asSafeURL(url: string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have a comment about this util function? Brief input & output example would be helpful :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

}
const rawStr = token.value;
// @ts-ignore
const matches = [...rawStr.matchAll(MarkdownRegex)];
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have a reason for copying rawStr.matchAll(MarkdownRegex) and create a new array here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

purpose was not to copy but to create an array from iterator

Comment on lines +120 to +122
const allMatches = matches.map((value) => {
const text = value[0];
const start = value.index ?? 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const allMatches = matches.map((value) => {
const text = value[0];
const start = value.index ?? 0;
const allMatches = matches.map((value, start) => {
const text = value[0];

We can get the index directly like in this way too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

are you sure its the same? matches.map((value, start) => { start here would be array index but const start = value.index ?? 0; is meant to get start index from match object.

@AhyoungRyu AhyoungRyu merged commit e1f4669 into main Jun 19, 2024
@AhyoungRyu AhyoungRyu deleted the feat/AC-2156-apply-markdown-to-user-message branch June 19, 2024 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants