Add wot to discover
This commit is contained in:
+13
-1
@@ -17,8 +17,9 @@ import {
|
||||
removeFromListByPredicate,
|
||||
getListTags,
|
||||
getRelayTags,
|
||||
isShareableRelayUrl,
|
||||
} from "@welshman/util"
|
||||
import type {TrustedEvent, EventTemplate} from "@welshman/util"
|
||||
import type {TrustedEvent, EventTemplate, List} from "@welshman/util"
|
||||
import type {SubscribeRequestWithHandlers} from "@welshman/net"
|
||||
import {PublishStatus, AuthStatus, ConnectionStatus} from "@welshman/net"
|
||||
import {Nip59, stamp} from "@welshman/signer"
|
||||
@@ -96,6 +97,7 @@ export const loadUserData = (
|
||||
await sleep(300)
|
||||
|
||||
for (const pubkey of pubkeys) {
|
||||
loadMembership(pubkey),
|
||||
loadProfile(pubkey)
|
||||
loadFollows(pubkey)
|
||||
loadMutes(pubkey)
|
||||
@@ -106,6 +108,16 @@ export const loadUserData = (
|
||||
return promise
|
||||
}
|
||||
|
||||
export const discoverRelays = (lists: List[]) => {
|
||||
const urls = uniq(lists.flatMap(getRelayUrls))
|
||||
|
||||
for (const url of urls) {
|
||||
if (isShareableRelayUrl(url)) {
|
||||
loadRelay(url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Synchronization
|
||||
|
||||
export const broadcastUserData = async (relays: string[]) => {
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
import Icon from "@lib/components/Icon.svelte"
|
||||
import Button from "@lib/components/Button.svelte"
|
||||
import RelayItem from "@app/components/RelayItem.svelte"
|
||||
import {discoverRelays} from "@app/state"
|
||||
|
||||
export let relays: Readable<string[]>
|
||||
export let addRelay: (url: string) => void
|
||||
@@ -16,7 +15,6 @@
|
||||
let element: Element
|
||||
|
||||
onMount(() => {
|
||||
const sub = discoverRelays()
|
||||
const scroller = createScroller({
|
||||
delay: 300,
|
||||
element: element.closest(".modal-box")!,
|
||||
@@ -26,7 +24,6 @@
|
||||
})
|
||||
|
||||
return () => {
|
||||
sub.close()
|
||||
scroller.stop()
|
||||
}
|
||||
})
|
||||
|
||||
+9
-12
@@ -14,6 +14,7 @@ import {
|
||||
max,
|
||||
pushToMapKey,
|
||||
nthEq,
|
||||
shuffle,
|
||||
} from "@welshman/lib"
|
||||
import {
|
||||
getIdFilters,
|
||||
@@ -54,6 +55,7 @@ import {
|
||||
hasNegentropy,
|
||||
pull,
|
||||
createSearch,
|
||||
userFollows,
|
||||
} from "@welshman/app"
|
||||
import type {AppSyncOpts} from "@welshman/app"
|
||||
import type {SubscribeRequestWithHandlers} from "@welshman/net"
|
||||
@@ -123,6 +125,13 @@ export const entityLink = (entity: string) => `https://coracle.social/${entity}`
|
||||
|
||||
export const tagRoom = (room: string, url: string) => [ROOM, room, url]
|
||||
|
||||
export const getDefaultPubkeys = () => {
|
||||
const appPubkeys = import.meta.env.VITE_DEFAULT_PUBKEYS.split(",")
|
||||
const userPubkeys = shuffle(getPubkeyTagValues(getListTags(get(userFollows))))
|
||||
|
||||
return userPubkeys.length > 5 ? userPubkeys : [...userPubkeys, ...appPubkeys]
|
||||
}
|
||||
|
||||
export const ensureUnwrapped = async (event: TrustedEvent) => {
|
||||
if (event.kind !== WRAP) {
|
||||
return event
|
||||
@@ -428,15 +437,3 @@ export const displayReaction = (content: string) => {
|
||||
if (content === "-") return "👎"
|
||||
return content
|
||||
}
|
||||
|
||||
export const discoverRelays = () =>
|
||||
subscribe({
|
||||
filters: [{kinds: [RELAYS]}],
|
||||
onEvent: (event: TrustedEvent) => {
|
||||
for (const url of getRelayTagValues(event.tags)) {
|
||||
if (isShareableRelayUrl(url)) {
|
||||
loadRelay(url)
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user