Bug Fix 2

This commit is contained in:
KoalaSat 2022-11-07 08:30:51 +01:00
parent e7830f85ce
commit 25f0b4686f
No known key found for this signature in database
GPG Key ID: 2F7F61C6146AB157
3 changed files with 14 additions and 21 deletions

View File

@ -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),
})
}
}
}

View File

@ -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)
})

View File

@ -106,15 +106,6 @@ export const getUser: (pubkey: string, db: QuickSQLiteConnection) => Promise<Use
}
}
export const removeContact: (
pubkey: string,
db: QuickSQLiteConnection,
) => Promise<QueryResult> = 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<QueryResult> = async (
pubKey,
db,