Add blossom server collections
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
import {BLOSSOM_SERVERS, asDecryptedEvent, readList} from "@welshman/util"
|
||||||
|
import {TrustedEvent, PublishedList} from "@welshman/util"
|
||||||
|
import {deriveEventsMapped, collection} from "@welshman/store"
|
||||||
|
import {repository} from "./core.js"
|
||||||
|
import {makeOutboxLoader} from "./relaySelections.js"
|
||||||
|
|
||||||
|
export const blossomServers = deriveEventsMapped<PublishedList>(repository, {
|
||||||
|
filters: [{kinds: [BLOSSOM_SERVERS]}],
|
||||||
|
itemToEvent: item => item.event,
|
||||||
|
eventToItem: (event: TrustedEvent) => readList(asDecryptedEvent(event)),
|
||||||
|
})
|
||||||
|
|
||||||
|
export const {
|
||||||
|
indexStore: blossomServersByPubkey,
|
||||||
|
deriveItem: deriveBlossomServers,
|
||||||
|
loadItem: loadBlossomServers,
|
||||||
|
} = collection({
|
||||||
|
name: "blossomServers",
|
||||||
|
store: blossomServers,
|
||||||
|
getKey: blossomServers => blossomServers.event.pubkey,
|
||||||
|
load: makeOutboxLoader(BLOSSOM_SERVERS),
|
||||||
|
})
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
export * from "./blossom.js"
|
||||||
export * from "./context.js"
|
export * from "./context.js"
|
||||||
export * from "./core.js"
|
export * from "./core.js"
|
||||||
export * from "./commands.js"
|
export * from "./commands.js"
|
||||||
|
|||||||
+41
-41
@@ -1,9 +1,11 @@
|
|||||||
import {derived} from "svelte/store"
|
import {derived, Readable} from "svelte/store"
|
||||||
|
import {withGetter} from "@welshman/store"
|
||||||
import {pubkey} from "./session.js"
|
import {pubkey} from "./session.js"
|
||||||
import {profilesByPubkey, loadProfile} from "./profiles.js"
|
import {profilesByPubkey, loadProfile} from "./profiles.js"
|
||||||
import {followsByPubkey, loadFollows} from "./follows.js"
|
import {followsByPubkey, loadFollows} from "./follows.js"
|
||||||
import {loadPins, pinsByPubkey} from "./pins.js"
|
import {loadPins, pinsByPubkey} from "./pins.js"
|
||||||
import {mutesByPubkey, loadMutes} from "./mutes.js"
|
import {mutesByPubkey, loadMutes} from "./mutes.js"
|
||||||
|
import {blossomServersByPubkey, loadBlossomServers} from "./blossom.js"
|
||||||
import {
|
import {
|
||||||
relaySelectionsByPubkey,
|
relaySelectionsByPubkey,
|
||||||
inboxRelaySelectionsByPubkey,
|
inboxRelaySelectionsByPubkey,
|
||||||
@@ -12,58 +14,56 @@ import {
|
|||||||
} from "./relaySelections.js"
|
} from "./relaySelections.js"
|
||||||
import {wotGraph} from "./wot.js"
|
import {wotGraph} from "./wot.js"
|
||||||
|
|
||||||
export const userProfile = derived([profilesByPubkey, pubkey], ([$profilesByPubkey, $pubkey]) => {
|
export type MakeUserDataOptions<T> = {
|
||||||
if (!$pubkey) return undefined
|
mapStore: Readable<Map<string, T>>
|
||||||
|
loadItem: (pubkey: string) => unknown
|
||||||
|
}
|
||||||
|
|
||||||
loadProfile($pubkey)
|
const makeUserData = <T>({mapStore, loadItem}: MakeUserDataOptions<T>) =>
|
||||||
|
withGetter(
|
||||||
|
derived([mapStore, pubkey], ([$mapStore, $pubkey]) => {
|
||||||
|
if (!$pubkey) return undefined
|
||||||
|
|
||||||
return $profilesByPubkey.get($pubkey)
|
loadItem($pubkey)
|
||||||
|
|
||||||
|
return $mapStore.get($pubkey)
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
export const userProfile = makeUserData({
|
||||||
|
mapStore: profilesByPubkey,
|
||||||
|
loadItem: loadProfile,
|
||||||
})
|
})
|
||||||
|
|
||||||
export const userFollows = derived([followsByPubkey, pubkey], ([$followsByPubkey, $pubkey]) => {
|
export const userFollows = makeUserData({
|
||||||
if (!$pubkey) return undefined
|
mapStore: followsByPubkey,
|
||||||
|
loadItem: loadFollows,
|
||||||
loadFollows($pubkey)
|
|
||||||
|
|
||||||
return $followsByPubkey.get($pubkey)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export const userMutes = derived([mutesByPubkey, pubkey], ([$mutesByPubkey, $pubkey]) => {
|
export const userMutes = makeUserData({
|
||||||
if (!$pubkey) return undefined
|
mapStore: mutesByPubkey,
|
||||||
|
loadItem: loadMutes,
|
||||||
loadMutes($pubkey)
|
|
||||||
|
|
||||||
return $mutesByPubkey.get($pubkey)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export const userPins = derived([pinsByPubkey, pubkey], ([$pinsByPubkey, $pubkey]) => {
|
export const userPins = makeUserData({
|
||||||
if (!$pubkey) return undefined
|
mapStore: pinsByPubkey,
|
||||||
|
loadItem: loadPins,
|
||||||
loadPins($pubkey)
|
|
||||||
return $pinsByPubkey.get($pubkey)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export const userRelaySelections = derived(
|
export const userRelaySelections = makeUserData({
|
||||||
[relaySelectionsByPubkey, pubkey],
|
mapStore: relaySelectionsByPubkey,
|
||||||
([$relaySelectionsByPubkey, $pubkey]) => {
|
loadItem: loadRelaySelections,
|
||||||
if (!$pubkey) return undefined
|
})
|
||||||
|
|
||||||
loadRelaySelections($pubkey)
|
export const userInboxRelaySelections = makeUserData({
|
||||||
|
mapStore: inboxRelaySelectionsByPubkey,
|
||||||
|
loadItem: loadInboxRelaySelections,
|
||||||
|
})
|
||||||
|
|
||||||
return $relaySelectionsByPubkey.get($pubkey)
|
export const userBlossomServers = makeUserData({
|
||||||
},
|
mapStore: blossomServersByPubkey,
|
||||||
)
|
loadItem: loadBlossomServers,
|
||||||
|
})
|
||||||
export const userInboxRelaySelections = derived(
|
|
||||||
[inboxRelaySelectionsByPubkey, pubkey],
|
|
||||||
([$inboxRelaySelectionsByPubkey, $pubkey]) => {
|
|
||||||
if (!$pubkey) return undefined
|
|
||||||
|
|
||||||
loadInboxRelaySelections($pubkey)
|
|
||||||
|
|
||||||
return $inboxRelaySelectionsByPubkey.get($pubkey)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
export const getUserWotScore = (tpk: string) => wotGraph.get().get(tpk) || 0
|
export const getUserWotScore = (tpk: string) => wotGraph.get().get(tpk) || 0
|
||||||
|
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ export const FEEDS = 10014
|
|||||||
export const TOPICS = 10015
|
export const TOPICS = 10015
|
||||||
export const EMOJIS = 10030
|
export const EMOJIS = 10030
|
||||||
export const INBOX_RELAYS = 10050
|
export const INBOX_RELAYS = 10050
|
||||||
|
export const BLOSSOM_SERVERS = 10063
|
||||||
export const FILE_SERVERS = 10096
|
export const FILE_SERVERS = 10096
|
||||||
export const LIGHTNING_PUB_RPC = 21000
|
export const LIGHTNING_PUB_RPC = 21000
|
||||||
export const CLIENT_AUTH = 22242
|
export const CLIENT_AUTH = 22242
|
||||||
|
|||||||
@@ -109,3 +109,5 @@ export const getReplyTagValues = (tags: string[][]) =>
|
|||||||
export const uniqTags = (tags: string[][]) => uniqBy(t => t.slice(0, 2).join(":"), tags)
|
export const uniqTags = (tags: string[][]) => uniqBy(t => t.slice(0, 2).join(":"), tags)
|
||||||
|
|
||||||
export const tagsFromIMeta = (imeta: string[]) => imeta.map((m: string) => m.split(" "))
|
export const tagsFromIMeta = (imeta: string[]) => imeta.map((m: string) => m.split(" "))
|
||||||
|
|
||||||
|
export const tagger = (name: string) => (value: string) => [name, value]
|
||||||
|
|||||||
Reference in New Issue
Block a user