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' : ''
)}
>
<div className="relative h-5 w-5 shrink-0 rounded bg-zinc-900">
<img src={channel?.picture || DEFAULT_AVATAR} alt={data.event_id} className="h-5 w-5 rounded object-contain" />
<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 bg-white object-cover"
/>
</div>
<div>
<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 { RelayContext } from '@components/relaysProvider';
import { defaultChannelsAtom } from '@stores/channel';
import { DEFAULT_AVATAR, MESSAGE_RELAYS } from '@stores/constants';
import { DEFAULT_AVATAR, WRITEONLY_RELAYS } from '@stores/constants';
import { dateToUnix } from '@utils/getDate';
import { createChannel } from '@utils/storage';
import { Dialog, Transition } from '@headlessui/react';
import { Cancel, Plus } from 'iconoir-react';
import { useSetAtom } from 'jotai';
import { getEventHash, signEvent } from 'nostr-tools';
import { Fragment, useContext, useEffect, useState } from 'react';
import { useForm } from 'react-hook-form';
@@ -24,8 +22,6 @@ export const CreateChannelModal = () => {
const [image, setImage] = useState(DEFAULT_AVATAR);
const [loading, setLoading] = useState(false);
const setChannel = useSetAtom(defaultChannelsAtom);
const closeModal = () => {
setIsOpen(false);
};
@@ -56,21 +52,12 @@ export const CreateChannelModal = () => {
event.sig = signEvent(event, activeAccount.privkey);
// publish channel
pool.publish(event, MESSAGE_RELAYS);
// update jotai state
setChannel((prev: any) => [
...prev,
{
event_id: event.id,
metadata: { name: data.name, picture: data.picture, about: data.about },
created_at: event.created_at,
},
]);
pool.publish(event, WRITEONLY_RELAYS);
// insert to database
createChannel(event.id, event.pubkey, event.content, event.created_at);
// reset form
reset();
setTimeout(() => {
// insert to database
createChannel(event.id, event.content, event.created_at);
// close modal
setIsOpen(false);
// redirect to channel page

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,7 +1,7 @@
import { RelayContext } from '@components/relaysProvider';
import { UserFollow } from '@components/user/follow';
import { DEFAULT_RELAYS } from '@stores/constants';
import { READONLY_RELAYS } from '@stores/constants';
import destr from 'destr';
import { Author } from 'nostr-relaypool';
@@ -12,7 +12,7 @@ export default function ProfileFollowers({ id }: { id: string }) {
const [followers, setFollowers] = useState(null);
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);
}, [id, pool]);

View File

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

View File

@@ -1,6 +1,6 @@
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';
@@ -15,7 +15,7 @@ export default function ProfileMetadata({ id }: { id: string }) {
const [profile, setProfile] = useState(null);
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);
}, [id, pool]);

View File

@@ -1,7 +1,7 @@
import { NoteBase } from '@components/note/base';
import { RelayContext } from '@components/relaysProvider';
import { DEFAULT_RELAYS } from '@stores/constants';
import { READONLY_RELAYS } from '@stores/constants';
import { Author } from 'nostr-relaypool';
import { useContext, useEffect, useState } from 'react';
@@ -11,7 +11,7 @@ export default function ProfileNotes({ id }: { id: string }) {
const [data, setData] = useState([]);
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);
}, [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 { createContext, useMemo } from 'react';
@@ -8,7 +8,7 @@ export const RelayContext = createContext({});
export default function RelayProvider({ children }: { children: React.ReactNode }) {
const pool = useMemo(() => {
if (typeof window !== 'undefined') {
return new RelayPool(DEFAULT_RELAYS, { useEventCache: false, logSubscriptions: false });
return new RelayPool(READONLY_RELAYS, { useEventCache: false, logSubscriptions: false });
} else {
return null;
}