use new note parser for channel message

This commit is contained in:
Ren Amamiya
2023-05-02 16:33:42 +07:00
parent dfd1333db8
commit 90bcabf27b
5 changed files with 7 additions and 60 deletions

View File

@@ -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);
};

View File

@@ -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 <ImagePreview key={match + i} url={match} size="small" />;
} else if (match.match(/(http:|https:)?(\/\/)?(www\.)?(youtube.com|youtu.be)\/(watch|embed)?(\?v=|\/)?(\S+)?/)) {
// youtube
return <YoutubePreview key={match + i} url={match} size="small" />;
} else if (match.match(/\.(mp4|webm)$/i)) {
// video
return <VideoPreview key={match + i} url={match} size="small" />;
} else {
return (
<a key={match + i} href={match} className="cursor-pointer text-fuchsia-500" target="_blank" rel="noreferrer">
{match}
</a>
);
}
});
// handle #-hashtags
parsedContent = reactStringReplace(parsedContent, /#(\w+)/g, (match, i) => (
<span key={match + i} className="cursor-pointer text-fuchsia-500">
#{match}
</span>
));
return parsedContent;
};