Open source video conferencing app powered by LiveKit. Built with Django and React.
π(frontend) vendor formatChatMessageLinks and trim surrounding newlines
lebaudantoine01e004e27218
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 6acf2696..44fce3fd 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -11,6 +11,7 @@ and this project adheres to### Changed- π₯(frontend) drop unused vendored ConnectionObserver+- π(frontend) vendor formatChatMessageLinks and trim surrounding newlines### Fixeddiff --git a/src/frontend/src/features/chat/components/ChatMessageBody.tsx b/src/frontend/src/features/chat/components/ChatMessageBody.tsxindex 67381ea4..f9decfdc 100644--- a/src/frontend/src/features/chat/components/ChatMessageBody.tsx+++ b/src/frontend/src/features/chat/components/ChatMessageBody.tsx@@ -1,6 +1,6 @@import { ChatRow } from '@/stores/chat'import React, { useMemo } from 'react'-import { formatChatMessageLinks } from '@livekit/components-react'+import { formatChatMessageLinks } from '../utils'import { css } from '@/styled-system/css'import { Text } from '@/primitives'diff --git a/src/frontend/src/features/chat/utils.tsx b/src/frontend/src/features/chat/utils.tsxnew file mode 100644index 00000000..7542e3b1--- /dev/null+++ b/src/frontend/src/features/chat/utils.tsx@@ -0,0 +1,32 @@+import { tokenize, createDefaultGrammar } from '@livekit/components-core'+import { ReactNode } from 'react'++const defaultGrammar = Object.freeze(createDefaultGrammar())++export function formatChatMessageLinks(message: string): ReactNode {+ const trimmedMessage = message.replace(/^[\r\n]+|[\r\n]+$/g, '')+ return tokenize(trimmedMessage, defaultGrammar).map((tok, i) => {+ if (typeof tok === `string`) {+ return tok+ } else {+ const content = tok.content.toString()+ const href =+ tok.type === `url`+ ? /^http(s?):\/\//.test(content)+ ? content+ : `https://${content}`+ : `mailto:${content}`+ return (+ <a+ className="lk-chat-link"+ key={i}+ href={href}+ target="_blank"+ rel="noreferrer"+ >+ {content}+ </a>+ )+ }+ })+}