mirror of
https://github.com/PrimalHQ/primal-web-app.git
synced 2024-10-01 17:31:13 +00:00
Render long-form notes
This commit is contained in:
parent
cca4ab5949
commit
f9ad9742e9
@ -21,7 +21,7 @@ import {
|
||||
isWebmVideo,
|
||||
isYouTube,
|
||||
} from '../../lib/notes';
|
||||
import { truncateNpub, userName } from '../../stores/profile';
|
||||
import { authorName, truncateNpub, userName } from '../../stores/profile';
|
||||
import EmbeddedNote from '../EmbeddedNote/EmbeddedNote';
|
||||
import {
|
||||
Component, createSignal, For, JSXElement, onMount, Show,
|
||||
@ -40,7 +40,7 @@ import { hookForDev } from '../../lib/devTools';
|
||||
import { getMediaUrl as getMediaUrlDefault } from "../../lib/media";
|
||||
import NoteImage from '../NoteImage/NoteImage';
|
||||
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 { actions } from '../../translations';
|
||||
|
||||
@ -783,6 +783,32 @@ const ParsedNote: Component<{
|
||||
</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) => {
|
||||
return <For each={item.tokens}>
|
||||
{(token) => {
|
||||
@ -825,13 +851,19 @@ const ParsedNote: Component<{
|
||||
if (ment) {
|
||||
setWordsDisplayed(w => w + shortMentionInWords);
|
||||
|
||||
link = <div>
|
||||
<EmbeddedNote
|
||||
note={ment}
|
||||
mentionedUsers={props.note.mentionedUsers || {}}
|
||||
isLast={index === content.length-1}
|
||||
/>
|
||||
</div>;
|
||||
if (ment.post.kind === Kind.LongForm) {
|
||||
link = renderLongFormMention(ment, index)
|
||||
}
|
||||
else {
|
||||
link = <div>
|
||||
<EmbeddedNote
|
||||
note={ment}
|
||||
mentionedUsers={props.note.mentionedUsers || {}}
|
||||
isLast={index === content.length-1}
|
||||
/>
|
||||
</div>;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,9 @@ export enum Kind {
|
||||
ChannelHideMessage = 43,
|
||||
ChannelMuteUser = 44,
|
||||
|
||||
Zap = 9735,
|
||||
LongForm = 30_023,
|
||||
|
||||
Zap = 9_735,
|
||||
|
||||
MuteList = 10_000,
|
||||
RelayList = 10_002,
|
||||
|
@ -43,6 +43,7 @@ export const getRepostInfo: RepostInfo = (page, message) => {
|
||||
created_at: message.created_at || 0,
|
||||
tags: message.tags,
|
||||
content: sanitize(message.content),
|
||||
kind: message.kind,
|
||||
sig: message.sig,
|
||||
likes: stat?.likes || 0,
|
||||
mentions: stat?.mentions || 0,
|
||||
@ -239,7 +240,7 @@ export const convertToNotes: ConvertToNotes = (page) => {
|
||||
|
||||
mentionedNotes[id] = {
|
||||
// @ts-ignore TODO: Investigate this typing
|
||||
post: { ...m },
|
||||
post: { ...m, noteId: nip19.noteEncode(m.id) },
|
||||
user: convertToUser(page.users[m.pubkey] || emptyUser(m.pubkey)),
|
||||
mentionedUsers,
|
||||
};
|
||||
@ -286,6 +287,7 @@ export const convertToNotes: ConvertToNotes = (page) => {
|
||||
created_at: msg.created_at || 0,
|
||||
tags: msg.tags,
|
||||
content: sanitize(msg.content),
|
||||
kind: msg.kind,
|
||||
sig: msg.sig,
|
||||
likes: stat?.likes || 0,
|
||||
mentions: stat?.mentions || 0,
|
||||
|
3
src/types/primal.d.ts
vendored
3
src/types/primal.d.ts
vendored
@ -7,7 +7,7 @@ import { Kind } from "../constants";
|
||||
|
||||
|
||||
export type NostrNoteContent = {
|
||||
kind: Kind.Text | Kind.Repost,
|
||||
kind: Kind.Text | Kind.Repost | Kind.LongForm,
|
||||
content: string,
|
||||
id: string,
|
||||
created_at?: number,
|
||||
@ -418,6 +418,7 @@ export type PrimalNoteData = {
|
||||
tags: string[][],
|
||||
content: string,
|
||||
sig: string,
|
||||
kind: Kind.Text | Kind.Repost | Kind.LongForm,
|
||||
likes: number,
|
||||
mentions: number,
|
||||
reposts: number,
|
||||
|
Loading…
Reference in New Issue
Block a user