completed migrate to tauri-sql
This commit is contained in:
@@ -16,19 +16,9 @@ export const BrowseChannelItem = ({ data }: { data: any }) => {
|
||||
[router]
|
||||
);
|
||||
|
||||
const joinChannel = useCallback(
|
||||
async (id: string) => {
|
||||
const { updateChannel } = await import('@utils/bindings');
|
||||
updateChannel({ event_id: id, active: true })
|
||||
.then(() => openChannel(id))
|
||||
.catch(console.error);
|
||||
},
|
||||
[openChannel]
|
||||
);
|
||||
|
||||
return (
|
||||
<div
|
||||
onClick={() => openChannel(data.eventId)}
|
||||
onClick={() => openChannel(data.event_id)}
|
||||
className="group relative flex items-center gap-2 border-b border-zinc-800 px-3 py-2.5 hover:bg-black/20"
|
||||
>
|
||||
<div className="relative h-11 w-11 shrink overflow-hidden rounded-md border border-white/10">
|
||||
@@ -44,10 +34,7 @@ export const BrowseChannelItem = ({ data }: { data: any }) => {
|
||||
<span className="text-sm leading-tight text-zinc-400">{channel.about}</span>
|
||||
</div>
|
||||
<div className="absolute right-2 top-1/2 hidden -translate-y-1/2 transform group-hover:inline-flex">
|
||||
<button
|
||||
onClick={() => joinChannel(data.eventId)}
|
||||
className="inline-flex h-8 w-16 items-center justify-center rounded-md bg-fuchsia-500 px-4 text-sm font-medium shadow-button hover:bg-fuchsia-600 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50"
|
||||
>
|
||||
<button className="inline-flex h-8 w-16 items-center justify-center rounded-md bg-fuchsia-500 px-4 text-sm font-medium shadow-button hover:bg-fuchsia-600 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50">
|
||||
Join
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -3,21 +3,10 @@ import { CreateChannelModal } from '@components/channels/createChannelModal';
|
||||
|
||||
import { Globe } from 'iconoir-react';
|
||||
import Link from 'next/link';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useState } from 'react';
|
||||
|
||||
export default function ChannelList() {
|
||||
const [list, setList] = useState([]);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchChannels = async () => {
|
||||
const { getActiveChannels } = await import('@utils/bindings');
|
||||
return await getActiveChannels({ active: true });
|
||||
};
|
||||
|
||||
fetchChannels()
|
||||
.then((res) => setList(res))
|
||||
.catch(console.error);
|
||||
}, []);
|
||||
const [list] = useState([]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-px">
|
||||
|
||||
@@ -8,14 +8,14 @@ export const ChannelListItem = ({ data }: { data: any }) => {
|
||||
|
||||
return (
|
||||
<ActiveLink
|
||||
href={`/nostr/channels/${data.eventId}`}
|
||||
href={`/nostr/channels/${data.event_id}`}
|
||||
activeClassName="dark:bg-zinc-900 dark:text-zinc-100 hover:dark:bg-zinc-800"
|
||||
className="inline-flex items-center gap-2 rounded-md px-2.5 py-1.5 hover:bg-zinc-900"
|
||||
>
|
||||
<div className="relative h-5 w-5 shrink-0 overflow-hidden rounded">
|
||||
<ImageWithFallback
|
||||
src={channel?.picture || DEFAULT_AVATAR}
|
||||
alt={data.eventId}
|
||||
alt={data.event_id}
|
||||
fill={true}
|
||||
className="rounded object-cover"
|
||||
/>
|
||||
|
||||
@@ -6,14 +6,13 @@ import * as Dialog from '@radix-ui/react-dialog';
|
||||
import useLocalStorage from '@rehooks/local-storage';
|
||||
import { Cancel, Plus } from 'iconoir-react';
|
||||
import { getEventHash, signEvent } from 'nostr-tools';
|
||||
import { useCallback, useContext, useState } from 'react';
|
||||
import { useContext, useState } from 'react';
|
||||
import { useForm } from 'react-hook-form';
|
||||
|
||||
export const CreateChannelModal = () => {
|
||||
const [pool, relays]: any = useContext(RelayContext);
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const [activeAccount]: any = useLocalStorage('activeAccount', {});
|
||||
const [activeAccount]: any = useLocalStorage('account', {});
|
||||
|
||||
const {
|
||||
register,
|
||||
@@ -22,11 +21,6 @@ export const CreateChannelModal = () => {
|
||||
formState: { isDirty, isValid },
|
||||
} = useForm();
|
||||
|
||||
const insertChannelToDB = useCallback(async (id, data, account) => {
|
||||
const { createChannel } = await import('@utils/bindings');
|
||||
return await createChannel({ event_id: id, content: data, account_id: account });
|
||||
}, []);
|
||||
|
||||
const onSubmit = (data) => {
|
||||
const event: any = {
|
||||
content: JSON.stringify(data),
|
||||
@@ -40,8 +34,6 @@ export const CreateChannelModal = () => {
|
||||
|
||||
// publish channel
|
||||
pool.publish(event, relays);
|
||||
// save to database
|
||||
insertChannelToDB(event.id, data, activeAccount.id);
|
||||
// close modal
|
||||
setOpen(false);
|
||||
// reset form
|
||||
|
||||
@@ -11,7 +11,7 @@ import { useCallback, useContext } from 'react';
|
||||
|
||||
export const HideMessageButton = ({ id }: { id: string }) => {
|
||||
const [pool, relays]: any = useContext(RelayContext);
|
||||
const [activeAccount]: any = useLocalStorage('activeAccount', {});
|
||||
const [activeAccount]: any = useLocalStorage('account', {});
|
||||
|
||||
const hideMessage = useCallback(() => {
|
||||
const event: any = {
|
||||
|
||||
@@ -11,7 +11,7 @@ import { useCallback, useContext } from 'react';
|
||||
|
||||
export const MuteButton = ({ pubkey }: { pubkey: string }) => {
|
||||
const [pool, relays]: any = useContext(RelayContext);
|
||||
const [activeAccount]: any = useLocalStorage('activeAccount', {});
|
||||
const [activeAccount]: any = useLocalStorage('account', {});
|
||||
|
||||
const muteUser = useCallback(() => {
|
||||
const event: any = {
|
||||
|
||||
@@ -4,6 +4,8 @@ import { ImageWithFallback } from '@components/imageWithFallback';
|
||||
|
||||
import { DEFAULT_AVATAR } from '@stores/constants';
|
||||
|
||||
import { getChats } from '@utils/storage';
|
||||
|
||||
import useLocalStorage from '@rehooks/local-storage';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useEffect, useState } from 'react';
|
||||
@@ -12,7 +14,7 @@ export default function ChatList() {
|
||||
const router = useRouter();
|
||||
|
||||
const [list, setList] = useState([]);
|
||||
const [activeAccount]: any = useLocalStorage('activeAccount', {});
|
||||
const [activeAccount]: any = useLocalStorage('account', {});
|
||||
const profile = activeAccount.metadata ? JSON.parse(activeAccount.metadata) : null;
|
||||
|
||||
const openSelfChat = () => {
|
||||
@@ -20,12 +22,7 @@ export default function ChatList() {
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const fetchChats = async () => {
|
||||
const { getChats } = await import('@utils/bindings');
|
||||
return await getChats({ account_id: activeAccount.id });
|
||||
};
|
||||
|
||||
fetchChats()
|
||||
getChats(activeAccount.id)
|
||||
.then((res) => setList(res))
|
||||
.catch(console.error);
|
||||
}, [activeAccount.id]);
|
||||
|
||||
@@ -1,24 +1,19 @@
|
||||
import { ChatModalUser } from '@components/chats/chatModalUser';
|
||||
|
||||
import { getPlebs } from '@utils/storage';
|
||||
|
||||
import * as Dialog from '@radix-ui/react-dialog';
|
||||
import useLocalStorage from '@rehooks/local-storage';
|
||||
import { Cancel, Plus } from 'iconoir-react';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
export const ChatModal = () => {
|
||||
const [plebs, setPlebs] = useState([]);
|
||||
const [activeAccount]: any = useLocalStorage('activeAccount', {});
|
||||
|
||||
const fetchPlebsByAccount = useCallback(async (id) => {
|
||||
const { getPlebs } = await import('@utils/bindings');
|
||||
return await getPlebs({ account_id: id, kind: 0 });
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetchPlebsByAccount(activeAccount.id)
|
||||
getPlebs()
|
||||
.then((res) => setPlebs(res))
|
||||
.catch(console.error);
|
||||
}, [activeAccount.id, fetchPlebsByAccount]);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Dialog.Root>
|
||||
|
||||
@@ -9,7 +9,7 @@ import { useCallback, useRef } from 'react';
|
||||
import { Virtuoso } from 'react-virtuoso';
|
||||
|
||||
export const MessageList = () => {
|
||||
const [activeAccount]: any = useLocalStorage('activeAccount', {});
|
||||
const [activeAccount]: any = useLocalStorage('account', {});
|
||||
const virtuosoRef = useRef(null);
|
||||
|
||||
const data = useAtomValue(sortedChatMessagesAtom);
|
||||
|
||||
@@ -6,8 +6,8 @@ import { RelayContext } from '@components/relaysProvider';
|
||||
import { hasNewerNoteAtom } from '@stores/note';
|
||||
|
||||
import { dateToUnix } from '@utils/getDate';
|
||||
import { fetchProfileMetadata } from '@utils/hooks/useProfileMetadata';
|
||||
import { getParentID, pubkeyArray } from '@utils/transform';
|
||||
import { createChannel, createChat, createNote, updateAccount } from '@utils/storage';
|
||||
import { getParentID, nip02ToArray } from '@utils/transform';
|
||||
|
||||
import useLocalStorage, { writeStorage } from '@rehooks/local-storage';
|
||||
import { window } from '@tauri-apps/api';
|
||||
@@ -17,46 +17,19 @@ import { useCallback, useContext, useEffect, useRef } from 'react';
|
||||
|
||||
export default function EventCollector() {
|
||||
const [pool, relays]: any = useContext(RelayContext);
|
||||
|
||||
const [activeAccount]: any = useLocalStorage('activeAccount', {});
|
||||
const [follows] = useLocalStorage('activeAccountFollows', []);
|
||||
const [activeAccount]: any = useLocalStorage('account', {});
|
||||
|
||||
const setHasNewerNote = useSetAtom(hasNewerNoteAtom);
|
||||
|
||||
const now = useRef(new Date());
|
||||
const unsubscribe = useRef(null);
|
||||
|
||||
const createFollowingPlebs = useCallback(
|
||||
async (tags) => {
|
||||
const { createPleb } = await import('@utils/bindings');
|
||||
for (const tag of tags) {
|
||||
const pubkey = tag[1];
|
||||
fetchProfileMetadata(pubkey)
|
||||
.then((res: { content: string }) => {
|
||||
createPleb({
|
||||
pleb_id: pubkey + '-lume' + activeAccount.id.toString(),
|
||||
pubkey: pubkey,
|
||||
kind: 0,
|
||||
metadata: res.content,
|
||||
account_id: activeAccount.id,
|
||||
}).catch(console.error);
|
||||
})
|
||||
.catch(console.error);
|
||||
}
|
||||
},
|
||||
[activeAccount.id]
|
||||
);
|
||||
|
||||
const subscribe = useCallback(async () => {
|
||||
const { createNote } = await import('@utils/bindings');
|
||||
const { createChat } = await import('@utils/bindings');
|
||||
const { createChannel } = await import('@utils/bindings');
|
||||
|
||||
unsubscribe.current = pool.subscribe(
|
||||
[
|
||||
{
|
||||
kinds: [1, 6],
|
||||
authors: pubkeyArray(follows),
|
||||
authors: activeAccount.follows,
|
||||
since: dateToUnix(now.current),
|
||||
},
|
||||
{
|
||||
@@ -79,65 +52,54 @@ export default function EventCollector() {
|
||||
// short text note
|
||||
case 1:
|
||||
const parentID = getParentID(event.tags, event.id);
|
||||
createNote({
|
||||
event_id: event.id,
|
||||
pubkey: event.pubkey,
|
||||
kind: event.kind,
|
||||
tags: JSON.stringify(event.tags),
|
||||
content: event.content,
|
||||
parent_id: parentID,
|
||||
parent_comment_id: '',
|
||||
created_at: event.created_at,
|
||||
account_id: activeAccount.id,
|
||||
})
|
||||
.then(() =>
|
||||
// notify user reload to get newer note
|
||||
setHasNewerNote(true)
|
||||
)
|
||||
.catch(console.error);
|
||||
createNote(
|
||||
event.id,
|
||||
activeAccount.id,
|
||||
event.pubkey,
|
||||
event.kind,
|
||||
event.tags,
|
||||
event.content,
|
||||
event.created_at,
|
||||
parentID
|
||||
);
|
||||
// notify user reload to get newer note
|
||||
setHasNewerNote(true);
|
||||
break;
|
||||
// contacts
|
||||
case 3:
|
||||
createFollowingPlebs(event.tags);
|
||||
const arr = nip02ToArray(event.tags);
|
||||
// update account's folllows with NIP-02 tag list
|
||||
updateAccount('follows', arr, event.pubkey);
|
||||
break;
|
||||
// chat
|
||||
case 4:
|
||||
if (event.pubkey !== activeAccount.pubkey) {
|
||||
createChat({
|
||||
pubkey: event.pubkey,
|
||||
created_at: event.created_at,
|
||||
account_id: activeAccount.id,
|
||||
}).catch(console.error);
|
||||
createChat(activeAccount.id, event.pubkey, event.created_at);
|
||||
}
|
||||
break;
|
||||
// repost
|
||||
case 6:
|
||||
createNote({
|
||||
event_id: event.id,
|
||||
pubkey: event.pubkey,
|
||||
kind: event.kind,
|
||||
tags: JSON.stringify(event.tags),
|
||||
content: event.content,
|
||||
parent_id: '',
|
||||
parent_comment_id: '',
|
||||
created_at: event.created_at,
|
||||
account_id: activeAccount.id,
|
||||
})
|
||||
.then(() =>
|
||||
// notify user reload to get newer note
|
||||
setHasNewerNote(true)
|
||||
)
|
||||
.catch(console.error);
|
||||
createNote(
|
||||
event.id,
|
||||
activeAccount.id,
|
||||
event.pubkey,
|
||||
event.kind,
|
||||
event.tags,
|
||||
event.content,
|
||||
event.created_at,
|
||||
''
|
||||
);
|
||||
break;
|
||||
// channel
|
||||
case 40:
|
||||
createChannel({ event_id: event.id, content: event.content, account_id: activeAccount.id }).catch(
|
||||
console.error
|
||||
);
|
||||
createChannel(event.id, event.content, event.created_at);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
);
|
||||
}, [pool, relays, activeAccount.id, activeAccount.pubkey, follows, setHasNewerNote, createFollowingPlebs]);
|
||||
}, [activeAccount.follows, activeAccount.pubkey, activeAccount.id, pool, relays, setHasNewerNote]);
|
||||
|
||||
const listenWindowClose = useCallback(async () => {
|
||||
window.getCurrent().listen(TauriEvent.WINDOW_CLOSE_REQUESTED, () => {
|
||||
|
||||
@@ -18,7 +18,7 @@ export default function FormBase() {
|
||||
const [value, setValue] = useAtom(noteContentAtom);
|
||||
const resetValue = useResetAtom(noteContentAtom);
|
||||
|
||||
const [activeAccount]: any = useLocalStorage('activeAccount', {});
|
||||
const [activeAccount]: any = useLocalStorage('account', {});
|
||||
|
||||
const submitEvent = () => {
|
||||
const event: any = {
|
||||
|
||||
@@ -17,7 +17,7 @@ export default function FormChannelMessage({ eventId }: { eventId: string | stri
|
||||
const [pool, relays]: any = useContext(RelayContext);
|
||||
|
||||
const [value, setValue] = useState('');
|
||||
const [activeAccount]: any = useLocalStorage('activeAccount', {});
|
||||
const [activeAccount]: any = useLocalStorage('account', {});
|
||||
|
||||
const channelReply = useAtomValue(channelReplyAtom);
|
||||
const resetChannelReply = useResetAtom(channelReplyAtom);
|
||||
|
||||
@@ -11,7 +11,7 @@ export default function FormChat({ receiverPubkey }: { receiverPubkey: string })
|
||||
const [pool, relays]: any = useContext(RelayContext);
|
||||
|
||||
const [value, setValue] = useState('');
|
||||
const [activeAccount]: any = useLocalStorage('activeAccount', {});
|
||||
const [activeAccount]: any = useLocalStorage('account', {});
|
||||
|
||||
const encryptMessage = useCallback(
|
||||
async (privkey: string) => {
|
||||
|
||||
@@ -10,7 +10,7 @@ import { useContext, useState } from 'react';
|
||||
export default function FormComment({ eventID }: { eventID: any }) {
|
||||
const [pool, relays]: any = useContext(RelayContext);
|
||||
|
||||
const [activeAccount]: any = useLocalStorage('activeAccount', {});
|
||||
const [activeAccount]: any = useLocalStorage('account', {});
|
||||
const [value, setValue] = useState('');
|
||||
|
||||
const profile = JSON.parse(activeAccount.metadata);
|
||||
|
||||
@@ -5,6 +5,8 @@ import { InactiveAccount } from '@components/multiAccounts/inactiveAccount';
|
||||
|
||||
import { APP_VERSION } from '@stores/constants';
|
||||
|
||||
import { getAccounts } from '@utils/storage';
|
||||
|
||||
import LumeSymbol from '@assets/icons/Lume';
|
||||
|
||||
import useLocalStorage from '@rehooks/local-storage';
|
||||
@@ -14,7 +16,7 @@ import { useCallback, useEffect, useState } from 'react';
|
||||
|
||||
export default function MultiAccounts() {
|
||||
const [users, setUsers] = useState([]);
|
||||
const [activeAccount]: any = useLocalStorage('activeAccount', {});
|
||||
const [activeAccount]: any = useLocalStorage('account', {});
|
||||
|
||||
const renderAccount = useCallback(
|
||||
(user: { pubkey: string }) => {
|
||||
@@ -27,16 +29,11 @@ export default function MultiAccounts() {
|
||||
[activeAccount.pubkey]
|
||||
);
|
||||
|
||||
const fetchAccounts = useCallback(async () => {
|
||||
const { getAccounts } = await import('@utils/bindings');
|
||||
const accounts = await getAccounts();
|
||||
// update state
|
||||
setUsers(accounts);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetchAccounts().catch(console.error);
|
||||
}, [fetchAccounts]);
|
||||
getAccounts()
|
||||
.then((res) => setUsers(res))
|
||||
.catch(console.error);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-between px-2 pb-4 pt-3">
|
||||
|
||||
@@ -13,7 +13,7 @@ export const NoteBase = memo(function NoteBase({ event }: { event: any }) {
|
||||
|
||||
const parentNote = () => {
|
||||
if (event.parent_id) {
|
||||
if (event.parent_id !== event.eventId && !event.content.includes('#[0]')) {
|
||||
if (event.parent_id !== event.event_id && !event.content.includes('#[0]')) {
|
||||
return <NoteParent key={event.parent_id} id={event.parent_id} />;
|
||||
}
|
||||
}
|
||||
@@ -42,17 +42,17 @@ export const NoteBase = memo(function NoteBase({ event }: { event: any }) {
|
||||
{parentNote()}
|
||||
<div className="relative z-10 flex flex-col">
|
||||
<div onClick={(e) => openUserPage(e)}>
|
||||
<UserExtend pubkey={event.pubkey} time={event.createdAt || event.created_at} />
|
||||
<UserExtend pubkey={event.pubkey} time={event.created_at} />
|
||||
</div>
|
||||
<div className="mt-1 pl-[52px]">
|
||||
<div className="whitespace-pre-line break-words text-[15px] leading-tight text-zinc-100">{content}</div>
|
||||
</div>
|
||||
<div onClick={(e) => e.stopPropagation()} className="mt-5 pl-[52px]">
|
||||
<NoteMetadata
|
||||
eventID={event.eventId}
|
||||
eventID={event.event_id}
|
||||
eventPubkey={event.pubkey}
|
||||
eventContent={event.content}
|
||||
eventTime={event.createdAt || event.created_at}
|
||||
eventTime={event.created_at}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -60,7 +60,7 @@ export const NoteComment = memo(function NoteComment({ event }: { event: any })
|
||||
return (
|
||||
<div className="relative z-10 flex h-min min-h-min w-full select-text flex-col border-b border-zinc-800 px-3 py-5 hover:bg-black/20">
|
||||
<div className="relative z-10 flex flex-col">
|
||||
<UserExtend pubkey={event.pubkey} time={event.createdAt || event.created_at} />
|
||||
<UserExtend pubkey={event.pubkey} time={event.created_at} />
|
||||
<div className="-mt-5 pl-[52px]">
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="prose prose-zinc max-w-none break-words text-[15px] leading-tight dark:prose-invert prose-p:m-0 prose-p:text-[15px] prose-p:leading-tight prose-a:font-normal prose-a:text-fuchsia-500 prose-a:no-underline prose-img:m-0 prose-video:m-0">
|
||||
@@ -70,10 +70,10 @@ export const NoteComment = memo(function NoteComment({ event }: { event: any })
|
||||
</div>
|
||||
<div onClick={(e) => e.stopPropagation()} className="mt-5 pl-[52px]">
|
||||
<NoteMetadata
|
||||
eventID={event.eventId}
|
||||
eventID={event.event_id}
|
||||
eventPubkey={event.pubkey}
|
||||
eventContent={event.content}
|
||||
eventTime={event.createdAt || event.created_at}
|
||||
eventTime={event.created_at}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -60,7 +60,7 @@ export const NoteExtend = memo(function NoteExtend({ event }: { event: any }) {
|
||||
return (
|
||||
<div className="relative z-10 flex h-min min-h-min w-full select-text flex-col">
|
||||
<div className="relative z-10 flex flex-col">
|
||||
<UserLarge pubkey={event.pubkey} time={event.createdAt || event.created_at} />
|
||||
<UserLarge pubkey={event.pubkey} time={event.created_at} />
|
||||
<div className="mt-2">
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="prose prose-zinc max-w-none break-words text-[15px] leading-tight dark:prose-invert prose-p:m-0 prose-p:text-[15px] prose-p:leading-tight prose-a:font-normal prose-a:text-fuchsia-500 prose-a:no-underline prose-img:m-0 prose-video:m-0">
|
||||
@@ -70,10 +70,10 @@ export const NoteExtend = memo(function NoteExtend({ event }: { event: any }) {
|
||||
</div>
|
||||
<div className="mt-5 flex items-center border-b border-t border-zinc-800 py-2">
|
||||
<NoteMetadata
|
||||
eventID={event.eventId}
|
||||
eventID={event.event_id}
|
||||
eventPubkey={event.pubkey}
|
||||
eventContent={event.content}
|
||||
eventTime={event.createdAt || event.created_at}
|
||||
eventTime={event.created_at}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -30,7 +30,7 @@ export const NoteComment = ({
|
||||
const [open, setOpen] = useState(false);
|
||||
const [value, setValue] = useState('');
|
||||
|
||||
const [activeAccount]: any = useLocalStorage('activeAccount', {});
|
||||
const [activeAccount]: any = useLocalStorage('account', {});
|
||||
const profile = activeAccount.metadata ? JSON.parse(activeAccount.metadata) : null;
|
||||
|
||||
const openThread = () => {
|
||||
|
||||
@@ -19,7 +19,7 @@ export const NoteReaction = ({
|
||||
eventPubkey: string;
|
||||
}) => {
|
||||
const [pool, relays]: any = useContext(RelayContext);
|
||||
const [activeAccount]: any = useLocalStorage('activeAccount', {});
|
||||
const [activeAccount]: any = useLocalStorage('account', {});
|
||||
|
||||
const [isReact, setIsReact] = useState(false);
|
||||
const [like, setLike] = useState(0);
|
||||
|
||||
@@ -17,7 +17,7 @@ export const NoteMetadata = memo(function NoteMetadata({
|
||||
eventContent: any;
|
||||
}) {
|
||||
const [pool, relays]: any = useContext(RelayContext);
|
||||
const [activeAccount]: any = useLocalStorage('activeAccount', {});
|
||||
const [activeAccount]: any = useLocalStorage('account', {});
|
||||
|
||||
const [liked, setLiked] = useState(false);
|
||||
const [likeCount, setLikeCount] = useState(0);
|
||||
|
||||
@@ -3,6 +3,7 @@ import { RelayContext } from '@components/relaysProvider';
|
||||
import { UserExtend } from '@components/user/extend';
|
||||
|
||||
import { contentParser } from '@utils/parser';
|
||||
import { createNote, getNoteByID } from '@utils/storage';
|
||||
import { getParentID } from '@utils/transform';
|
||||
|
||||
import useLocalStorage from '@rehooks/local-storage';
|
||||
@@ -11,14 +12,13 @@ import { memo, useCallback, useContext, useEffect, useRef, useState } from 'reac
|
||||
export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
|
||||
const [pool, relays]: any = useContext(RelayContext);
|
||||
|
||||
const [activeAccount]: any = useLocalStorage('activeAccount', {});
|
||||
const [activeAccount]: any = useLocalStorage('account', {});
|
||||
const [event, setEvent] = useState(null);
|
||||
const unsubscribe = useRef(null);
|
||||
|
||||
const content = event ? contentParser(event.content, event.tags) : '';
|
||||
|
||||
const fetchEvent = useCallback(async () => {
|
||||
const { createNote } = await import('@utils/bindings');
|
||||
unsubscribe.current = pool.subscribe(
|
||||
[
|
||||
{
|
||||
@@ -33,17 +33,16 @@ export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
|
||||
// insert to database
|
||||
const parentID = getParentID(event.tags, event.id);
|
||||
// insert event to local database
|
||||
createNote({
|
||||
event_id: event.id,
|
||||
pubkey: event.pubkey,
|
||||
kind: event.kind,
|
||||
tags: JSON.stringify(event.tags),
|
||||
content: event.content,
|
||||
parent_id: parentID,
|
||||
parent_comment_id: '',
|
||||
created_at: event.created_at,
|
||||
account_id: activeAccount.id,
|
||||
}).catch(console.error);
|
||||
createNote(
|
||||
event.id,
|
||||
activeAccount.id,
|
||||
event.pubkey,
|
||||
event.kind,
|
||||
event.tags,
|
||||
event.content,
|
||||
event.created_at,
|
||||
parentID
|
||||
);
|
||||
},
|
||||
undefined,
|
||||
undefined,
|
||||
@@ -54,8 +53,7 @@ export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
|
||||
}, [activeAccount.id, id, pool, relays]);
|
||||
|
||||
const checkNoteExist = useCallback(async () => {
|
||||
const { getNoteById } = await import('@utils/bindings');
|
||||
getNoteById({ event_id: id })
|
||||
getNoteByID(id)
|
||||
.then((res) => {
|
||||
if (res) {
|
||||
setEvent(res);
|
||||
@@ -81,16 +79,16 @@ export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
|
||||
<div className="relative pb-5">
|
||||
<div className="absolute left-[21px] top-0 h-full w-0.5 bg-gradient-to-t from-zinc-800 to-zinc-600"></div>
|
||||
<div className="relative z-10 flex flex-col">
|
||||
<UserExtend pubkey={event.pubkey} time={event.createdAt || event.created_at} />
|
||||
<UserExtend pubkey={event.pubkey} time={event.created_at} />
|
||||
<div className="mt-1 pl-[52px]">
|
||||
<div className="whitespace-pre-line break-words text-[15px] leading-tight text-zinc-100">{content}</div>
|
||||
</div>
|
||||
<div onClick={(e) => e.stopPropagation()} className="mt-5 pl-[52px]">
|
||||
<NoteMetadata
|
||||
eventID={event.eventId}
|
||||
eventID={event.event_id}
|
||||
eventPubkey={event.pubkey}
|
||||
eventContent={event.content}
|
||||
eventTime={event.createdAt || event.created_at}
|
||||
eventTime={event.created_at}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -2,6 +2,7 @@ import { RelayContext } from '@components/relaysProvider';
|
||||
import { UserExtend } from '@components/user/extend';
|
||||
|
||||
import { contentParser } from '@utils/parser';
|
||||
import { createNote, getNoteByID } from '@utils/storage';
|
||||
import { getParentID } from '@utils/transform';
|
||||
|
||||
import useLocalStorage from '@rehooks/local-storage';
|
||||
@@ -10,15 +11,13 @@ import { memo, useCallback, useContext, useEffect, useRef, useState } from 'reac
|
||||
export const NoteQuote = memo(function NoteQuote({ id }: { id: string }) {
|
||||
const [pool, relays]: any = useContext(RelayContext);
|
||||
|
||||
const [activeAccount]: any = useLocalStorage('activeAccount', {});
|
||||
const [activeAccount]: any = useLocalStorage('account', {});
|
||||
const [event, setEvent] = useState(null);
|
||||
const unsubscribe = useRef(null);
|
||||
|
||||
const content = event ? contentParser(event.content, event.tags) : '';
|
||||
|
||||
const fetchEvent = useCallback(async () => {
|
||||
const { createNote } = await import('@utils/bindings');
|
||||
|
||||
unsubscribe.current = pool.subscribe(
|
||||
[
|
||||
{
|
||||
@@ -32,18 +31,16 @@ export const NoteQuote = memo(function NoteQuote({ id }: { id: string }) {
|
||||
setEvent(event);
|
||||
// insert to database
|
||||
const parentID = getParentID(event.tags, event.id);
|
||||
// insert event to local database
|
||||
createNote({
|
||||
event_id: event.id,
|
||||
pubkey: event.pubkey,
|
||||
kind: event.kind,
|
||||
tags: JSON.stringify(event.tags),
|
||||
content: event.content,
|
||||
parent_id: parentID,
|
||||
parent_comment_id: '',
|
||||
created_at: event.created_at,
|
||||
account_id: activeAccount.id,
|
||||
}).catch(console.error);
|
||||
createNote(
|
||||
event.id,
|
||||
activeAccount.id,
|
||||
event.pubkey,
|
||||
event.kind,
|
||||
event.tags,
|
||||
event.content,
|
||||
event.created_at,
|
||||
parentID
|
||||
);
|
||||
},
|
||||
undefined,
|
||||
undefined,
|
||||
@@ -54,8 +51,7 @@ export const NoteQuote = memo(function NoteQuote({ id }: { id: string }) {
|
||||
}, [activeAccount.id, id, pool, relays]);
|
||||
|
||||
const checkNoteExist = useCallback(async () => {
|
||||
const { getNoteById } = await import('@utils/bindings');
|
||||
getNoteById({ event_id: id })
|
||||
getNoteByID(id)
|
||||
.then((res) => {
|
||||
if (res) {
|
||||
setEvent(res);
|
||||
@@ -80,7 +76,7 @@ export const NoteQuote = memo(function NoteQuote({ id }: { id: string }) {
|
||||
return (
|
||||
<div className="relative mb-2 mt-3 rounded-lg border border-zinc-700 bg-zinc-800 p-2 py-3">
|
||||
<div className="relative z-10 flex flex-col">
|
||||
<UserExtend pubkey={event.pubkey} time={event.createdAt || event.created_at} />
|
||||
<UserExtend pubkey={event.pubkey} time={event.created_at} />
|
||||
<div className="mt-1 pl-[52px]">
|
||||
<div className="whitespace-pre-line break-words text-[15px] leading-tight text-zinc-100">{content}</div>
|
||||
</div>
|
||||
|
||||
@@ -20,7 +20,7 @@ export const NoteQuoteRepost = memo(function NoteQuoteRepost({ event }: { event:
|
||||
<div className="relative z-10 m-0 flex h-min min-h-min w-full select-text flex-col border-b border-zinc-800 px-3 py-5 hover:bg-black/20">
|
||||
<div className="relative z-10 flex flex-col pb-8">
|
||||
<div className="absolute left-[21px] top-0 h-full w-0.5 bg-gradient-to-t from-zinc-800 to-zinc-600"></div>
|
||||
<UserQuoteRepost pubkey={event.pubkey} time={event.createdAt || event.created_at} />
|
||||
<UserQuoteRepost pubkey={event.pubkey} time={event.created_at} />
|
||||
</div>
|
||||
{rootNote()}
|
||||
</div>
|
||||
|
||||
@@ -16,7 +16,7 @@ const relays = [
|
||||
'wss://relay.current.fyi',
|
||||
'wss://nostr.bitcoiner.social',
|
||||
//'wss://relay.nostr.info',
|
||||
'wss://nostr-01.dorafactory.org',
|
||||
//'wss://nostr-01.dorafactory.org',
|
||||
'wss://nostr.zhongwen.world',
|
||||
'wss://nostro.cc',
|
||||
'wss://relay.nostr.net.in',
|
||||
|
||||
Reference in New Issue
Block a user