mirror of
https://github.com/KoalaSat/nostros.git
synced 2024-09-29 06:30:47 +00:00
refactor relay pool and profile load
This commit is contained in:
parent
3f9601faf8
commit
3107a03193
@ -67,10 +67,9 @@ export const RelayPoolContextProvider = ({
|
||||
if (database && publicKey) {
|
||||
DeviceEventEmitter.addListener('WebsocketEvent', debouncedEventIdHandler)
|
||||
DeviceEventEmitter.addListener('WebsocketConfirmation', debouncedConfirmationHandler)
|
||||
const initRelayPool = new RelayPool([], privateKey)
|
||||
initRelayPool.connect(publicKey, (eventId: string) => setLastEventId(eventId))
|
||||
const initRelayPool = new RelayPool(privateKey)
|
||||
initRelayPool.connect(publicKey, () => setRelayPoolReady(true))
|
||||
setRelayPool(initRelayPool)
|
||||
setRelayPoolReady(true)
|
||||
loadRelays()
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ export const ProfileLoadPage: React.FC = () => {
|
||||
if (database && publicKey) {
|
||||
getUsers(database, {}).then((results) => {
|
||||
if (results && results.length > 0) {
|
||||
setContactsCount(results.length)
|
||||
setContactsCount(results.filter((user) => user.contact).length)
|
||||
const authors = [...results.map((user: User) => user.id), publicKey]
|
||||
relayPool?.subscribe('profile-load-notes', [
|
||||
{
|
||||
|
@ -18,19 +18,13 @@ export interface RelayMessage {
|
||||
}
|
||||
|
||||
class RelayPool {
|
||||
constructor(relaysUrls: string[], privateKey?: string) {
|
||||
constructor(privateKey?: string) {
|
||||
this.privateKey = privateKey
|
||||
this.relays = relaysUrls
|
||||
this.subscriptions = {}
|
||||
|
||||
this.relays.forEach((relayUrl) => {
|
||||
this.add(relayUrl)
|
||||
})
|
||||
}
|
||||
|
||||
private readonly privateKey?: string
|
||||
private subscriptions: Record<string, string[]>
|
||||
public relays: string[]
|
||||
|
||||
private readonly send: (message: object) => void = async (message) => {
|
||||
const tosend = JSON.stringify(message)
|
||||
@ -47,7 +41,6 @@ class RelayPool {
|
||||
callback = () => {},
|
||||
) => {
|
||||
RelayPoolModule.add(relayUrl, callback)
|
||||
this.relays.push(relayUrl)
|
||||
}
|
||||
|
||||
public readonly remove: (relayUrl: string, callback?: () => void) => void = async (
|
||||
@ -55,7 +48,6 @@ class RelayPool {
|
||||
callback = () => {},
|
||||
) => {
|
||||
RelayPoolModule.remove(relayUrl, callback)
|
||||
this.relays = this.relays.filter((relay) => relay === relayUrl)
|
||||
}
|
||||
|
||||
public readonly sendEvent: (event: Event) => Promise<Event | null> = async (event) => {
|
||||
|
Loading…
Reference in New Issue
Block a user