Optimize deriveDisplaysByPubkey
This commit is contained in:
parent
8cb89f362c
commit
4f584e3f5d
1 changed files with 26 additions and 11 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import {derived} from "svelte/store"
|
import {derived} from "svelte/store"
|
||||||
import {pushToMapKey, removeUndefined, shuffle, sortBy, uniqBy} from "@welshman/lib"
|
import {noop, pushToMapKey, removeUndefined, shuffle, sortBy, uniqBy} from "@welshman/lib"
|
||||||
import {
|
import {
|
||||||
COMMENT,
|
COMMENT,
|
||||||
addressTags,
|
addressTags,
|
||||||
|
|
@ -12,20 +12,35 @@ import {
|
||||||
} from "@welshman/util"
|
} from "@welshman/util"
|
||||||
import type {TrustedEvent} from "@welshman/util"
|
import type {TrustedEvent} from "@welshman/util"
|
||||||
import {withGetter} from "@welshman/store"
|
import {withGetter} from "@welshman/store"
|
||||||
import {getCommentTagValues, getReplyTagValues} from "@welshman/domain"
|
import {displayPubkey, getCommentTagValues, getReplyTagValues} from "@welshman/domain"
|
||||||
import {FollowLists, MuteLists} from "@welshman/app"
|
import {FollowLists, MuteLists, Profiles} from "@welshman/app"
|
||||||
import {deriveUserItem, profiles, user} from "@app/core"
|
import {deriveUserItem, fromApp, profiles, user} from "@app/core"
|
||||||
import {DEFAULT_PUBKEYS} from "@app/env"
|
import {DEFAULT_PUBKEYS} from "@app/env"
|
||||||
|
|
||||||
// The display names for a group of people, as a store rather than a snapshot. A display starts
|
const profileIndex = fromApp($app => $app.use(Profiles).index.$)
|
||||||
// out as the author's npub and only becomes their name once the profile loads, so reading it once
|
|
||||||
// leaves a name frozen as bech32 — and reading it that way never asks for the profile at all.
|
export const deriveDisplaysByPubkey = (pubkeys: string[], url?: string) => {
|
||||||
export const deriveDisplaysByPubkey = (pubkeys: string[], url?: string) =>
|
const relays = removeUndefined([url])
|
||||||
derived(
|
|
||||||
pubkeys.map(pubkey => profiles.get().display(pubkey, removeUndefined([url])).$),
|
// Load profiles
|
||||||
displays => new Map(pubkeys.map((pubkey, i) => [pubkey, displays[i]])),
|
for (const pubkey of pubkeys) {
|
||||||
|
if (pubkey) {
|
||||||
|
profiles.get().load(pubkey, relays).catch(noop)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return derived(
|
||||||
|
profileIndex,
|
||||||
|
$index =>
|
||||||
|
new Map(
|
||||||
|
pubkeys.map(pubkey => [
|
||||||
|
pubkey,
|
||||||
|
pubkey ? ($index.get(pubkey)?.display() ?? displayPubkey(pubkey)) : "",
|
||||||
|
]),
|
||||||
|
),
|
||||||
new Map<string, string>(),
|
new Map<string, string>(),
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export const bootstrapPubkeys = derived(deriveUserItem(FollowLists), $userFollowList => {
|
export const bootstrapPubkeys = derived(deriveUserItem(FollowLists), $userFollowList => {
|
||||||
const appPubkeys = DEFAULT_PUBKEYS.split(",")
|
const appPubkeys = DEFAULT_PUBKEYS.split(",")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue