mirror of
https://github.com/luminous-devs/lume.git
synced 2024-09-19 11:43:30 +00:00
reuse relayprovider
This commit is contained in:
parent
be8b40c86d
commit
3f06193c59
@ -1,4 +1,5 @@
|
||||
import { AvatarUploader } from '@lume/shared/avatarUploader';
|
||||
import { RelayContext } from '@lume/shared/relayProvider';
|
||||
import { DEFAULT_AVATAR, WRITEONLY_RELAYS } from '@lume/stores/constants';
|
||||
import { dateToUnix } from '@lume/utils/getDate';
|
||||
import { useActiveAccount } from '@lume/utils/hooks/useActiveAccount';
|
||||
@ -6,14 +7,15 @@ import { createChannel } from '@lume/utils/storage';
|
||||
|
||||
import { Dialog, Transition } from '@headlessui/react';
|
||||
import { Cancel, Plus } from 'iconoir-react';
|
||||
import { RelayPool } from 'nostr-relaypool';
|
||||
import { getEventHash, signEvent } from 'nostr-tools';
|
||||
import { Fragment, useEffect, useState } from 'react';
|
||||
import { Fragment, useContext, useEffect, useState } from 'react';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { useSWRConfig } from 'swr';
|
||||
import { navigate } from 'vite-plugin-ssr/client/router';
|
||||
|
||||
export default function ChannelCreateModal() {
|
||||
const pool: any = useContext(RelayContext);
|
||||
|
||||
const { account, isError, isLoading } = useActiveAccount();
|
||||
const { mutate } = useSWRConfig();
|
||||
|
||||
@ -41,7 +43,6 @@ export default function ChannelCreateModal() {
|
||||
setLoading(true);
|
||||
|
||||
if (!isError && !isLoading && account) {
|
||||
const pool = new RelayPool(WRITEONLY_RELAYS);
|
||||
const event: any = {
|
||||
content: JSON.stringify(data),
|
||||
created_at: dateToUnix(),
|
||||
|
@ -1,17 +1,19 @@
|
||||
import UserReply from '@lume/app/channel/components/messages/userReply';
|
||||
import { ImagePicker } from '@lume/shared/form/imagePicker';
|
||||
import { RelayContext } from '@lume/shared/relayProvider';
|
||||
import { channelContentAtom, channelReplyAtom } from '@lume/stores/channel';
|
||||
import { FULL_RELAYS, WRITEONLY_RELAYS } from '@lume/stores/constants';
|
||||
import { WRITEONLY_RELAYS } from '@lume/stores/constants';
|
||||
import { dateToUnix } from '@lume/utils/getDate';
|
||||
import { useActiveAccount } from '@lume/utils/hooks/useActiveAccount';
|
||||
|
||||
import { Cancel } from 'iconoir-react';
|
||||
import { useAtom, useAtomValue } from 'jotai';
|
||||
import { useResetAtom } from 'jotai/utils';
|
||||
import { RelayPool } from 'nostr-relaypool';
|
||||
import { getEventHash, signEvent } from 'nostr-tools';
|
||||
import { useContext } from 'react';
|
||||
|
||||
export default function ChannelMessageForm({ channelID }: { channelID: string | string[] }) {
|
||||
const pool: any = useContext(RelayContext);
|
||||
const { account, isLoading, isError } = useActiveAccount();
|
||||
|
||||
const [value, setValue] = useAtom(channelContentAtom);
|
||||
@ -34,7 +36,6 @@ export default function ChannelMessageForm({ channelID }: { channelID: string |
|
||||
}
|
||||
|
||||
if (!isError && !isLoading && account) {
|
||||
const pool = new RelayPool(WRITEONLY_RELAYS);
|
||||
const event: any = {
|
||||
content: value,
|
||||
created_at: dateToUnix(),
|
||||
@ -46,7 +47,7 @@ export default function ChannelMessageForm({ channelID }: { channelID: string |
|
||||
event.sig = signEvent(event, account.privkey);
|
||||
|
||||
// publish note
|
||||
pool.publish(event, FULL_RELAYS);
|
||||
pool.publish(event, WRITEONLY_RELAYS);
|
||||
// reset state
|
||||
resetValue();
|
||||
// reset channel reply
|
||||
|
@ -1,18 +1,19 @@
|
||||
import { RelayContext } from '@lume/shared/relayProvider';
|
||||
import Tooltip from '@lume/shared/tooltip';
|
||||
import { WRITEONLY_RELAYS } from '@lume/stores/constants';
|
||||
import { dateToUnix } from '@lume/utils/getDate';
|
||||
import { useActiveAccount } from '@lume/utils/hooks/useActiveAccount';
|
||||
|
||||
import { EyeClose } from 'iconoir-react';
|
||||
import { RelayPool } from 'nostr-relaypool';
|
||||
import { getEventHash, signEvent } from 'nostr-tools';
|
||||
import { useContext } from 'react';
|
||||
|
||||
export default function MessageHideButton({ id }: { id: string }) {
|
||||
const pool: any = useContext(RelayContext);
|
||||
const { account, isError, isLoading } = useActiveAccount();
|
||||
|
||||
const hideMessage = () => {
|
||||
if (!isError && !isLoading && account) {
|
||||
const pool = new RelayPool(WRITEONLY_RELAYS);
|
||||
const event: any = {
|
||||
content: '',
|
||||
created_at: dateToUnix(),
|
||||
|
@ -1,18 +1,19 @@
|
||||
import { RelayContext } from '@lume/shared/relayProvider';
|
||||
import Tooltip from '@lume/shared/tooltip';
|
||||
import { WRITEONLY_RELAYS } from '@lume/stores/constants';
|
||||
import { dateToUnix } from '@lume/utils/getDate';
|
||||
import { useActiveAccount } from '@lume/utils/hooks/useActiveAccount';
|
||||
|
||||
import { MicMute } from 'iconoir-react';
|
||||
import { RelayPool } from 'nostr-relaypool';
|
||||
import { getEventHash, signEvent } from 'nostr-tools';
|
||||
import { useContext } from 'react';
|
||||
|
||||
export default function MessageMuteButton({ pubkey }: { pubkey: string }) {
|
||||
const pool: any = useContext(RelayContext);
|
||||
const { account, isError, isLoading } = useActiveAccount();
|
||||
|
||||
const muteUser = () => {
|
||||
if (!isError && !isLoading && account) {
|
||||
const pool = new RelayPool(WRITEONLY_RELAYS);
|
||||
const event: any = {
|
||||
content: '',
|
||||
created_at: dateToUnix(),
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { AvatarUploader } from '@lume/shared/avatarUploader';
|
||||
import { RelayContext } from '@lume/shared/relayProvider';
|
||||
import { DEFAULT_AVATAR, WRITEONLY_RELAYS } from '@lume/stores/constants';
|
||||
import { dateToUnix } from '@lume/utils/getDate';
|
||||
import { useActiveAccount } from '@lume/utils/hooks/useActiveAccount';
|
||||
@ -6,12 +7,12 @@ import { getChannel, updateChannelMetadata } from '@lume/utils/storage';
|
||||
|
||||
import { Dialog, Transition } from '@headlessui/react';
|
||||
import { Cancel, EditPencil } from 'iconoir-react';
|
||||
import { RelayPool } from 'nostr-relaypool';
|
||||
import { getEventHash, signEvent } from 'nostr-tools';
|
||||
import { Fragment, useEffect, useState } from 'react';
|
||||
import { Fragment, useContext, useEffect, useState } from 'react';
|
||||
import { useForm } from 'react-hook-form';
|
||||
|
||||
export default function ChannelUpdateModal({ id }: { id: string }) {
|
||||
const pool: any = useContext(RelayContext);
|
||||
const { account, isError, isLoading } = useActiveAccount();
|
||||
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
@ -47,7 +48,6 @@ export default function ChannelUpdateModal({ id }: { id: string }) {
|
||||
setLoading(true);
|
||||
|
||||
if (!isError && !isLoading && account) {
|
||||
const pool = new RelayPool(WRITEONLY_RELAYS);
|
||||
const event: any = {
|
||||
content: JSON.stringify(data),
|
||||
created_at: dateToUnix(),
|
||||
|
@ -10,7 +10,7 @@ export function LayoutChannel({ children }: { children: React.ReactNode }) {
|
||||
data-tauri-drag-region
|
||||
className="relative h-11 shrink-0 border-b border-zinc-100 bg-white dark:border-zinc-900 dark:bg-black"
|
||||
>
|
||||
<AppHeader collector={true} />
|
||||
<AppHeader />
|
||||
</div>
|
||||
<div className="relative flex min-h-0 w-full flex-1">
|
||||
<div className="relative w-[68px] shrink-0 border-r border-zinc-900">
|
||||
|
@ -3,8 +3,9 @@ import ChannelMembers from '@lume/app/channel/components/members';
|
||||
import ChannelMessageForm from '@lume/app/channel/components/messages/form';
|
||||
import ChannelMetadata from '@lume/app/channel/components/metadata';
|
||||
import ChannelUpdateModal from '@lume/app/channel/components/updateModal';
|
||||
import { RelayContext } from '@lume/shared/relayProvider';
|
||||
import { channelMessagesAtom, channelReplyAtom } from '@lume/stores/channel';
|
||||
import { FULL_RELAYS } from '@lume/stores/constants';
|
||||
import { READONLY_RELAYS } from '@lume/stores/constants';
|
||||
import { dateToUnix, hoursAgo } from '@lume/utils/getDate';
|
||||
import { useActiveAccount } from '@lume/utils/hooks/useActiveAccount';
|
||||
import { usePageContext } from '@lume/utils/hooks/usePageContext';
|
||||
@ -12,8 +13,7 @@ import { arrayObjToPureArr } from '@lume/utils/transform';
|
||||
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { useResetAtom } from 'jotai/utils';
|
||||
import { RelayPool } from 'nostr-relaypool';
|
||||
import { Suspense, lazy, useEffect, useRef } from 'react';
|
||||
import { Suspense, lazy, useContext, useEffect, useRef } from 'react';
|
||||
import useSWRSubscription from 'swr/subscription';
|
||||
|
||||
let mutedList: any = [];
|
||||
@ -31,6 +31,7 @@ if (typeof window !== 'undefined') {
|
||||
const ChannelMessageList = lazy(() => import('@lume/app/channel/components/messageList'));
|
||||
|
||||
export function Page() {
|
||||
const pool: any = useContext(RelayContext);
|
||||
const pageContext = usePageContext();
|
||||
const searchParams: any = pageContext.urlParsed.search;
|
||||
|
||||
@ -49,7 +50,6 @@ export function Page() {
|
||||
|
||||
useSWRSubscription(channelID ? ['channel', channelID] : null, ([, key], {}: any) => {
|
||||
// subscribe to channel
|
||||
const pool = new RelayPool(FULL_RELAYS);
|
||||
const unsubscribe = pool.subscribe(
|
||||
[
|
||||
{
|
||||
@ -59,8 +59,8 @@ export function Page() {
|
||||
limit: 20,
|
||||
},
|
||||
],
|
||||
FULL_RELAYS,
|
||||
(event) => {
|
||||
READONLY_RELAYS,
|
||||
(event: { id: string; pubkey: string }) => {
|
||||
const message: any = event;
|
||||
if (hided.includes(event.id)) {
|
||||
message['hide'] = true;
|
||||
|
@ -1,16 +1,17 @@
|
||||
import { ImagePicker } from '@lume/shared/form/imagePicker';
|
||||
import { RelayContext } from '@lume/shared/relayProvider';
|
||||
import { chatContentAtom } from '@lume/stores/chat';
|
||||
import { FULL_RELAYS, WRITEONLY_RELAYS } from '@lume/stores/constants';
|
||||
import { WRITEONLY_RELAYS } from '@lume/stores/constants';
|
||||
import { dateToUnix } from '@lume/utils/getDate';
|
||||
import { useActiveAccount } from '@lume/utils/hooks/useActiveAccount';
|
||||
|
||||
import { useAtom } from 'jotai';
|
||||
import { useResetAtom } from 'jotai/utils';
|
||||
import { RelayPool } from 'nostr-relaypool';
|
||||
import { getEventHash, nip04, signEvent } from 'nostr-tools';
|
||||
import { useCallback } from 'react';
|
||||
import { useCallback, useContext } from 'react';
|
||||
|
||||
export default function ChatMessageForm({ receiverPubkey }: { receiverPubkey: string }) {
|
||||
const pool: any = useContext(RelayContext);
|
||||
const { account, isLoading, isError } = useActiveAccount();
|
||||
|
||||
const [value, setValue] = useAtom(chatContentAtom);
|
||||
@ -27,7 +28,6 @@ export default function ChatMessageForm({ receiverPubkey }: { receiverPubkey: st
|
||||
if (!isError && !isLoading && account) {
|
||||
encryptMessage(account.privkey)
|
||||
.then((encryptedContent) => {
|
||||
const pool = new RelayPool(WRITEONLY_RELAYS);
|
||||
const event: any = {
|
||||
content: encryptedContent,
|
||||
created_at: dateToUnix(),
|
||||
@ -38,7 +38,7 @@ export default function ChatMessageForm({ receiverPubkey }: { receiverPubkey: st
|
||||
event.id = getEventHash(event);
|
||||
event.sig = signEvent(event, account.privkey);
|
||||
// publish note
|
||||
pool.publish(event, FULL_RELAYS);
|
||||
pool.publish(event, WRITEONLY_RELAYS);
|
||||
// reset state
|
||||
resetValue();
|
||||
})
|
||||
|
@ -10,7 +10,7 @@ export function LayoutChat({ children }: { children: React.ReactNode }) {
|
||||
data-tauri-drag-region
|
||||
className="relative h-11 shrink-0 border-b border-zinc-100 bg-white dark:border-zinc-900 dark:bg-black"
|
||||
>
|
||||
<AppHeader collector={true} />
|
||||
<AppHeader />
|
||||
</div>
|
||||
<div className="relative flex min-h-0 w-full flex-1">
|
||||
<div className="relative w-[68px] shrink-0 border-r border-zinc-900">
|
||||
|
@ -1,18 +1,19 @@
|
||||
import ChatMessageForm from '@lume/app/chat/components/messages/form';
|
||||
import { RelayContext } from '@lume/shared/relayProvider';
|
||||
import { chatMessagesAtom } from '@lume/stores/chat';
|
||||
import { FULL_RELAYS } from '@lume/stores/constants';
|
||||
import { READONLY_RELAYS } from '@lume/stores/constants';
|
||||
import { useActiveAccount } from '@lume/utils/hooks/useActiveAccount';
|
||||
import { usePageContext } from '@lume/utils/hooks/usePageContext';
|
||||
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { useResetAtom } from 'jotai/utils';
|
||||
import { RelayPool } from 'nostr-relaypool';
|
||||
import { Suspense, lazy, useEffect } from 'react';
|
||||
import { Suspense, lazy, useContext, useEffect } from 'react';
|
||||
import useSWRSubscription from 'swr/subscription';
|
||||
|
||||
const ChatMessageList = lazy(() => import('@lume/app/chat/components/messageList'));
|
||||
|
||||
export function Page() {
|
||||
const pool: any = useContext(RelayContext);
|
||||
const pageContext = usePageContext();
|
||||
const searchParams: any = pageContext.urlParsed.search;
|
||||
|
||||
@ -24,7 +25,6 @@ export function Page() {
|
||||
const resetChatMessages = useResetAtom(chatMessagesAtom);
|
||||
|
||||
useSWRSubscription(pubkey ? ['chat', pubkey] : null, ([, key], {}: any) => {
|
||||
const pool = new RelayPool(FULL_RELAYS);
|
||||
const unsubscribe = pool.subscribe(
|
||||
[
|
||||
{
|
||||
@ -40,7 +40,7 @@ export function Page() {
|
||||
limit: 20,
|
||||
},
|
||||
],
|
||||
FULL_RELAYS,
|
||||
READONLY_RELAYS,
|
||||
(event: any) => {
|
||||
setChatMessages((prev) => [...prev, event]);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import LumeIcon from '@lume/shared/icons/lume';
|
||||
import { FULL_RELAYS } from '@lume/stores/constants';
|
||||
import { RelayContext } from '@lume/shared/relayProvider';
|
||||
import { READONLY_RELAYS } from '@lume/stores/constants';
|
||||
import { dateToUnix, hoursAgo } from '@lume/utils/getDate';
|
||||
import {
|
||||
addToBlacklist,
|
||||
@ -12,11 +13,11 @@ import {
|
||||
} from '@lume/utils/storage';
|
||||
import { getParentID, nip02ToArray } from '@lume/utils/transform';
|
||||
|
||||
import { RelayPool } from 'nostr-relaypool';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { useContext, useEffect, useRef } from 'react';
|
||||
import { navigate } from 'vite-plugin-ssr/client/router';
|
||||
|
||||
export function Page() {
|
||||
const pool: any = useContext(RelayContext);
|
||||
const now = useRef(new Date());
|
||||
|
||||
useEffect(() => {
|
||||
@ -28,7 +29,6 @@ export function Page() {
|
||||
const lastLogin = await getLastLogin();
|
||||
const notes = await countTotalNotes();
|
||||
|
||||
const pool = new RelayPool(FULL_RELAYS);
|
||||
const follows = nip02ToArray(JSON.parse(account.follows));
|
||||
const query = [];
|
||||
|
||||
@ -71,7 +71,7 @@ export function Page() {
|
||||
// subscribe relays
|
||||
unsubscribe = pool.subscribe(
|
||||
query,
|
||||
FULL_RELAYS,
|
||||
READONLY_RELAYS,
|
||||
(event: any) => {
|
||||
switch (event.kind) {
|
||||
// short text note
|
||||
@ -140,7 +140,7 @@ export function Page() {
|
||||
}
|
||||
clearTimeout(timeout);
|
||||
};
|
||||
}, []);
|
||||
}, [pool]);
|
||||
|
||||
return (
|
||||
<div className="h-screen w-screen bg-zinc-50 text-zinc-900 dark:bg-black dark:text-white">
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { ImagePicker } from '@lume/shared/form/imagePicker';
|
||||
import { RelayContext } from '@lume/shared/relayProvider';
|
||||
import { WRITEONLY_RELAYS } from '@lume/stores/constants';
|
||||
import { noteContentAtom } from '@lume/stores/note';
|
||||
import { dateToUnix } from '@lume/utils/getDate';
|
||||
@ -6,17 +7,17 @@ import { useActiveAccount } from '@lume/utils/hooks/useActiveAccount';
|
||||
|
||||
import { useAtom } from 'jotai';
|
||||
import { useResetAtom } from 'jotai/utils';
|
||||
import { RelayPool } from 'nostr-relaypool';
|
||||
import { getEventHash, signEvent } from 'nostr-tools';
|
||||
import { useContext } from 'react';
|
||||
|
||||
export default function NoteForm() {
|
||||
const pool: any = useContext(RelayContext);
|
||||
const { account, isLoading, isError } = useActiveAccount();
|
||||
const [value, setValue] = useAtom(noteContentAtom);
|
||||
const resetValue = useResetAtom(noteContentAtom);
|
||||
|
||||
const submitEvent = () => {
|
||||
if (!isLoading && !isError && account) {
|
||||
const pool = new RelayPool(WRITEONLY_RELAYS);
|
||||
const event: any = {
|
||||
content: value,
|
||||
created_at: dateToUnix(),
|
||||
|
@ -1,14 +1,15 @@
|
||||
import { contentParser } from '@lume/app/newsfeed/components/contentParser';
|
||||
import { NoteDefaultUser } from '@lume/app/newsfeed/components/user/default';
|
||||
import { RelayContext } from '@lume/shared/relayProvider';
|
||||
import { READONLY_RELAYS } from '@lume/stores/constants';
|
||||
|
||||
import { RelayPool } from 'nostr-relaypool';
|
||||
import { memo } from 'react';
|
||||
import { memo, useContext } from 'react';
|
||||
import useSWRSubscription from 'swr/subscription';
|
||||
|
||||
export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
|
||||
const pool: any = useContext(RelayContext);
|
||||
|
||||
const { data, error } = useSWRSubscription(id ? id : null, (key, { next }) => {
|
||||
const pool = new RelayPool(READONLY_RELAYS);
|
||||
const unsubscribe = pool.subscribe(
|
||||
[
|
||||
{
|
||||
|
@ -1,41 +1,36 @@
|
||||
import { contentParser } from '@lume/app/newsfeed/components/contentParser';
|
||||
import { NoteDefaultUser } from '@lume/app/newsfeed/components/user/default';
|
||||
import { RelayContext } from '@lume/shared/relayProvider';
|
||||
import { READONLY_RELAYS } from '@lume/stores/constants';
|
||||
|
||||
import { RelayPool } from 'nostr-relaypool';
|
||||
import { memo } from 'react';
|
||||
import { memo, useContext } from 'react';
|
||||
import useSWRSubscription from 'swr/subscription';
|
||||
|
||||
export const NoteQuote = memo(function NoteQuote({ id }: { id: string }) {
|
||||
const { data, error } = useSWRSubscription(
|
||||
id
|
||||
? [
|
||||
{
|
||||
ids: [id],
|
||||
kinds: [1],
|
||||
},
|
||||
]
|
||||
: null,
|
||||
(key, { next }) => {
|
||||
const pool = new RelayPool(READONLY_RELAYS);
|
||||
const unsubscribe = pool.subscribe(
|
||||
key,
|
||||
READONLY_RELAYS,
|
||||
(event: any) => {
|
||||
next(null, event);
|
||||
},
|
||||
undefined,
|
||||
undefined,
|
||||
{
|
||||
unsubscribeOnEose: true,
|
||||
}
|
||||
);
|
||||
const pool: any = useContext(RelayContext);
|
||||
|
||||
return () => {
|
||||
unsubscribe();
|
||||
};
|
||||
}
|
||||
);
|
||||
const { data, error } = useSWRSubscription(id ? id : null, (key, { next }) => {
|
||||
const unsubscribe = pool.subscribe(
|
||||
[
|
||||
{
|
||||
ids: [key],
|
||||
},
|
||||
],
|
||||
READONLY_RELAYS,
|
||||
(event: any) => {
|
||||
next(null, event);
|
||||
},
|
||||
undefined,
|
||||
undefined,
|
||||
{
|
||||
unsubscribeOnEose: true,
|
||||
}
|
||||
);
|
||||
|
||||
return () => {
|
||||
unsubscribe();
|
||||
};
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="relative mb-2 mt-3 rounded-lg border border-zinc-700 bg-zinc-800 p-2 py-3">
|
||||
|
@ -1,17 +1,17 @@
|
||||
import { contentParser } from '@lume/app/newsfeed/components/contentParser';
|
||||
import { NoteDefaultUser } from '@lume/app/newsfeed/components/user/default';
|
||||
import { RelayContext } from '@lume/shared/relayProvider';
|
||||
import { READONLY_RELAYS } from '@lume/stores/constants';
|
||||
|
||||
import { RelayPool } from 'nostr-relaypool';
|
||||
import { memo } from 'react';
|
||||
import { memo, useContext } from 'react';
|
||||
import useSWRSubscription from 'swr/subscription';
|
||||
import { navigate } from 'vite-plugin-ssr/client/router';
|
||||
|
||||
export const RootNote = memo(function RootNote({ id, fallback }: { id: string; fallback?: any }) {
|
||||
const pool: any = useContext(RelayContext);
|
||||
const parseFallback = fallback.length > 0 ? JSON.parse(fallback) : null;
|
||||
|
||||
const { data, error } = useSWRSubscription(parseFallback ? null : id, (key, { next }) => {
|
||||
const pool = new RelayPool(READONLY_RELAYS);
|
||||
const unsubscribe = pool.subscribe(
|
||||
[
|
||||
{
|
||||
|
@ -10,7 +10,7 @@ export function LayoutNewsfeed({ children }: { children: React.ReactNode }) {
|
||||
data-tauri-drag-region
|
||||
className="relative h-11 shrink-0 border-b border-zinc-100 bg-white dark:border-zinc-900 dark:bg-black"
|
||||
>
|
||||
<AppHeader collector={true} />
|
||||
<AppHeader />
|
||||
</div>
|
||||
<div className="relative flex min-h-0 w-full flex-1">
|
||||
<div className="relative w-[68px] shrink-0 border-r border-zinc-900">
|
||||
|
@ -1,4 +1,5 @@
|
||||
import User from '@lume/auth/components/user';
|
||||
import { RelayContext } from '@lume/shared/relayProvider';
|
||||
import { WRITEONLY_RELAYS } from '@lume/stores/constants';
|
||||
import { onboardingAtom } from '@lume/stores/onboarding';
|
||||
import { createAccount, createPleb } from '@lume/utils/storage';
|
||||
@ -6,9 +7,8 @@ import { arrayToNIP02 } from '@lume/utils/transform';
|
||||
|
||||
import { CheckCircle } from 'iconoir-react';
|
||||
import { useAtom } from 'jotai';
|
||||
import { RelayPool } from 'nostr-relaypool';
|
||||
import { getEventHash, signEvent } from 'nostr-tools';
|
||||
import { useState } from 'react';
|
||||
import { useContext, useState } from 'react';
|
||||
import { navigate } from 'vite-plugin-ssr/client/router';
|
||||
|
||||
const initialList = [
|
||||
@ -47,6 +47,8 @@ const initialList = [
|
||||
];
|
||||
|
||||
export function Page() {
|
||||
const pool: any = useContext(RelayContext);
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [follows, setFollows] = useState([]);
|
||||
const [onboarding] = useAtom(onboardingAtom);
|
||||
@ -58,7 +60,6 @@ export function Page() {
|
||||
};
|
||||
|
||||
const broadcastAccount = () => {
|
||||
const pool = new RelayPool(WRITEONLY_RELAYS);
|
||||
// build event
|
||||
const event: any = {
|
||||
content: JSON.stringify(onboarding.metadata),
|
||||
@ -74,7 +75,6 @@ export function Page() {
|
||||
};
|
||||
|
||||
const broadcastContacts = () => {
|
||||
const pool = new RelayPool(WRITEONLY_RELAYS);
|
||||
const nip02 = arrayToNIP02(follows);
|
||||
// build event
|
||||
const event: any = {
|
||||
|
@ -1,33 +1,32 @@
|
||||
import { DEFAULT_AVATAR, READONLY_RELAYS } from '@lume/stores/constants';
|
||||
import { RelayContext } from '@lume/shared/relayProvider';
|
||||
import { DEFAULT_AVATAR } from '@lume/stores/constants';
|
||||
import { onboardingAtom } from '@lume/stores/onboarding';
|
||||
import { shortenKey } from '@lume/utils/shortenKey';
|
||||
import { createAccount, createPleb } from '@lume/utils/storage';
|
||||
|
||||
import { useAtom } from 'jotai';
|
||||
import { RelayPool } from 'nostr-relaypool';
|
||||
import { getPublicKey } from 'nostr-tools';
|
||||
import { useMemo, useState } from 'react';
|
||||
import { useContext, useMemo, useState } from 'react';
|
||||
import useSWRSubscription from 'swr/subscription';
|
||||
import { navigate } from 'vite-plugin-ssr/client/router';
|
||||
|
||||
export function Page() {
|
||||
const pool: any = useContext(RelayContext);
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [onboarding, setOnboarding] = useAtom(onboardingAtom);
|
||||
const pubkey = useMemo(() => (onboarding.privkey ? getPublicKey(onboarding.privkey) : ''), [onboarding.privkey]);
|
||||
|
||||
const { data: user, error } = useSWRSubscription(
|
||||
pubkey && !loading
|
||||
? [
|
||||
{
|
||||
kinds: [0, 3],
|
||||
authors: [pubkey],
|
||||
},
|
||||
]
|
||||
: null,
|
||||
(key, { next }) => {
|
||||
const pool = new RelayPool(READONLY_RELAYS);
|
||||
|
||||
const unsubscribe = pool.subscribe(key, READONLY_RELAYS, (event: any) => {
|
||||
const { data: user, error } = useSWRSubscription(pubkey && !loading ? pubkey : null, (key, { next }) => {
|
||||
const unsubscribe = pool.subscribe(
|
||||
[
|
||||
{
|
||||
kinds: [0, 3],
|
||||
authors: [key],
|
||||
},
|
||||
],
|
||||
null,
|
||||
(event: any) => {
|
||||
switch (event.kind) {
|
||||
case 0:
|
||||
// update state
|
||||
@ -41,13 +40,13 @@ export function Page() {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
return () => {
|
||||
unsubscribe();
|
||||
};
|
||||
}
|
||||
);
|
||||
return () => {
|
||||
unsubscribe();
|
||||
};
|
||||
});
|
||||
|
||||
const submit = () => {
|
||||
// show loading indicator
|
||||
|
@ -1,4 +1,4 @@
|
||||
import AccountProvider from '@lume/shared/accountProvider';
|
||||
import RelayProvider from '@lume/shared/relayProvider';
|
||||
import { PageContextProvider } from '@lume/utils/hooks/usePageContext';
|
||||
|
||||
import { PageContext } from '@renderer/types';
|
||||
@ -14,9 +14,9 @@ export function Shell({ children, pageContext }: { children: React.ReactNode; pa
|
||||
return (
|
||||
<PageContextProvider pageContext={pageContext}>
|
||||
<Layout>
|
||||
<AccountProvider>
|
||||
<RelayProvider>
|
||||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
||||
</AccountProvider>
|
||||
</RelayProvider>
|
||||
</Layout>
|
||||
</PageContextProvider>
|
||||
);
|
||||
|
@ -1,14 +0,0 @@
|
||||
import { createContext } from 'react';
|
||||
|
||||
export const AccountContext = createContext({});
|
||||
|
||||
let activeAccount: any = { id: '', pubkey: '', follows: null, metadata: {} };
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
const { getActiveAccount } = await import('@lume/utils/storage');
|
||||
activeAccount = await getActiveAccount();
|
||||
}
|
||||
|
||||
export default function AccountProvider({ children }: { children: React.ReactNode }) {
|
||||
return <AccountContext.Provider value={activeAccount}>{children}</AccountContext.Provider>;
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
import EventCollector from '@lume/shared/eventCollector';
|
||||
|
||||
import { ArrowLeft, ArrowRight, Refresh } from 'iconoir-react';
|
||||
|
||||
let platformName = 'darwin';
|
||||
@ -9,7 +7,7 @@ if (typeof window !== 'undefined') {
|
||||
platformName = await platform();
|
||||
}
|
||||
|
||||
export default function AppHeader({ collector }: { collector: boolean }) {
|
||||
export default function AppHeader() {
|
||||
const goBack = () => {
|
||||
window.history.back();
|
||||
};
|
||||
@ -46,7 +44,6 @@ export default function AppHeader({ collector }: { collector: boolean }) {
|
||||
</div>
|
||||
<div data-tauri-drag-region className="flex h-full w-full items-center justify-between">
|
||||
<div className="flex h-full items-center divide-x divide-zinc-900 px-4 pt-px"></div>
|
||||
{collector && <EventCollector />}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { NetworkStatusIndicator } from '@lume/shared/networkStatusIndicator';
|
||||
import { RelayContext } from '@lume/shared/relayProvider';
|
||||
import { READONLY_RELAYS } from '@lume/stores/constants';
|
||||
import { hasNewerNoteAtom } from '@lume/stores/note';
|
||||
import { dateToUnix } from '@lume/utils/getDate';
|
||||
@ -7,20 +8,19 @@ import { createChat, createNote, updateAccount } from '@lume/utils/storage';
|
||||
import { getParentID, nip02ToArray } from '@lume/utils/transform';
|
||||
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { RelayPool } from 'nostr-relaypool';
|
||||
import { useRef } from 'react';
|
||||
import { useContext, useRef } from 'react';
|
||||
import useSWRSubscription from 'swr/subscription';
|
||||
|
||||
export default function EventCollector() {
|
||||
const pool: any = useContext(RelayContext);
|
||||
|
||||
const setHasNewerNote = useSetAtom(hasNewerNoteAtom);
|
||||
const now = useRef(new Date());
|
||||
|
||||
const { account, isLoading, isError } = useActiveAccount();
|
||||
|
||||
useSWRSubscription(!isLoading && !isError ? account : null, () => {
|
||||
const follows = nip02ToArray(JSON.parse(account.follows));
|
||||
|
||||
const pool = new RelayPool(READONLY_RELAYS);
|
||||
useSWRSubscription(!isLoading && !isError && account ? ['eventCollector', account] : null, ([, key], {}) => {
|
||||
const follows = nip02ToArray(JSON.parse(key.follows));
|
||||
const unsubscribe = pool.subscribe(
|
||||
[
|
||||
{
|
||||
@ -30,11 +30,11 @@ export default function EventCollector() {
|
||||
},
|
||||
{
|
||||
kinds: [0, 3],
|
||||
authors: [account.pubkey],
|
||||
authors: [key.pubkey],
|
||||
},
|
||||
{
|
||||
kinds: [4],
|
||||
'#p': [account.pubkey],
|
||||
'#p': [key.pubkey],
|
||||
since: dateToUnix(now.current),
|
||||
},
|
||||
],
|
||||
@ -68,15 +68,15 @@ export default function EventCollector() {
|
||||
break;
|
||||
// chat
|
||||
case 4:
|
||||
if (event.pubkey !== account.pubkey) {
|
||||
createChat(account.id, event.pubkey, event.created_at);
|
||||
if (event.pubkey !== key.pubkey) {
|
||||
createChat(key.id, event.pubkey, event.created_at);
|
||||
}
|
||||
break;
|
||||
// repost
|
||||
case 6:
|
||||
createNote(
|
||||
event.id,
|
||||
account.id,
|
||||
key.id,
|
||||
event.pubkey,
|
||||
event.kind,
|
||||
event.tags,
|
||||
|
@ -1,20 +1,19 @@
|
||||
import { RelayContext } from '@lume/shared/relayProvider';
|
||||
import { WRITEONLY_RELAYS } from '@lume/stores/constants';
|
||||
import { dateToUnix } from '@lume/utils/getDate';
|
||||
import { useActiveAccount } from '@lume/utils/hooks/useActiveAccount';
|
||||
|
||||
import { RelayPool } from 'nostr-relaypool';
|
||||
import { getEventHash, signEvent } from 'nostr-tools';
|
||||
import { useState } from 'react';
|
||||
import { useContext, useState } from 'react';
|
||||
|
||||
export default function FormComment({ eventID }: { eventID: any }) {
|
||||
const pool: any = useContext(RelayContext);
|
||||
const { account } = useActiveAccount();
|
||||
|
||||
const [value, setValue] = useState('');
|
||||
|
||||
const profile = JSON.parse(account.metadata);
|
||||
|
||||
const submitEvent = () => {
|
||||
const pool = new RelayPool(WRITEONLY_RELAYS);
|
||||
const event: any = {
|
||||
content: value,
|
||||
created_at: dateToUnix(),
|
||||
|
17
src/shared/relayProvider.tsx
Normal file
17
src/shared/relayProvider.tsx
Normal file
@ -0,0 +1,17 @@
|
||||
import { FULL_RELAYS } from '@lume/stores/constants';
|
||||
|
||||
import { RelayPool } from 'nostr-relaypool';
|
||||
import { createContext } from 'react';
|
||||
|
||||
export const RelayContext = createContext({});
|
||||
|
||||
const pool = new RelayPool(FULL_RELAYS, {
|
||||
useEventCache: false,
|
||||
subscriptionCache: true,
|
||||
logErrorsAndNotices: false,
|
||||
logSubscriptions: false,
|
||||
});
|
||||
|
||||
export default function RelayProvider({ children }: { children: React.ReactNode }) {
|
||||
return <RelayContext.Provider value={pool}>{children}</RelayContext.Provider>;
|
||||
}
|
@ -15,18 +15,12 @@ export const METADATA_SERVICE = 'https://us.rbr.bio';
|
||||
export const READONLY_RELAYS = ['wss://welcome.nostr.wine', 'wss://relay.nostr.band'];
|
||||
|
||||
// write-only relay list
|
||||
export const WRITEONLY_RELAYS = ['wss://nostr.mutinywallet.com', 'wss://relay.nostr.band'];
|
||||
export const WRITEONLY_RELAYS = ['wss://nostr.mutinywallet.com', 'wss://relay.nostr.band', 'wss://relay.damus.io'];
|
||||
|
||||
// full-relay list, used for inital page and chat/channel messages loading
|
||||
export const FULL_RELAYS = [
|
||||
'wss://welcome.nostr.wine',
|
||||
'wss://relay.nostr.band',
|
||||
'wss://nostr.mutinywallet.com',
|
||||
'wss://relay.damus.io',
|
||||
'wss://nos.lol',
|
||||
'wss://nostr.mom',
|
||||
'wss://relay.plebstr.com',
|
||||
'wss://nostr-pub.wellorder.net',
|
||||
'wss://nostr.zebedee.cloud',
|
||||
'wss://nostr.fmt.wiz.biz',
|
||||
'wss://relay.snort.social',
|
||||
'wss://offchain.pub',
|
||||
'wss://relay.current.fyi',
|
||||
];
|
||||
|
@ -1,15 +1,15 @@
|
||||
import { RelayContext } from '@lume/shared/relayProvider';
|
||||
import { READONLY_RELAYS } from '@lume/stores/constants';
|
||||
import { updateChannelMetadata } from '@lume/utils/storage';
|
||||
import { getChannel } from '@lume/utils/storage';
|
||||
|
||||
import { RelayPool } from 'nostr-relaypool';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { useCallback, useContext, useEffect, useState } from 'react';
|
||||
|
||||
export const useChannelMetadata = (id: string, channelPubkey: string) => {
|
||||
const pool: any = useContext(RelayContext);
|
||||
const [metadata, setMetadata] = useState(null);
|
||||
|
||||
const fetchFromRelay = useCallback(() => {
|
||||
const pool = new RelayPool(READONLY_RELAYS);
|
||||
const unsubscribe = pool.subscribe(
|
||||
[
|
||||
{
|
||||
|
@ -1,11 +1,13 @@
|
||||
import { FULL_RELAYS } from '@lume/stores/constants';
|
||||
import { RelayContext } from '@lume/shared/relayProvider';
|
||||
import { READONLY_RELAYS } from '@lume/stores/constants';
|
||||
|
||||
import { RelayPool } from 'nostr-relaypool';
|
||||
import { useContext } from 'react';
|
||||
import useSWRSubscription from 'swr/subscription';
|
||||
|
||||
export const useChannelProfile = (id: string, channelPubkey: string) => {
|
||||
const pool: any = useContext(RelayContext);
|
||||
|
||||
const { data } = useSWRSubscription(id ? id : null, (key, { next }) => {
|
||||
const pool = new RelayPool(FULL_RELAYS);
|
||||
const unsubscribe = pool.subscribe(
|
||||
[
|
||||
{
|
||||
@ -17,7 +19,7 @@ export const useChannelProfile = (id: string, channelPubkey: string) => {
|
||||
kinds: [40],
|
||||
},
|
||||
],
|
||||
FULL_RELAYS,
|
||||
READONLY_RELAYS,
|
||||
(event: { kind: number; pubkey: string; content: string }) => {
|
||||
switch (event.kind) {
|
||||
case 40:
|
||||
|
Loading…
Reference in New Issue
Block a user