From 90bcabf27b6dec26c470bef7a5115049872b3b4d Mon Sep 17 00:00:00 2001 From: Ren Amamiya <123083837+reyamir@users.noreply.github.com> Date: Tue, 2 May 2023 16:33:42 +0700 Subject: [PATCH] use new note parser for channel message --- src/app/channel/components/messages/item.tsx | 10 +++--- src/app/chat/components/messages/item.tsx | 2 +- src/app/note/components/parser.tsx | 7 ---- src/utils/broadcast.tsx | 11 ------ src/utils/parser.tsx | 37 -------------------- 5 files changed, 7 insertions(+), 60 deletions(-) delete mode 100644 src/utils/broadcast.tsx delete mode 100644 src/utils/parser.tsx diff --git a/src/app/channel/components/messages/item.tsx b/src/app/channel/components/messages/item.tsx index 116277d0..39cc765a 100644 --- a/src/app/channel/components/messages/item.tsx +++ b/src/app/channel/components/messages/item.tsx @@ -2,10 +2,12 @@ import MessageHideButton from '@lume/app/channel/components/messages/hideButton' import MessageMuteButton from '@lume/app/channel/components/messages/muteButton'; import MessageReplyButton from '@lume/app/channel/components/messages/replyButton'; import ChannelMessageUser from '@lume/app/channel/components/messages/user'; -import { messageParser } from '@lume/utils/parser'; +import { noteParser } from '@lume/app/note/components/parser'; + +import { useMemo } from 'react'; export default function ChannelMessageItem({ data }: { data: any }) { - const content = messageParser(data.content); + const content = useMemo(() => noteParser(data), [data]); return (
@@ -13,8 +15,8 @@ export default function ChannelMessageItem({ data }: { data: any }) {
-
- {data.hide ? [hided message] : content} +
+ {data.hide ? [hided message] : content.parsed}
diff --git a/src/app/chat/components/messages/item.tsx b/src/app/chat/components/messages/item.tsx index eb38a1cc..e38705a9 100644 --- a/src/app/chat/components/messages/item.tsx +++ b/src/app/chat/components/messages/item.tsx @@ -19,7 +19,7 @@ export const ChatMessageItem = memo(function MessageListItem({
-
{content}
+
{content}
diff --git a/src/app/note/components/parser.tsx b/src/app/note/components/parser.tsx index cae72011..f1802ec5 100644 --- a/src/app/note/components/parser.tsx +++ b/src/app/note/components/parser.tsx @@ -57,12 +57,5 @@ export const noteParser = (event: Event) => { } }); - // make sure no unnessary spaces are left - content.parsed.forEach((item: string, index: string) => { - if (typeof item === 'string') { - content.parsed[index] = item.replace(/^\x20+|\x20+$/gm, ''); - } - }); - return content; }; diff --git a/src/utils/broadcast.tsx b/src/utils/broadcast.tsx deleted file mode 100644 index 488b182d..00000000 --- a/src/utils/broadcast.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import { WRITEONLY_RELAYS } from '@lume/stores/constants'; - -import { getEventHash, signEvent } from 'nostr-tools'; - -export const broadcast = ({ pool, data, privkey }: { pool: any; data: any; privkey: string }) => { - const event = data; - event.id = getEventHash(event); - event.sig = signEvent(event, privkey); - - pool.publish(event, WRITEONLY_RELAYS); -}; diff --git a/src/utils/parser.tsx b/src/utils/parser.tsx deleted file mode 100644 index 355b047b..00000000 --- a/src/utils/parser.tsx +++ /dev/null @@ -1,37 +0,0 @@ -import ImagePreview from '@lume/shared/preview/image'; -import VideoPreview from '@lume/shared/preview/video'; -import YoutubePreview from '@lume/shared/preview/youtube'; - -import reactStringReplace from 'react-string-replace'; - -export const messageParser = (noteContent: any) => { - let parsedContent = noteContent.trim(); - - // handle urls - parsedContent = reactStringReplace(parsedContent, /(https?:\/\/\S+)/g, (match, i) => { - if (match.match(/\.(jpg|jpeg|gif|png|webp)$/i)) { - // image url - return ; - } else if (match.match(/(http:|https:)?(\/\/)?(www\.)?(youtube.com|youtu.be)\/(watch|embed)?(\?v=|\/)?(\S+)?/)) { - // youtube - return ; - } else if (match.match(/\.(mp4|webm)$/i)) { - // video - return ; - } else { - return ( - - {match} - - ); - } - }); - // handle #-hashtags - parsedContent = reactStringReplace(parsedContent, /#(\w+)/g, (match, i) => ( - - #{match} - - )); - - return parsedContent; -};