From 25f0b4686f70a6156a150f1880237507d18aec65 Mon Sep 17 00:00:00 2001 From: KoalaSat Date: Mon, 7 Nov 2022 08:30:51 +0100 Subject: [PATCH] Bug Fix 2 --- frontend/Components/ContactsPage/index.tsx | 23 +++++++++++-------- frontend/Components/ProfilePage/index.tsx | 3 +-- .../DatabaseFunctions/Users/index.ts | 9 -------- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/frontend/Components/ContactsPage/index.tsx b/frontend/Components/ContactsPage/index.tsx index 3aeaf4c..cc224e5 100644 --- a/frontend/Components/ContactsPage/index.tsx +++ b/frontend/Components/ContactsPage/index.tsx @@ -6,6 +6,7 @@ import Icon from 'react-native-vector-icons/FontAwesome5' import { Event, EventKind } from '../../lib/nostr/Events' import { useTranslation } from 'react-i18next' import { + getUser, getUsers, insertUserPets, updateUserContact, @@ -58,7 +59,7 @@ export const ContactsPage: React.FC = () => { const subscribeContacts: () => void = async () => { relayPool?.unsubscribeAll() - relayPool?.on('event', 'contacts', (relay: Relay, _subId?: string, event?: Event) => { + relayPool?.on('event', 'contacts', async (relay: Relay, _subId?: string, event?: Event) => { console.log('CONTACTS PAGE EVENT =======>', relay.url, event) if (database && event?.id && publicKey && event.kind === EventKind.petNames) { if (event.pubkey === publicKey) { @@ -66,9 +67,17 @@ export const ContactsPage: React.FC = () => { relayPool?.removeOn('event', 'contacts') } else { const isFollower = event.tags.some((tag) => tag[1] === publicKey) - updateUserFollower(event.pubkey, database, isFollower).then(() => { - setLastEventId(event?.id ?? '') - }) + await updateUserFollower(event.pubkey, database, isFollower) + setLastEventId(event?.id ?? '') + if (isFollower) { + const user = await getUser(event.pubkey, database) + if (!user?.name && user?.id) { + relayPool?.subscribe('main-channel', { + kinds: [EventKind.meta], + authors: [user.id], + }) + } + } } } }) @@ -84,12 +93,6 @@ export const ContactsPage: React.FC = () => { '#p': [publicKey], }) } - if (users && users.length > 0) { - relayPool?.subscribe('main-channel', { - kinds: [EventKind.meta], - authors: users?.map((user) => user.id), - }) - } } } diff --git a/frontend/Components/ProfilePage/index.tsx b/frontend/Components/ProfilePage/index.tsx index 8ff6bd5..9ed0697 100644 --- a/frontend/Components/ProfilePage/index.tsx +++ b/frontend/Components/ProfilePage/index.tsx @@ -24,7 +24,6 @@ import NoteCard from '../NoteCard' import { RelayPoolContext } from '../../Contexts/RelayPoolContext' import { getUser, - removeContact, User, updateUserFollower, updateUserContact, @@ -157,7 +156,7 @@ export const ProfilePage: React.FC = () => { const removeAuthor: () => void = () => { if (relayPool && database && publicKey) { - removeContact(userId, database).then(() => { + updateUserContact(userId, database, false).then(() => { populatePets(relayPool, database, publicKey) setIsContact(false) }) diff --git a/frontend/Functions/DatabaseFunctions/Users/index.ts b/frontend/Functions/DatabaseFunctions/Users/index.ts index 5149806..97e10bd 100644 --- a/frontend/Functions/DatabaseFunctions/Users/index.ts +++ b/frontend/Functions/DatabaseFunctions/Users/index.ts @@ -106,15 +106,6 @@ export const getUser: (pubkey: string, db: QuickSQLiteConnection) => Promise Promise = async (pubkey, db) => { - const userQuery = `UPDATE nostros_users SET contact = 0 WHERE id = ?` - - return db.execute(userQuery, [pubkey]) -} - export const addUser: (pubKey: string, db: QuickSQLiteConnection) => Promise = async ( pubKey, db,