This commit is contained in:
+33
-111
@@ -1,112 +1,34 @@
|
||||
export * from "./blossom.js"
|
||||
export * from "./context.js"
|
||||
export * from "./core.js"
|
||||
export * from "./commands.js"
|
||||
export * from "./feeds.js"
|
||||
export * from "./follows.js"
|
||||
export * from "./handles.js"
|
||||
export * from "./mutes.js"
|
||||
export * from "./plaintext.js"
|
||||
export * from "./profiles.js"
|
||||
export * from "./pins.js"
|
||||
export * from "./relays.js"
|
||||
export * from "./relayStats.js"
|
||||
export * from "./relayLists.js"
|
||||
export * from "./blockedRelayLists.js"
|
||||
export * from "./messagingRelayLists.js"
|
||||
export * from "./search.js"
|
||||
export * from "./session.js"
|
||||
export * from "./sync.js"
|
||||
export * from "./tags.js"
|
||||
export * from "./thunk.js"
|
||||
export * from "./topics.js"
|
||||
export * from "./app.js"
|
||||
export * from "./policy.js"
|
||||
export * from "./user.js"
|
||||
export * from "./wot.js"
|
||||
export * from "./zappers.js"
|
||||
|
||||
import {derived} from "svelte/store"
|
||||
import {sortBy, throttleWithValue} from "@welshman/lib"
|
||||
import {
|
||||
isEphemeralKind,
|
||||
isDVMKind,
|
||||
WRAP,
|
||||
RelayMode,
|
||||
RelayProfile,
|
||||
getRelaysFromList,
|
||||
} from "@welshman/util"
|
||||
import {routerContext} from "@welshman/router"
|
||||
import {Pool, SocketEvent, isRelayEvent, netContext} from "@welshman/net"
|
||||
import {pubkey, unwrapAndStore} from "./session.js"
|
||||
import {repository, tracker} from "./core.js"
|
||||
import {getRelays, loadRelay} from "./relays.js"
|
||||
import {trackRelayStats, getRelayQuality} from "./relayStats.js"
|
||||
import {deriveRelayList, getRelayList} from "./relayLists.js"
|
||||
import {deriveSearchRelayList, getSearchRelayList} from "./searchRelayLists.js"
|
||||
import {deriveBlockedRelayList, getBlockedRelayList} from "./blockedRelayLists.js"
|
||||
import {deriveMessagingRelayList, getMessagingRelayList} from "./messagingRelayLists.js"
|
||||
|
||||
// Sync relays with our database
|
||||
|
||||
Pool.get().subscribe(socket => {
|
||||
loadRelay(socket.url)
|
||||
trackRelayStats(socket)
|
||||
|
||||
socket.on(SocketEvent.Receive, message => {
|
||||
if (isRelayEvent(message)) {
|
||||
const event = message[2]
|
||||
|
||||
if (
|
||||
!isDVMKind(event.kind) &&
|
||||
!isEphemeralKind(event.kind) &&
|
||||
netContext.isEventValid(event, socket.url)
|
||||
) {
|
||||
tracker.track(event.id, socket.url)
|
||||
|
||||
if (event.kind === WRAP) {
|
||||
unwrapAndStore(event)
|
||||
} else {
|
||||
repository.publish(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
// Configure the router and add a few other relay utils
|
||||
|
||||
const _relayGetter = (fn?: (relay: RelayProfile) => any) =>
|
||||
throttleWithValue(200, () => {
|
||||
let _relays = getRelays()
|
||||
|
||||
if (fn) {
|
||||
_relays = _relays.filter(fn)
|
||||
}
|
||||
|
||||
return sortBy(r => -getRelayQuality(r.url), _relays)
|
||||
.slice(0, 5)
|
||||
.map(r => r.url)
|
||||
})
|
||||
|
||||
export const getPubkeyRelays = (pubkey: string, mode?: RelayMode) => {
|
||||
if (mode === RelayMode.Search) return getRelaysFromList(getSearchRelayList(pubkey))
|
||||
if (mode === RelayMode.Blocked) return getRelaysFromList(getBlockedRelayList(pubkey))
|
||||
if (mode === RelayMode.Messaging) return getRelaysFromList(getMessagingRelayList(pubkey))
|
||||
return getRelaysFromList(getRelayList(pubkey), mode)
|
||||
}
|
||||
|
||||
export const derivePubkeyRelays = (pubkey: string, mode?: RelayMode) => {
|
||||
if (mode === RelayMode.Search)
|
||||
return derived(deriveSearchRelayList(pubkey), list => getRelaysFromList(list))
|
||||
if (mode === RelayMode.Blocked)
|
||||
return derived(deriveBlockedRelayList(pubkey), list => getRelaysFromList(list))
|
||||
if (mode === RelayMode.Messaging)
|
||||
return derived(deriveMessagingRelayList(pubkey), list => getRelaysFromList(list))
|
||||
return derived(deriveRelayList(pubkey), list => getRelaysFromList(list, mode))
|
||||
}
|
||||
|
||||
routerContext.getUserPubkey = () => pubkey.get()
|
||||
routerContext.getPubkeyRelays = getPubkeyRelays
|
||||
routerContext.getRelayQuality = getRelayQuality
|
||||
routerContext.getDefaultRelays = _relayGetter()
|
||||
routerContext.getIndexerRelays = _relayGetter()
|
||||
routerContext.getSearchRelays = _relayGetter(r => r?.supported_nips?.includes?.("50"))
|
||||
export * from "./session.js"
|
||||
export * from "./logging.js"
|
||||
export * from "./createApp.js"
|
||||
export * from "./plugins/base.js"
|
||||
export * from "./plugins/network.js"
|
||||
export * from "./plugins/stores.js"
|
||||
export * from "./plugins/router.js"
|
||||
export * from "./plugins/relays.js"
|
||||
export * from "./plugins/relayStats.js"
|
||||
export * from "./plugins/relayLists.js"
|
||||
export * from "./plugins/blockedRelayLists.js"
|
||||
export * from "./plugins/plaintext.js"
|
||||
export * from "./plugins/profiles.js"
|
||||
export * from "./plugins/follows.js"
|
||||
export * from "./plugins/mutes.js"
|
||||
export * from "./plugins/pins.js"
|
||||
export * from "./plugins/blossom.js"
|
||||
export * from "./plugins/messagingRelayLists.js"
|
||||
export * from "./plugins/searchRelayLists.js"
|
||||
export * from "./plugins/handles.js"
|
||||
export * from "./plugins/zappers.js"
|
||||
export * from "./plugins/topics.js"
|
||||
export * from "./plugins/tags.js"
|
||||
export * from "./plugins/wot.js"
|
||||
export * from "./plugins/feeds.js"
|
||||
export * from "./plugins/search.js"
|
||||
export * from "./plugins/sync.js"
|
||||
export * from "./plugins/wraps.js"
|
||||
export * from "./plugins/rooms.js"
|
||||
export * from "./plugins/relayManagement.js"
|
||||
export * from "./plugins/thunk.js"
|
||||
|
||||
Reference in New Issue
Block a user