Render long-form notes

This commit is contained in:
Bojan Mojsilovic 2024-03-26 11:10:51 +01:00
parent cca4ab5949
commit f9ad9742e9
4 changed files with 49 additions and 12 deletions

View File

@ -21,7 +21,7 @@ import {
isWebmVideo, isWebmVideo,
isYouTube, isYouTube,
} from '../../lib/notes'; } from '../../lib/notes';
import { truncateNpub, userName } from '../../stores/profile'; import { authorName, truncateNpub, userName } from '../../stores/profile';
import EmbeddedNote from '../EmbeddedNote/EmbeddedNote'; import EmbeddedNote from '../EmbeddedNote/EmbeddedNote';
import { import {
Component, createSignal, For, JSXElement, onMount, Show, Component, createSignal, For, JSXElement, onMount, Show,
@ -40,7 +40,7 @@ import { hookForDev } from '../../lib/devTools';
import { getMediaUrl as getMediaUrlDefault } from "../../lib/media"; import { getMediaUrl as getMediaUrlDefault } from "../../lib/media";
import NoteImage from '../NoteImage/NoteImage'; import NoteImage from '../NoteImage/NoteImage';
import { createStore, unwrap } from 'solid-js/store'; import { createStore, unwrap } from 'solid-js/store';
import { hashtagCharsRegex, linebreakRegex, shortMentionInWords, shortNoteWords, specialCharsRegex, urlExtractRegex } from '../../constants'; import { hashtagCharsRegex, Kind, linebreakRegex, shortMentionInWords, shortNoteWords, specialCharsRegex, urlExtractRegex } from '../../constants';
import { useIntl } from '@cookbook/solid-intl'; import { useIntl } from '@cookbook/solid-intl';
import { actions } from '../../translations'; import { actions } from '../../translations';
@ -783,6 +783,32 @@ const ParsedNote: Component<{
</For> </For>
}; };
const renderLongFormMention = (mention: PrimalNote | undefined, index?: number) => {
if(!mention) return <></>;
const url = `https://highlighter.com/${mention.user.npub}/${mention.post.noteId}`
if (props.noPreviews) {
return renderLinks({
type: 'link',
tokens: [`https://highlighter.com/${mention.user.npub}/${mention.post.noteId}`],
});
}
const preview = {
url,
description: mention.post.content.slice(0, 100),
images: [mention.user.picture],
title: authorName(mention.user),
}
return <LinkPreview
preview={preview}
bordered={props.isEmbeded}
isLast={index === content.length-1}
/>;
};
const renderNoteMention = (item: NoteContent, index?: number) => { const renderNoteMention = (item: NoteContent, index?: number) => {
return <For each={item.tokens}> return <For each={item.tokens}>
{(token) => { {(token) => {
@ -825,13 +851,19 @@ const ParsedNote: Component<{
if (ment) { if (ment) {
setWordsDisplayed(w => w + shortMentionInWords); setWordsDisplayed(w => w + shortMentionInWords);
link = <div> if (ment.post.kind === Kind.LongForm) {
<EmbeddedNote link = renderLongFormMention(ment, index)
note={ment} }
mentionedUsers={props.note.mentionedUsers || {}} else {
isLast={index === content.length-1} link = <div>
/> <EmbeddedNote
</div>; note={ment}
mentionedUsers={props.note.mentionedUsers || {}}
isLast={index === content.length-1}
/>
</div>;
}
} }
} }

View File

@ -101,7 +101,9 @@ export enum Kind {
ChannelHideMessage = 43, ChannelHideMessage = 43,
ChannelMuteUser = 44, ChannelMuteUser = 44,
Zap = 9735, LongForm = 30_023,
Zap = 9_735,
MuteList = 10_000, MuteList = 10_000,
RelayList = 10_002, RelayList = 10_002,

View File

@ -43,6 +43,7 @@ export const getRepostInfo: RepostInfo = (page, message) => {
created_at: message.created_at || 0, created_at: message.created_at || 0,
tags: message.tags, tags: message.tags,
content: sanitize(message.content), content: sanitize(message.content),
kind: message.kind,
sig: message.sig, sig: message.sig,
likes: stat?.likes || 0, likes: stat?.likes || 0,
mentions: stat?.mentions || 0, mentions: stat?.mentions || 0,
@ -239,7 +240,7 @@ export const convertToNotes: ConvertToNotes = (page) => {
mentionedNotes[id] = { mentionedNotes[id] = {
// @ts-ignore TODO: Investigate this typing // @ts-ignore TODO: Investigate this typing
post: { ...m }, post: { ...m, noteId: nip19.noteEncode(m.id) },
user: convertToUser(page.users[m.pubkey] || emptyUser(m.pubkey)), user: convertToUser(page.users[m.pubkey] || emptyUser(m.pubkey)),
mentionedUsers, mentionedUsers,
}; };
@ -286,6 +287,7 @@ export const convertToNotes: ConvertToNotes = (page) => {
created_at: msg.created_at || 0, created_at: msg.created_at || 0,
tags: msg.tags, tags: msg.tags,
content: sanitize(msg.content), content: sanitize(msg.content),
kind: msg.kind,
sig: msg.sig, sig: msg.sig,
likes: stat?.likes || 0, likes: stat?.likes || 0,
mentions: stat?.mentions || 0, mentions: stat?.mentions || 0,

View File

@ -7,7 +7,7 @@ import { Kind } from "../constants";
export type NostrNoteContent = { export type NostrNoteContent = {
kind: Kind.Text | Kind.Repost, kind: Kind.Text | Kind.Repost | Kind.LongForm,
content: string, content: string,
id: string, id: string,
created_at?: number, created_at?: number,
@ -418,6 +418,7 @@ export type PrimalNoteData = {
tags: string[][], tags: string[][],
content: string, content: string,
sig: string, sig: string,
kind: Kind.Text | Kind.Repost | Kind.LongForm,
likes: number, likes: number,
mentions: number, mentions: number,
reposts: number, reposts: number,