From 3e6df7a24632e0c77c5a92753aa03ae85b693860 Mon Sep 17 00:00:00 2001
From: florian <>
Date: Wed, 29 May 2024 00:11:33 +0200
Subject: [PATCH] feat: Added links to posts and videos
---
.../AudioBlobList/AudioBlobList.tsx | 15 +++---
src/components/BlobList/Badge.tsx | 38 ++++++++++++-
.../DocumentBlobList/DocumentBlobList.tsx | 5 +-
.../FileEventEditor/FileEventEditor.tsx | 17 ++++--
.../FileEventEditor/usePublishing.ts | 9 ++--
src/utils/useFileMetaEvents.ts | 54 ++++++++++++++-----
6 files changed, 104 insertions(+), 34 deletions(-)
diff --git a/src/components/AudioBlobList/AudioBlobList.tsx b/src/components/AudioBlobList/AudioBlobList.tsx
index 485f024..1143450 100644
--- a/src/components/AudioBlobList/AudioBlobList.tsx
+++ b/src/components/AudioBlobList/AudioBlobList.tsx
@@ -31,13 +31,9 @@ const AudioBlobList = ({ audioFiles, onDelete }: AudioBlobListProps) => {
{audioFilesWithId3.map(
blob =>
blob.isSuccess && (
-
+
-
+
![]()
{
}
/>
{state.currentSong?.url == blob.data.url ? (
-
- dispatch({ type: 'RESET_CURRENT_SONG'})
- }>
+
dispatch({ type: 'RESET_CURRENT_SONG' })}
+ >
) : (
{
);
}
- return <>>;
+ if (ev.kind == KIND_VIDEO_HORIZONTAL || ev.kind == KIND_VIDEO_VERTICAL) {
+ const naddr = nip19.naddrEncode({
+ kind: ev.kind,
+ identifier: ev.tagValue('d'),
+ pubkey: ev.author.pubkey,
+ relays: ev.onRelays.map(r => r.url),
+ } as AddressPointer);
+ return (
+
+ video
+
+ );
+ }
+
+ if (ev.kind == KIND_SOCIAL_POST) {
+ const nevent = nip19.neventEncode({
+ kind: ev.kind,
+ id: ev.id,
+ author: ev.author.pubkey,
+ relays: ev.onRelays.map(r => r.url),
+ } as EventPointer);
+ return (
+
+ post
+
+ );
+ }
+
+ return {ev.kind};
};
export default Badge;
diff --git a/src/components/DocumentBlobList/DocumentBlobList.tsx b/src/components/DocumentBlobList/DocumentBlobList.tsx
index 873aab5..4a50bdb 100644
--- a/src/components/DocumentBlobList/DocumentBlobList.tsx
+++ b/src/components/DocumentBlobList/DocumentBlobList.tsx
@@ -11,10 +11,7 @@ type DocumentBlobListProps = {
const DocumentBlobList = ({ docs, onDelete }: DocumentBlobListProps) => (
{docs.map(blob => (
-
+
-
+
{jsonOutput}
>
);
diff --git a/src/components/FileEventEditor/usePublishing.ts b/src/components/FileEventEditor/usePublishing.ts
index 9c78528..d85d432 100644
--- a/src/components/FileEventEditor/usePublishing.ts
+++ b/src/components/FileEventEditor/usePublishing.ts
@@ -7,7 +7,7 @@ import { useNDK } from '../../utils/ndk';
export const usePublishing = () => {
const { ndk, user } = useNDK();
- const publishFileEvent = async (data: FileEventData) => {
+ const publishFileEvent = async (data: FileEventData): Promise
=> {
// TODO REupload selected video thumbnail from DVM
const e: NostrEvent = {
@@ -42,9 +42,10 @@ export const usePublishing = () => {
await ev.sign();
console.log(ev.rawEvent());
// await ev.publish();
+ return JSON.stringify(ev.rawEvent(), null, 2);
};
- const publishAudioEvent = async (data: FileEventData) => {
+ const publishAudioEvent = async (data: FileEventData): Promise => {
const e: NostrEvent = {
created_at: dayjs().unix(),
content: `${data.artist} - ${data.title}`,
@@ -76,9 +77,10 @@ export const usePublishing = () => {
await ev.sign();
console.log(ev.rawEvent());
// await ev.publish();
+ return JSON.stringify(ev.rawEvent(), null, 2);
};
- const publishVideoEvent = async (data: FileEventData) => {
+ const publishVideoEvent = async (data: FileEventData): Promise => {
const e: NostrEvent = {
created_at: dayjs().unix(),
content: data.content,
@@ -115,6 +117,7 @@ export const usePublishing = () => {
await ev.sign();
console.log(ev.rawEvent());
// await ev.publish();
+ return JSON.stringify(ev.rawEvent(), null, 2);
};
return {
diff --git a/src/utils/useFileMetaEvents.ts b/src/utils/useFileMetaEvents.ts
index d91afd1..4c4c360 100644
--- a/src/utils/useFileMetaEvents.ts
+++ b/src/utils/useFileMetaEvents.ts
@@ -1,36 +1,64 @@
import { useMemo } from 'react';
import useEvents from '../utils/useEvents';
import groupBy from 'lodash/groupBy';
-import { NDKFilter } from '@nostr-dev-kit/ndk';
+import { NDKEvent, NDKFilter } from '@nostr-dev-kit/ndk';
import { useNDK } from '../utils/ndk';
-import { mapValues } from 'lodash';
+import { mapValues, uniq } from 'lodash';
export const KIND_FILE_META = 1063;
export const KIND_BLOSSOM_DRIVE = 30563;
+export const KIND_SOCIAL_POST = 1;
+export const KIND_VIDEO_HORIZONTAL = 34235;
+export const KIND_VIDEO_VERTICAL = 34236;
+export const KIND_AUDIO = 31337;
+
+
+const blossomUrlRegex = /https?:\/\/(?:www\.)?[^\s/]+\/([a-fA-F0-9]{64})(?:\.[a-zA-Z0-9]+)?/g;
+
+function extractHashesFromContent(text: string) {
+ let match;
+ const hashes = [];
+ while ((match = blossomUrlRegex.exec(text)) !== null) {
+ hashes.push(match[1]);
+ }
+ return hashes;
+}
+
+const extractFromEvent = (ev: NDKEvent) => {
+ const tags = ev.tags.filter(t => t[0] == 'x').map(t => t[1]);
+ const hashesFromUrls = ev.tags.filter(t => t[0] == 'url').flatMap(t => extractHashesFromContent(t[1]));
+ const hashesFromContent = extractHashesFromContent(ev.content);
+ const uniqueHashes = [...new Set([...tags, ...hashesFromUrls, ...hashesFromContent])];
+ return uniqueHashes.flatMap(t => ({ x: t, ev }));
+};
const useFileMetaEventsByHash = () => {
const { user } = useNDK();
const fileMetaFilter = useMemo(
- () => ({ kinds: [KIND_FILE_META, KIND_BLOSSOM_DRIVE], authors: [user?.pubkey] }) as NDKFilter,
+ () =>
+ ({
+ kinds: [
+ KIND_FILE_META,
+ KIND_BLOSSOM_DRIVE,
+ KIND_SOCIAL_POST,
+ KIND_VIDEO_HORIZONTAL,
+ KIND_VIDEO_VERTICAL,
+ KIND_AUDIO,
+ ],
+ authors: [user?.pubkey],
+ limit: 100,
+ }) as NDKFilter,
[user?.pubkey]
);
const fileMetaSub = useEvents(fileMetaFilter);
- /*
const fileMetaEventsByHash = useMemo(() => {
- const allXTags = fileMetaSub.events.flatMap(ev => ev.tags.filter(t => t[0]=='x').flatMap(t => ({x:t[1], ev})));
-console.log(allXTags);
- return groupBy(allXTags, item => item.x)
- }, [fileMetaSub.events]);
-*/
-
- const fileMetaEventsByHash = useMemo(() => {
- const allXTags = fileMetaSub.events.flatMap(ev => ev.tags.filter(t => t[0] == 'x').flatMap(t => ({ x: t[1], ev })));
+ const allXTags = fileMetaSub.events.flatMap(ev => extractFromEvent(ev));
const groupedByX = groupBy(allXTags, item => item.x);
return mapValues(groupedByX, v => v.map(e => e.ev));
}, [fileMetaSub]);
- // console.log(fileMetaEventsByHash);
+ console.log(fileMetaEventsByHash);
return fileMetaEventsByHash;
};