diff --git a/frontend/Components/NoteCard/index.tsx b/frontend/Components/NoteCard/index.tsx index 3ea3a17..3a99ce0 100644 --- a/frontend/Components/NoteCard/index.tsx +++ b/frontend/Components/NoteCard/index.tsx @@ -82,7 +82,7 @@ export const NoteCard: React.FC = ({ kinds: [EventKind.meta], authors: [...rootReplies.map((reply) => reply.pubkey), note.pubkey], } - relayPool?.subscribe('notecard', message) + relayPool?.subscribe('notecard', [message]) } }) } diff --git a/frontend/Pages/ContactsPage/index.tsx b/frontend/Pages/ContactsPage/index.tsx index f8950ad..9d60a6d 100644 --- a/frontend/Pages/ContactsPage/index.tsx +++ b/frontend/Pages/ContactsPage/index.tsx @@ -54,13 +54,12 @@ export const ContactsPage: React.FC = () => { getUsers(database, filters).then((results) => { if (results && results.length > 0) { setUsers(results) - const missingDataUsers = results.filter((user) => !user.picture).map((user) => user.id) - if (missingDataUsers.length > 0) { - relayPool?.subscribe('contacts-meta', { + relayPool?.subscribe('contacts-meta', [ + { kinds: [EventKind.meta], - authors: missingDataUsers, - }) - } + authors: results.map((user) => user.id), + }, + ]) } }) } @@ -69,17 +68,16 @@ export const ContactsPage: React.FC = () => { const subscribeContacts: () => void = async () => { relayPool?.unsubscribeAll() if (publicKey) { - if (selectedTab === 0) { - relayPool?.subscribe('contacts-following', { + relayPool?.subscribe('contacts', [ + { kinds: [EventKind.petNames], authors: [publicKey], - }) - } else if (selectedTab === 1) { - relayPool?.subscribe('contacts-followers', { + }, + { kinds: [EventKind.petNames], '#p': [publicKey], - }) - } + }, + ]) } } diff --git a/frontend/Pages/ConversationPage/index.tsx b/frontend/Pages/ConversationPage/index.tsx index daf1407..00a430e 100644 --- a/frontend/Pages/ConversationPage/index.tsx +++ b/frontend/Pages/ConversationPage/index.tsx @@ -73,16 +73,18 @@ export const ConversationPage: React.FC = () => { const subscribeDirectMessages: () => void = async () => { relayPool?.unsubscribeAll() if (publicKey && otherPubKey) { - relayPool?.subscribe('conversation-other', { - kinds: [EventKind.directMessage], - authors: [publicKey], - '#p': [otherPubKey], - }) - relayPool?.subscribe('conversation-user', { - kinds: [EventKind.directMessage], - authors: [otherPubKey], - '#p': [publicKey], - }) + relayPool?.subscribe('conversation', [ + { + kinds: [EventKind.directMessage], + authors: [publicKey], + '#p': [otherPubKey], + }, + { + kinds: [EventKind.directMessage], + authors: [otherPubKey], + '#p': [publicKey], + }, + ]) } } diff --git a/frontend/Pages/DirectMessagesPage/index.tsx b/frontend/Pages/DirectMessagesPage/index.tsx index 48ebb3d..a7dabb0 100644 --- a/frontend/Pages/DirectMessagesPage/index.tsx +++ b/frontend/Pages/DirectMessagesPage/index.tsx @@ -55,10 +55,12 @@ export const DirectMessagesPage: React.FC = () => { if (results && results.length > 0) { settDirectMessages(results) const otherUsers = results.map((message) => getOtherPubKey(message, publicKey)) - relayPool?.subscribe('directmessages-meta', { - kinds: [EventKind.meta], - authors: otherUsers, - }) + relayPool?.subscribe('directmessages-meta', [ + { + kinds: [EventKind.meta], + authors: otherUsers, + }, + ]) getUsers(database, { includeIds: otherUsers }).then(settUsers) } }) @@ -69,14 +71,16 @@ export const DirectMessagesPage: React.FC = () => { const subscribeDirectMessages: () => void = async () => { relayPool?.unsubscribeAll() if (publicKey) { - relayPool?.subscribe('directmessages-user', { - kinds: [EventKind.directMessage], - authors: [publicKey], - }) - relayPool?.subscribe('directmessages-others', { - kinds: [EventKind.directMessage], - '#p': [publicKey], - }) + relayPool?.subscribe('directmessages-user', [ + { + kinds: [EventKind.directMessage], + authors: [publicKey], + }, + { + kinds: [EventKind.directMessage], + '#p': [publicKey], + }, + ]) } } diff --git a/frontend/Pages/HomePage/index.tsx b/frontend/Pages/HomePage/index.tsx index 63d1047..38ea06f 100644 --- a/frontend/Pages/HomePage/index.tsx +++ b/frontend/Pages/HomePage/index.tsx @@ -33,10 +33,12 @@ export const HomePage: React.FC = () => { const calculateInitialNotes: () => Promise = async () => { if (database && publicKey) { - relayPool?.subscribe('homepage-contacts', { - kinds: [EventKind.petNames], - authors: [publicKey], - }) + relayPool?.subscribe('homepage-contacts', [ + { + kinds: [EventKind.petNames], + authors: [publicKey], + }, + ]) const users = await getUsers(database, { contacts: true, includeIds: [publicKey] }) subscribeNotes(users) setAuthors(users) @@ -60,7 +62,7 @@ export const HomePage: React.FC = () => { message.limit = pageSize + initialPageSize } - relayPool?.subscribe('homepage-main', message) + relayPool?.subscribe('homepage-main', [message]) } const loadNotes: () => void = () => { @@ -68,14 +70,16 @@ export const HomePage: React.FC = () => { getMainNotes(database, publicKey, pageSize).then((notes) => { setNotes(notes) setRefreshing(false) - relayPool?.subscribe('homepage-contacts-meta', { - kinds: [EventKind.meta], - authors: notes.map((note) => note.pubkey), - }) - relayPool?.subscribe('homepage-contacts-reactions', { - kinds: [EventKind.reaction], - '#e': notes.map((note) => note.id ?? ''), - }) + relayPool?.subscribe('homepage-contacts-meta', [ + { + kinds: [EventKind.meta], + authors: notes.map((note) => note.pubkey), + }, + { + kinds: [EventKind.reaction], + '#e': notes.map((note) => note.id ?? ''), + }, + ]) }) } } diff --git a/frontend/Pages/LandingPage/Loader/index.tsx b/frontend/Pages/LandingPage/Loader/index.tsx index 1c93e6b..f92c2e8 100644 --- a/frontend/Pages/LandingPage/Loader/index.tsx +++ b/frontend/Pages/LandingPage/Loader/index.tsx @@ -19,10 +19,12 @@ export const Loader: React.FC = () => { useEffect(() => { if (!loadingRelayPool && !loadingDb && publicKey) { - relayPool?.subscribe('loading-meta', { - kinds: [EventKind.petNames, EventKind.meta], - authors: [publicKey], - }) + relayPool?.subscribe('loading-meta', [ + { + kinds: [EventKind.petNames, EventKind.meta], + authors: [publicKey], + }, + ]) } }, [loadingRelayPool, publicKey, loadingDb]) @@ -37,11 +39,13 @@ export const Loader: React.FC = () => { setContactsCount(results.length) if (publicKey && results && results.length > 0) { const authors = [...results.map((user: User) => user.id), publicKey] - relayPool?.subscribe('loading-notes', { - kinds: [EventKind.meta, EventKind.textNote], - authors, - since: moment().unix() - 86400 * 2, - }) + relayPool?.subscribe('loading-notes', [ + { + kinds: [EventKind.meta, EventKind.textNote], + authors, + since: moment().unix() - 86400, + }, + ]) } }) } diff --git a/frontend/Pages/MentionsPage/index.tsx b/frontend/Pages/MentionsPage/index.tsx index 1282c65..fed183a 100644 --- a/frontend/Pages/MentionsPage/index.tsx +++ b/frontend/Pages/MentionsPage/index.tsx @@ -26,35 +26,35 @@ export const MentionsPage: React.FC = () => { const subscribeNotes: () => void = async () => { if (!database || !publicKey) return - relayPool?.subscribe('mentions-user-user', { - kinds: [EventKind.textNote], - '#p': [publicKey], - limit: pageSize, - }) - relayPool?.subscribe('mentions-user-answers', { - kinds: [EventKind.textNote], - '#e': [publicKey], - limit: pageSize, - }) + relayPool?.subscribe('mentions-user', [ + { + kinds: [EventKind.textNote], + '#p': [publicKey], + limit: pageSize, + }, + { + kinds: [EventKind.textNote], + '#e': [publicKey], + limit: pageSize, + }, + ]) } const loadNotes: () => void = () => { if (database && publicKey) { getMentionNotes(database, publicKey, pageSize).then((notes) => { setNotes(notes) - relayPool?.subscribe('mentions-notes-answers', { - kinds: [EventKind.reaction], - '#e': notes.map((note) => note.id ?? ''), - }) - const missingDataNotes = notes - .filter((note) => !note.picture || note.picture === '') - .map((note) => note.pubkey) - if (missingDataNotes.length > 0) { - relayPool?.subscribe('mentions-meta', { + const missingDataNotes = notes.map((note) => note.pubkey) + relayPool?.subscribe('mentions-answers', [ + { + kinds: [EventKind.reaction], + '#e': notes.map((note) => note.id ?? ''), + }, + { kinds: [EventKind.meta], authors: missingDataNotes, - }) - } + }, + ]) }) } } diff --git a/frontend/Pages/NotePage/index.tsx b/frontend/Pages/NotePage/index.tsx index c169602..2c6e59b 100644 --- a/frontend/Pages/NotePage/index.tsx +++ b/frontend/Pages/NotePage/index.tsx @@ -67,7 +67,7 @@ export const NotePage: React.FC = () => { kinds: [EventKind.meta], authors: [...rootReplies.map((note) => note.pubkey), event.pubkey], } - relayPool?.subscribe('meta-notepage', message) + relayPool?.subscribe('meta-notepage', [message]) } else { setReplies([]) } @@ -81,14 +81,16 @@ export const NotePage: React.FC = () => { const subscribeNotes: (past?: boolean) => Promise = async (past) => { if (database && eventId) { - relayPool?.subscribe('main-notepage', { - kinds: [EventKind.textNote], - ids: [eventId], - }) - relayPool?.subscribe('answers-notepage', { - kinds: [EventKind.reaction, EventKind.textNote], - '#e': [eventId], - }) + relayPool?.subscribe('notepage', [ + { + kinds: [EventKind.textNote], + ids: [eventId], + }, + { + kinds: [EventKind.reaction, EventKind.textNote], + '#e': [eventId], + }, + ]) } } diff --git a/frontend/Pages/ProfilePage/index.tsx b/frontend/Pages/ProfilePage/index.tsx index fdc35a9..7954743 100644 --- a/frontend/Pages/ProfilePage/index.tsx +++ b/frontend/Pages/ProfilePage/index.tsx @@ -85,10 +85,12 @@ export const ProfilePage: React.FC = () => { getNotes(database, { filters: { pubkey: userId }, limit: pageSize }).then((results) => { setNotes(results) setRefreshing(false) - relayPool?.subscribe('answers-profile', { - kinds: [EventKind.reaction], - '#e': results.map((note) => note.id ?? ''), - }) + relayPool?.subscribe('answers-profile', [ + { + kinds: [EventKind.reaction], + '#e': results.map((note) => note.id ?? ''), + }, + ]) }) } } @@ -101,14 +103,16 @@ export const ProfilePage: React.FC = () => { authors: [userId], limit: pageSize, } - relayPool?.subscribe('main-profile', message) + relayPool?.subscribe('main-profile', [message]) } const subscribeProfile: () => Promise = async () => { - relayPool?.subscribe('user-profile', { - kinds: [EventKind.meta, EventKind.petNames], - authors: [userId], - }) + relayPool?.subscribe('user-profile', [ + { + kinds: [EventKind.meta, EventKind.petNames], + authors: [userId], + }, + ]) } const onRefresh = useCallback(() => { diff --git a/frontend/lib/nostr/RelayPool/intex.ts b/frontend/lib/nostr/RelayPool/intex.ts index d74d952..9d2685c 100644 --- a/frontend/lib/nostr/RelayPool/intex.ts +++ b/frontend/lib/nostr/RelayPool/intex.ts @@ -72,7 +72,7 @@ class RelayPool { } } - public readonly subscribe: (subId: string, filters?: RelayFilters) => void = async ( + public readonly subscribe: (subId: string, filters?: RelayFilters[]) => void = async ( subId, filters, ) => { @@ -83,7 +83,7 @@ class RelayPool { if (this.subscriptions[subId]?.includes(uuid)) { console.log('Subscription already done!', filters) } else { - this.send(['REQ', subId, filters]) + this.send([...['REQ', subId], ...(filters ?? [])]) const newSubscriptions = [...(this.subscriptions[subId] ?? []), uuid] this.subscriptions[subId] = newSubscriptions }