mirror of
https://github.com/t4t5/nostr-react.git
synced 2025-03-17 13:31:43 +01:00
Add onSubscribe callback
This commit is contained in:
parent
50f67a0333
commit
f572ae9cdc
@ -16,6 +16,7 @@ export { dateToUnix } from "./utils"
|
||||
type OnConnectFunc = (relay: Relay) => void
|
||||
type OnDisconnectFunc = (relay: Relay) => void
|
||||
type OnEventFunc = (event: NostrEvent) => void
|
||||
type OnSubscribeFunc = (sub: Sub, relay: Relay) => void
|
||||
|
||||
interface NostrContextType {
|
||||
isLoading: boolean
|
||||
@ -138,6 +139,7 @@ export function useNostrEvents({
|
||||
})
|
||||
|
||||
let onEventCallback: null | OnEventFunc = null
|
||||
let onSubscribeCallback: null | OnSubscribeFunc = null
|
||||
|
||||
// Lets us detect changes in the nested filter object for the useEffect hook
|
||||
const filterBase64 =
|
||||
@ -183,8 +185,12 @@ export function useNostrEvents({
|
||||
if (!enabled) return
|
||||
|
||||
const relaySubs = connectedRelays.map((relay) => {
|
||||
const sub = subscribe(relay, filter)
|
||||
|
||||
onSubscribeCallback?.(sub, relay)
|
||||
|
||||
return {
|
||||
sub: subscribe(relay, filter),
|
||||
sub,
|
||||
relay,
|
||||
}
|
||||
})
|
||||
@ -205,6 +211,11 @@ export function useNostrEvents({
|
||||
onConnect,
|
||||
connectedRelays,
|
||||
unsubscribe,
|
||||
onSubscribe: (_onSubscribeCallback: OnSubscribeFunc) => {
|
||||
if (_onSubscribeCallback) {
|
||||
onSubscribeCallback = _onSubscribeCallback
|
||||
}
|
||||
},
|
||||
onEvent: (_onEventCallback: OnEventFunc) => {
|
||||
if (_onEventCallback) {
|
||||
onEventCallback = _onEventCallback
|
||||
|
Loading…
x
Reference in New Issue
Block a user