update relay list

This commit is contained in:
Ren Amamiya
2023-04-25 15:24:11 +07:00
parent 95e4a27b69
commit 01dff9f3c8
29 changed files with 77 additions and 118 deletions

View File

@@ -20,8 +20,12 @@ export const ChannelListItem = ({ data }: { data: any }) => {
pageID === data.event_id ? 'dark:bg-zinc-900 dark:text-zinc-100 hover:dark:bg-zinc-800' : '' pageID === data.event_id ? 'dark:bg-zinc-900 dark:text-zinc-100 hover:dark:bg-zinc-800' : ''
)} )}
> >
<div className="relative h-5 w-5 shrink-0 rounded bg-zinc-900"> <div className="relative h-5 w-5 shrink-0 rounded">
<img src={channel?.picture || DEFAULT_AVATAR} alt={data.event_id} className="h-5 w-5 rounded object-contain" /> <img
src={channel?.picture || DEFAULT_AVATAR}
alt={data.event_id}
className="h-5 w-5 rounded bg-white object-cover"
/>
</div> </div>
<div> <div>
<h5 className="truncate text-sm font-medium text-zinc-400">{channel?.name}</h5> <h5 className="truncate text-sm font-medium text-zinc-400">{channel?.name}</h5>

View File

@@ -2,15 +2,13 @@ import { AccountContext } from '@components/accountProvider';
import { AvatarUploader } from '@components/avatarUploader'; import { AvatarUploader } from '@components/avatarUploader';
import { RelayContext } from '@components/relaysProvider'; import { RelayContext } from '@components/relaysProvider';
import { defaultChannelsAtom } from '@stores/channel'; import { DEFAULT_AVATAR, WRITEONLY_RELAYS } from '@stores/constants';
import { DEFAULT_AVATAR, MESSAGE_RELAYS } from '@stores/constants';
import { dateToUnix } from '@utils/getDate'; import { dateToUnix } from '@utils/getDate';
import { createChannel } from '@utils/storage'; import { createChannel } from '@utils/storage';
import { Dialog, Transition } from '@headlessui/react'; import { Dialog, Transition } from '@headlessui/react';
import { Cancel, Plus } from 'iconoir-react'; import { Cancel, Plus } from 'iconoir-react';
import { useSetAtom } from 'jotai';
import { getEventHash, signEvent } from 'nostr-tools'; import { getEventHash, signEvent } from 'nostr-tools';
import { Fragment, useContext, useEffect, useState } from 'react'; import { Fragment, useContext, useEffect, useState } from 'react';
import { useForm } from 'react-hook-form'; import { useForm } from 'react-hook-form';
@@ -24,8 +22,6 @@ export const CreateChannelModal = () => {
const [image, setImage] = useState(DEFAULT_AVATAR); const [image, setImage] = useState(DEFAULT_AVATAR);
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const setChannel = useSetAtom(defaultChannelsAtom);
const closeModal = () => { const closeModal = () => {
setIsOpen(false); setIsOpen(false);
}; };
@@ -56,21 +52,12 @@ export const CreateChannelModal = () => {
event.sig = signEvent(event, activeAccount.privkey); event.sig = signEvent(event, activeAccount.privkey);
// publish channel // publish channel
pool.publish(event, MESSAGE_RELAYS); pool.publish(event, WRITEONLY_RELAYS);
// update jotai state // insert to database
setChannel((prev: any) => [ createChannel(event.id, event.pubkey, event.content, event.created_at);
...prev,
{
event_id: event.id,
metadata: { name: data.name, picture: data.picture, about: data.about },
created_at: event.created_at,
},
]);
// reset form // reset form
reset(); reset();
setTimeout(() => { setTimeout(() => {
// insert to database
createChannel(event.id, event.content, event.created_at);
// close modal // close modal
setIsOpen(false); setIsOpen(false);
// redirect to channel page // redirect to channel page

View File

@@ -2,7 +2,7 @@ import { AccountContext } from '@components/accountProvider';
import { RelayContext } from '@components/relaysProvider'; import { RelayContext } from '@components/relaysProvider';
import Tooltip from '@components/tooltip'; import Tooltip from '@components/tooltip';
import { MESSAGE_RELAYS } from '@stores/constants'; import { WRITEONLY_RELAYS } from '@stores/constants';
import { dateToUnix } from '@utils/getDate'; import { dateToUnix } from '@utils/getDate';
@@ -26,7 +26,7 @@ export const HideMessageButton = ({ id }: { id: string }) => {
event.sig = signEvent(event, activeAccount.privkey); event.sig = signEvent(event, activeAccount.privkey);
// publish note // publish note
pool.publish(event, MESSAGE_RELAYS); pool.publish(event, WRITEONLY_RELAYS);
}, [activeAccount.pubkey, activeAccount.privkey, id, pool]); }, [activeAccount.pubkey, activeAccount.privkey, id, pool]);
return ( return (

View File

@@ -2,7 +2,7 @@ import { AccountContext } from '@components/accountProvider';
import { RelayContext } from '@components/relaysProvider'; import { RelayContext } from '@components/relaysProvider';
import Tooltip from '@components/tooltip'; import Tooltip from '@components/tooltip';
import { MESSAGE_RELAYS } from '@stores/constants'; import { WRITEONLY_RELAYS } from '@stores/constants';
import { dateToUnix } from '@utils/getDate'; import { dateToUnix } from '@utils/getDate';
@@ -26,7 +26,7 @@ export const MuteButton = ({ pubkey }: { pubkey: string }) => {
event.sig = signEvent(event, activeAccount.privkey); event.sig = signEvent(event, activeAccount.privkey);
// publish note // publish note
pool.publish(event, MESSAGE_RELAYS); pool.publish(event, WRITEONLY_RELAYS);
}; };
return ( return (

View File

@@ -2,11 +2,11 @@ import { AccountContext } from '@components/accountProvider';
import { NetworkStatusIndicator } from '@components/networkStatusIndicator'; import { NetworkStatusIndicator } from '@components/networkStatusIndicator';
import { RelayContext } from '@components/relaysProvider'; import { RelayContext } from '@components/relaysProvider';
import { DEFAULT_RELAYS } from '@stores/constants'; import { READONLY_RELAYS } from '@stores/constants';
import { hasNewerNoteAtom } from '@stores/note'; import { hasNewerNoteAtom } from '@stores/note';
import { dateToUnix } from '@utils/getDate'; import { dateToUnix } from '@utils/getDate';
import { createChannel, createChat, createNote, updateAccount } from '@utils/storage'; import { createChat, createNote, updateAccount } from '@utils/storage';
import { getParentID, nip02ToArray } from '@utils/transform'; import { getParentID, nip02ToArray } from '@utils/transform';
import { useSetAtom } from 'jotai'; import { useSetAtom } from 'jotai';
@@ -17,11 +17,10 @@ export default function EventCollector() {
const activeAccount: any = useContext(AccountContext); const activeAccount: any = useContext(AccountContext);
const setHasNewerNote = useSetAtom(hasNewerNoteAtom); const setHasNewerNote = useSetAtom(hasNewerNoteAtom);
const follows = activeAccount.follows ? JSON.parse(activeAccount.follows) : [];
const now = useRef(new Date()); const now = useRef(new Date());
const subscribe = useCallback(async () => { const subscribe = useCallback(async () => {
const follows = activeAccount.follows ? JSON.parse(activeAccount.follows) : [];
const unsubscribe = pool.subscribe( const unsubscribe = pool.subscribe(
[ [
{ {
@@ -38,12 +37,8 @@ export default function EventCollector() {
'#p': [activeAccount.pubkey], '#p': [activeAccount.pubkey],
since: dateToUnix(now.current), since: dateToUnix(now.current),
}, },
{
kinds: [40],
since: dateToUnix(now.current),
},
], ],
DEFAULT_RELAYS, READONLY_RELAYS,
(event: { kind: number; tags: string[]; id: string; pubkey: string; content: string; created_at: number }) => { (event: { kind: number; tags: string[]; id: string; pubkey: string; content: string; created_at: number }) => {
switch (event.kind) { switch (event.kind) {
// metadata // metadata
@@ -91,10 +86,6 @@ export default function EventCollector() {
'' ''
); );
break; break;
// channel
case 40:
createChannel(event.id, event.content, event.created_at);
break;
default: default:
break; break;
} }
@@ -104,7 +95,7 @@ export default function EventCollector() {
return () => { return () => {
unsubscribe(); unsubscribe();
}; };
}, [activeAccount.id, activeAccount.pubkey, follows, pool, setHasNewerNote]); }, [activeAccount.id, activeAccount.pubkey, activeAccount.follows, pool, setHasNewerNote]);
useEffect(() => { useEffect(() => {
let ignore = false; let ignore = false;

View File

@@ -2,7 +2,7 @@ import { AccountContext } from '@components/accountProvider';
import { ImagePicker } from '@components/form/imagePicker'; import { ImagePicker } from '@components/form/imagePicker';
import { RelayContext } from '@components/relaysProvider'; import { RelayContext } from '@components/relaysProvider';
import { DEFAULT_RELAYS } from '@stores/constants'; import { WRITEONLY_RELAYS } from '@stores/constants';
import { noteContentAtom } from '@stores/note'; import { noteContentAtom } from '@stores/note';
import { dateToUnix } from '@utils/getDate'; import { dateToUnix } from '@utils/getDate';
@@ -31,7 +31,7 @@ export default function FormBase() {
event.sig = signEvent(event, activeAccount.privkey); event.sig = signEvent(event, activeAccount.privkey);
// publish note // publish note
pool.publish(event, DEFAULT_RELAYS); pool.publish(event, WRITEONLY_RELAYS);
// reset form // reset form
resetValue(); resetValue();
// send notification // send notification

View File

@@ -4,7 +4,7 @@ import { RelayContext } from '@components/relaysProvider';
import { UserMini } from '@components/user/mini'; import { UserMini } from '@components/user/mini';
import { channelContentAtom, channelReplyAtom } from '@stores/channel'; import { channelContentAtom, channelReplyAtom } from '@stores/channel';
import { MESSAGE_RELAYS } from '@stores/constants'; import { FULL_RELAYS } from '@stores/constants';
import { dateToUnix } from '@utils/getDate'; import { dateToUnix } from '@utils/getDate';
@@ -48,7 +48,7 @@ export const FormChannel = ({ eventId }: { eventId: string | string[] }) => {
event.sig = signEvent(event, activeAccount.privkey); event.sig = signEvent(event, activeAccount.privkey);
// publish note // publish note
pool.publish(event, MESSAGE_RELAYS); pool.publish(event, FULL_RELAYS);
// reset state // reset state
resetValue(); resetValue();
// reset channel reply // reset channel reply

View File

@@ -3,7 +3,7 @@ import { ImagePicker } from '@components/form/imagePicker';
import { RelayContext } from '@components/relaysProvider'; import { RelayContext } from '@components/relaysProvider';
import { chatContentAtom } from '@stores/chat'; import { chatContentAtom } from '@stores/chat';
import { MESSAGE_RELAYS } from '@stores/constants'; import { FULL_RELAYS } from '@stores/constants';
import { dateToUnix } from '@utils/getDate'; import { dateToUnix } from '@utils/getDate';
@@ -39,7 +39,7 @@ export default function FormChat({ receiverPubkey }: { receiverPubkey: string })
event.id = getEventHash(event); event.id = getEventHash(event);
event.sig = signEvent(event, activeAccount.privkey); event.sig = signEvent(event, activeAccount.privkey);
// publish note // publish note
pool.publish(event, MESSAGE_RELAYS); pool.publish(event, FULL_RELAYS);
// reset state // reset state
resetValue(); resetValue();
}) })

View File

@@ -1,7 +1,7 @@
import { AccountContext } from '@components/accountProvider'; import { AccountContext } from '@components/accountProvider';
import { RelayContext } from '@components/relaysProvider'; import { RelayContext } from '@components/relaysProvider';
import { DEFAULT_RELAYS } from '@stores/constants'; import { WRITEONLY_RELAYS } from '@stores/constants';
import { dateToUnix } from '@utils/getDate'; import { dateToUnix } from '@utils/getDate';
@@ -28,7 +28,7 @@ export default function FormComment({ eventID }: { eventID: any }) {
event.sig = signEvent(event, activeAccount.privkey); event.sig = signEvent(event, activeAccount.privkey);
// publish note // publish note
pool.publish(event, DEFAULT_RELAYS); pool.publish(event, WRITEONLY_RELAYS);
// send notification // send notification
// sendNotification('Comment has been published successfully'); // sendNotification('Comment has been published successfully');
}; };

View File

@@ -2,7 +2,7 @@ import { AccountContext } from '@components/accountProvider';
import { RelayContext } from '@components/relaysProvider'; import { RelayContext } from '@components/relaysProvider';
import { UserExtend } from '@components/user/extend'; import { UserExtend } from '@components/user/extend';
import { DEFAULT_RELAYS } from '@stores/constants'; import { WRITEONLY_RELAYS } from '@stores/constants';
import { dateToUnix } from '@utils/getDate'; import { dateToUnix } from '@utils/getDate';
@@ -56,7 +56,7 @@ export const NoteComment = ({
event.id = getEventHash(event); event.id = getEventHash(event);
event.sig = signEvent(event, activeAccount.privkey); event.sig = signEvent(event, activeAccount.privkey);
pool.publish(event, DEFAULT_RELAYS); pool.publish(event, WRITEONLY_RELAYS);
setIsOpen(false); setIsOpen(false);
}; };

View File

@@ -1,7 +1,7 @@
import { AccountContext } from '@components/accountProvider'; import { AccountContext } from '@components/accountProvider';
import { RelayContext } from '@components/relaysProvider'; import { RelayContext } from '@components/relaysProvider';
import { DEFAULT_RELAYS } from '@stores/constants'; import { WRITEONLY_RELAYS } from '@stores/constants';
import { dateToUnix } from '@utils/getDate'; import { dateToUnix } from '@utils/getDate';
@@ -43,7 +43,7 @@ export const NoteReaction = ({
event.id = getEventHash(event); event.id = getEventHash(event);
event.sig = signEvent(event, activeAccount.privkey); event.sig = signEvent(event, activeAccount.privkey);
// publish event to all relays // publish event to all relays
pool.publish(event, DEFAULT_RELAYS); pool.publish(event, WRITEONLY_RELAYS);
// update state to change icon to filled heart // update state to change icon to filled heart
setIsReact(true); setIsReact(true);
// update counter // update counter

View File

@@ -3,7 +3,7 @@ import { NoteComment } from '@components/note/meta/comment';
import { NoteReaction } from '@components/note/meta/reaction'; import { NoteReaction } from '@components/note/meta/reaction';
import { RelayContext } from '@components/relaysProvider'; import { RelayContext } from '@components/relaysProvider';
import { DEFAULT_RELAYS } from '@stores/constants'; import { READONLY_RELAYS } from '@stores/constants';
import { memo, useContext, useEffect, useState } from 'react'; import { memo, useContext, useEffect, useState } from 'react';
@@ -34,7 +34,7 @@ export const NoteMetadata = memo(function NoteMetadata({
kinds: [1, 7], kinds: [1, 7],
}, },
], ],
DEFAULT_RELAYS, READONLY_RELAYS,
(event: any) => { (event: any) => {
switch (event.kind) { switch (event.kind) {
case 1: case 1:

View File

@@ -3,7 +3,7 @@ import { NoteMetadata } from '@components/note/metadata';
import { RelayContext } from '@components/relaysProvider'; import { RelayContext } from '@components/relaysProvider';
import { UserExtend } from '@components/user/extend'; import { UserExtend } from '@components/user/extend';
import { DEFAULT_RELAYS } from '@stores/constants'; import { READONLY_RELAYS } from '@stores/constants';
import { contentParser } from '@utils/parser'; import { contentParser } from '@utils/parser';
import { createNote, getNoteByID } from '@utils/storage'; import { createNote, getNoteByID } from '@utils/storage';
@@ -26,7 +26,7 @@ export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
kinds: [1], kinds: [1],
}, },
], ],
DEFAULT_RELAYS, READONLY_RELAYS,
(event: any) => { (event: any) => {
// update state // update state
setEvent(event); setEvent(event);

View File

@@ -2,7 +2,7 @@ import { AccountContext } from '@components/accountProvider';
import { RelayContext } from '@components/relaysProvider'; import { RelayContext } from '@components/relaysProvider';
import { UserExtend } from '@components/user/extend'; import { UserExtend } from '@components/user/extend';
import { DEFAULT_RELAYS } from '@stores/constants'; import { READONLY_RELAYS } from '@stores/constants';
import { contentParser } from '@utils/parser'; import { contentParser } from '@utils/parser';
import { createNote, getNoteByID } from '@utils/storage'; import { createNote, getNoteByID } from '@utils/storage';
@@ -25,7 +25,7 @@ export const NoteQuote = memo(function NoteQuote({ id }: { id: string }) {
kinds: [1], kinds: [1],
}, },
], ],
DEFAULT_RELAYS, READONLY_RELAYS,
(event: any) => { (event: any) => {
// update state // update state
setEvent(event); setEvent(event);

View File

@@ -2,7 +2,7 @@ import { NoteMetadata } from '@components/note/metadata';
import { RelayContext } from '@components/relaysProvider'; import { RelayContext } from '@components/relaysProvider';
import { UserExtend } from '@components/user/extend'; import { UserExtend } from '@components/user/extend';
import { DEFAULT_RELAYS } from '@stores/constants'; import { READONLY_RELAYS } from '@stores/constants';
import { contentParser } from '@utils/parser'; import { contentParser } from '@utils/parser';
@@ -38,7 +38,7 @@ export const RootNote = memo(function RootNote({ event }: { event: any }) {
kinds: [1], kinds: [1],
}, },
], ],
DEFAULT_RELAYS, READONLY_RELAYS,
(event: any) => { (event: any) => {
setData(event); setData(event);
setContent(contentParser(event.content, event.tags)); setContent(contentParser(event.content, event.tags));

View File

@@ -1,7 +1,7 @@
import { RelayContext } from '@components/relaysProvider'; import { RelayContext } from '@components/relaysProvider';
import { UserFollow } from '@components/user/follow'; import { UserFollow } from '@components/user/follow';
import { DEFAULT_RELAYS } from '@stores/constants'; import { READONLY_RELAYS } from '@stores/constants';
import destr from 'destr'; import destr from 'destr';
import { Author } from 'nostr-relaypool'; import { Author } from 'nostr-relaypool';
@@ -12,7 +12,7 @@ export default function ProfileFollowers({ id }: { id: string }) {
const [followers, setFollowers] = useState(null); const [followers, setFollowers] = useState(null);
useEffect(() => { useEffect(() => {
const user = new Author(pool, DEFAULT_RELAYS, id); const user = new Author(pool, READONLY_RELAYS, id);
user.followers((res) => setFollowers(destr(res.tags)), 0, 100); user.followers((res) => setFollowers(destr(res.tags)), 0, 100);
}, [id, pool]); }, [id, pool]);

View File

@@ -1,7 +1,7 @@
import { RelayContext } from '@components/relaysProvider'; import { RelayContext } from '@components/relaysProvider';
import { UserFollow } from '@components/user/follow'; import { UserFollow } from '@components/user/follow';
import { DEFAULT_RELAYS } from '@stores/constants'; import { READONLY_RELAYS } from '@stores/constants';
import { Author } from 'nostr-relaypool'; import { Author } from 'nostr-relaypool';
import { useContext, useEffect, useState } from 'react'; import { useContext, useEffect, useState } from 'react';
@@ -11,7 +11,7 @@ export default function ProfileFollows({ id }: { id: string }) {
const [follows, setFollows] = useState(null); const [follows, setFollows] = useState(null);
useEffect(() => { useEffect(() => {
const user = new Author(pool, DEFAULT_RELAYS, id); const user = new Author(pool, READONLY_RELAYS, id);
user.follows((res) => setFollows(res), 0); user.follows((res) => setFollows(res), 0);
}, [id, pool]); }, [id, pool]);

View File

@@ -1,6 +1,6 @@
import { RelayContext } from '@components/relaysProvider'; import { RelayContext } from '@components/relaysProvider';
import { DEFAULT_AVATAR, DEFAULT_RELAYS } from '@stores/constants'; import { DEFAULT_AVATAR, READONLY_RELAYS } from '@stores/constants';
import { shortenKey } from '@utils/shortenKey'; import { shortenKey } from '@utils/shortenKey';
@@ -15,7 +15,7 @@ export default function ProfileMetadata({ id }: { id: string }) {
const [profile, setProfile] = useState(null); const [profile, setProfile] = useState(null);
useEffect(() => { useEffect(() => {
const user = new Author(pool, DEFAULT_RELAYS, id); const user = new Author(pool, READONLY_RELAYS, id);
user.metaData((res) => setProfile(destr(res.content)), 0); user.metaData((res) => setProfile(destr(res.content)), 0);
}, [id, pool]); }, [id, pool]);

View File

@@ -1,7 +1,7 @@
import { NoteBase } from '@components/note/base'; import { NoteBase } from '@components/note/base';
import { RelayContext } from '@components/relaysProvider'; import { RelayContext } from '@components/relaysProvider';
import { DEFAULT_RELAYS } from '@stores/constants'; import { READONLY_RELAYS } from '@stores/constants';
import { Author } from 'nostr-relaypool'; import { Author } from 'nostr-relaypool';
import { useContext, useEffect, useState } from 'react'; import { useContext, useEffect, useState } from 'react';
@@ -11,7 +11,7 @@ export default function ProfileNotes({ id }: { id: string }) {
const [data, setData] = useState([]); const [data, setData] = useState([]);
useEffect(() => { useEffect(() => {
const user = new Author(pool, DEFAULT_RELAYS, id); const user = new Author(pool, READONLY_RELAYS, id);
user.text((res) => setData((data) => [...data, res]), 100, 0); user.text((res) => setData((data) => [...data, res]), 100, 0);
}, [id, pool]); }, [id, pool]);

View File

@@ -1,4 +1,4 @@
import { DEFAULT_RELAYS } from '@stores/constants'; import { READONLY_RELAYS } from '@stores/constants';
import { RelayPool } from 'nostr-relaypool'; import { RelayPool } from 'nostr-relaypool';
import { createContext, useMemo } from 'react'; import { createContext, useMemo } from 'react';
@@ -8,7 +8,7 @@ export const RelayContext = createContext({});
export default function RelayProvider({ children }: { children: React.ReactNode }) { export default function RelayProvider({ children }: { children: React.ReactNode }) {
const pool = useMemo(() => { const pool = useMemo(() => {
if (typeof window !== 'undefined') { if (typeof window !== 'undefined') {
return new RelayPool(DEFAULT_RELAYS, { useEventCache: false, logSubscriptions: false }); return new RelayPool(READONLY_RELAYS, { useEventCache: false, logSubscriptions: false });
} else { } else {
return null; return null;
} }

View File

@@ -4,7 +4,7 @@ import NewsfeedLayout from '@components/layouts/newsfeed';
import { RelayContext } from '@components/relaysProvider'; import { RelayContext } from '@components/relaysProvider';
import { channelMessagesAtom, channelReplyAtom } from '@stores/channel'; import { channelMessagesAtom, channelReplyAtom } from '@stores/channel';
import { MESSAGE_RELAYS } from '@stores/constants'; import { FULL_RELAYS } from '@stores/constants';
import { dateToUnix, hoursAgo } from '@utils/getDate'; import { dateToUnix, hoursAgo } from '@utils/getDate';
import { usePageContext } from '@utils/hooks/usePageContext'; import { usePageContext } from '@utils/hooks/usePageContext';
@@ -59,7 +59,7 @@ export function Page() {
since: dateToUnix(hoursAgo(48, now.current)), since: dateToUnix(hoursAgo(48, now.current)),
}, },
], ],
MESSAGE_RELAYS, FULL_RELAYS,
(event: { kind: number; tags: string[][]; pubkey: string; id: string }) => { (event: { kind: number; tags: string[][]; pubkey: string; id: string }) => {
if (muted.includes(event.pubkey)) { if (muted.includes(event.pubkey)) {
console.log('muted'); console.log('muted');

View File

@@ -4,7 +4,7 @@ import NewsfeedLayout from '@components/layouts/newsfeed';
import { RelayContext } from '@components/relaysProvider'; import { RelayContext } from '@components/relaysProvider';
import { chatMessagesAtom } from '@stores/chat'; import { chatMessagesAtom } from '@stores/chat';
import { MESSAGE_RELAYS } from '@stores/constants'; import { FULL_RELAYS } from '@stores/constants';
import { usePageContext } from '@utils/hooks/usePageContext'; import { usePageContext } from '@utils/hooks/usePageContext';
@@ -44,7 +44,7 @@ export function Page() {
'#p': [pubkey], '#p': [pubkey],
}, },
], ],
MESSAGE_RELAYS, FULL_RELAYS,
(event: any) => { (event: any) => {
setChatMessages((prev) => [...prev, event]); setChatMessages((prev) => [...prev, event]);
} }

View File

@@ -1,6 +1,6 @@
import { RelayContext } from '@components/relaysProvider'; import { RelayContext } from '@components/relaysProvider';
import { MESSAGE_RELAYS } from '@stores/constants'; import { FULL_RELAYS } from '@stores/constants';
import { dateToUnix, hoursAgo } from '@utils/getDate'; import { dateToUnix, hoursAgo } from '@utils/getDate';
import { import {
@@ -69,7 +69,7 @@ export function Page() {
// subscribe relays // subscribe relays
const unsubscribe = pool.subscribe( const unsubscribe = pool.subscribe(
query, query,
MESSAGE_RELAYS, FULL_RELAYS,
(event: { kind: number; tags: string[]; id: string; pubkey: string; content: string; created_at: number }) => { (event: { kind: number; tags: string[]; id: string; pubkey: string; content: string; created_at: number }) => {
switch (event.kind) { switch (event.kind) {
// short text note // short text note

View File

@@ -1,7 +1,7 @@
import OnboardingLayout from '@components/layouts/onboarding'; import OnboardingLayout from '@components/layouts/onboarding';
import { RelayContext } from '@components/relaysProvider'; import { RelayContext } from '@components/relaysProvider';
import { DEFAULT_RELAYS } from '@stores/constants'; import { WRITEONLY_RELAYS } from '@stores/constants';
import { createAccount } from '@utils/storage'; import { createAccount } from '@utils/storage';
@@ -60,7 +60,7 @@ export function Page() {
// insert to database // insert to database
createAccount(pubkey, privkey, metadata); createAccount(pubkey, privkey, metadata);
// broadcast // broadcast
pool.publish(event, DEFAULT_RELAYS); pool.publish(event, WRITEONLY_RELAYS);
// redirect to next step // redirect to next step
navigate(`/onboarding/create/step-2?pubkey=${pubkey}&privkey=${privkey}`, { overwriteLastHistoryEntry: true }); navigate(`/onboarding/create/step-2?pubkey=${pubkey}&privkey=${privkey}`, { overwriteLastHistoryEntry: true });
}, [pool, pubkey, privkey, metadata]); }, [pool, pubkey, privkey, metadata]);

View File

@@ -2,7 +2,7 @@ import OnboardingLayout from '@components/layouts/onboarding';
import { RelayContext } from '@components/relaysProvider'; import { RelayContext } from '@components/relaysProvider';
import { UserBase } from '@components/user/base'; import { UserBase } from '@components/user/base';
import { DEFAULT_RELAYS } from '@stores/constants'; import { WRITEONLY_RELAYS } from '@stores/constants';
import { usePageContext } from '@utils/hooks/usePageContext'; import { usePageContext } from '@utils/hooks/usePageContext';
import { fetchProfileMetadata } from '@utils/hooks/useProfileMetadata'; import { fetchProfileMetadata } from '@utils/hooks/useProfileMetadata';
@@ -100,7 +100,7 @@ export function Page() {
event.id = getEventHash(event); event.id = getEventHash(event);
event.sig = signEvent(event, privkey); event.sig = signEvent(event, privkey);
// broadcast // broadcast
pool.publish(event, DEFAULT_RELAYS); pool.publish(event, WRITEONLY_RELAYS);
// redirect to splashscreen // redirect to splashscreen
navigate('/'); navigate('/');
}, [pubkey, privkey, follows, pool]); }, [pubkey, privkey, follows, pool]);

View File

@@ -1,7 +1,7 @@
import OnboardingLayout from '@components/layouts/onboarding'; import OnboardingLayout from '@components/layouts/onboarding';
import { RelayContext } from '@components/relaysProvider'; import { RelayContext } from '@components/relaysProvider';
import { DEFAULT_AVATAR, DEFAULT_RELAYS } from '@stores/constants'; import { DEFAULT_AVATAR, READONLY_RELAYS } from '@stores/constants';
import { usePageContext } from '@utils/hooks/usePageContext'; import { usePageContext } from '@utils/hooks/usePageContext';
import { fetchProfileMetadata } from '@utils/hooks/useProfileMetadata'; import { fetchProfileMetadata } from '@utils/hooks/useProfileMetadata';
@@ -53,7 +53,7 @@ export function Page() {
authors: [pubkey], authors: [pubkey],
}, },
], ],
DEFAULT_RELAYS, READONLY_RELAYS,
(event: any) => { (event: any) => {
switch (event.kind) { switch (event.kind) {
case 0: case 0:

View File

@@ -1,16 +1,6 @@
import { DEFAULT_CHANNELS } from '@stores/constants';
import { atom } from 'jotai'; import { atom } from 'jotai';
import { atomWithReset } from 'jotai/utils'; import { atomWithReset } from 'jotai/utils';
// channel list
export const defaultChannelsAtom = atom(DEFAULT_CHANNELS);
export const channelsAtom = atom(async (get) => {
const { getChannels } = await import('@utils/storage');
const result: any = await getChannels(100, 0);
return get(defaultChannelsAtom).concat(result);
});
// channel reply id // channel reply id
export const channelReplyAtom = atomWithReset({ id: null, pubkey: null, content: null }); export const channelReplyAtom = atomWithReset({ id: null, pubkey: null, content: null });

View File

@@ -1,35 +1,22 @@
export const APP_VERSION = '0.2.5'; export const APP_VERSION = '0.2.5';
export const DEFAULT_AVATAR = 'https://void.cat/d/KmypFh2fBdYCEvyJrPiN89.webp'; export const DEFAULT_AVATAR = 'https://void.cat/d/KmypFh2fBdYCEvyJrPiN89.webp';
export const DEFAULT_CHANNEL_BANNER = export const DEFAULT_CHANNEL_BANNER =
'https://bafybeiacwit7hjmdefqggxqtgh6ht5dhth7ndptwn2msl5kpkodudsr7py.ipfs.w3s.link/banner-1.jpg'; 'https://bafybeiacwit7hjmdefqggxqtgh6ht5dhth7ndptwn2msl5kpkodudsr7py.ipfs.w3s.link/banner-1.jpg';
export const DEFAULT_CHANNELS = [
{ // read-only relay list
event_id: 'e3cadf5beca1b2af1cddaa41a633679bedf263e3de1eb229c6686c50d85df753', export const READONLY_RELAYS = ['wss://welcome.nostr.wine', 'wss://relay.nostr.band'];
metadata: {
name: 'Lume General', // write-only relay list
picture: 'https://void.cat/d/UNyxBmAh1MUx5gQTX95jyf.webp', export const WRITEONLY_RELAYS = ['wss://nostr.mutinywallet.com', 'wss://relay.nostr.band'];
about: 'General discussion about the Lume client',
}, // full-relay list, used for inital page and chat/channel messages loading
created_at: 1681898574, export const FULL_RELAYS = [
},
{
event_id: '1abf8948d2fd05dd1836b33b324dca65138b2e80c77b27eeeed4323246efba4d',
metadata: { picture: 'https://void.cat/d/MsqUKXXC4SxDfmT2KiHovJ.webp', name: 'Arcade Open R&D', about: '' },
created_at: 1682252461,
},
{
event_id: '25e5c82273a271cb1a840d0060391a0bf4965cafeb029d5ab55350b418953fbb',
metadata: {
about: '',
name: 'Nostr',
picture: 'https://cloudflare-ipfs.com/ipfs/QmTN4Eas9atUULVbEAbUU8cowhtvK7g3t7jfKztY7wc8eP?.png',
},
created_at: 1661333723,
},
];
export const DEFAULT_RELAYS = ['wss://welcome.nostr.wine', 'wss://relay.nostr.band', 'wss://nostr.mutinywallet.com'];
export const MESSAGE_RELAYS = [
'wss://relay.damus.io', 'wss://relay.damus.io',
'wss://nos.lol',
'wss://nostr.mom',
'wss://relay.plebstr.com',
'wss://nostr-pub.wellorder.net', 'wss://nostr-pub.wellorder.net',
'wss://nostr.zebedee.cloud', 'wss://nostr.zebedee.cloud',
'wss://nostr.fmt.wiz.biz', 'wss://nostr.fmt.wiz.biz',

View File

@@ -1,6 +1,6 @@
import { RelayContext } from '@components/relaysProvider'; import { RelayContext } from '@components/relaysProvider';
import { DEFAULT_RELAYS } from '@stores/constants'; import { READONLY_RELAYS } from '@stores/constants';
import { updateChannelMetadata } from '@utils/storage'; import { updateChannelMetadata } from '@utils/storage';
import { getChannel } from '@utils/storage'; import { getChannel } from '@utils/storage';
@@ -23,7 +23,7 @@ export const useChannelMetadata = (id: string, channelPubkey: string) => {
kinds: [40], kinds: [40],
}, },
], ],
DEFAULT_RELAYS, READONLY_RELAYS,
(event: { kind: number; pubkey: string; content: string }) => { (event: { kind: number; pubkey: string; content: string }) => {
switch (event.kind) { switch (event.kind) {
case 41: case 41: