mirror of
https://github.com/coracle-social/coracle.git
synced 2024-09-29 00:10:52 +00:00
Fix anonymous usage
This commit is contained in:
parent
843da0bd45
commit
d7bca1af6f
@ -99,7 +99,7 @@
|
||||
</script>
|
||||
|
||||
<div class="flex items-center gap-3" on:click|stopPropagation>
|
||||
{#if !isSelf && ($canSign || !$session.pubkey)}
|
||||
{#if !isSelf && ($canSign || !$session)}
|
||||
<Popover triggerType="mouseenter">
|
||||
<div slot="trigger" class="w-6 cursor-pointer text-center">
|
||||
{#if $following}
|
||||
|
@ -44,10 +44,10 @@
|
||||
onMount(() => {
|
||||
const {admins} = getGroupReqInfo()
|
||||
const scroller = createScroller(loadMore, {element})
|
||||
const loader = loadGiftWraps()
|
||||
|
||||
updateCurrentSession(assoc("groups_last_synced", now()))
|
||||
|
||||
const loaders = [loadGiftWraps(), loadGroupMessages()]
|
||||
loadGroupMessages()
|
||||
|
||||
load({
|
||||
skipCache: true,
|
||||
@ -59,8 +59,8 @@
|
||||
})
|
||||
|
||||
return () => {
|
||||
loader.stop()
|
||||
scroller.stop()
|
||||
loaders.forEach(loader => loader.stop())
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
@ -31,7 +31,9 @@
|
||||
const searchRelays = async relays => {
|
||||
failed = false
|
||||
|
||||
await loadPubkeyUserData([$session.pubkey], {relays})
|
||||
loadPubkeyUserData([$session.pubkey], {relays})
|
||||
|
||||
await sleep(3000)
|
||||
|
||||
if (!found) {
|
||||
failed = true
|
||||
|
@ -1,5 +1,6 @@
|
||||
import {last} from '@welshman/lib'
|
||||
import {LOCAL_RELAY_URL, normalizeRelayUrl as _normalizeRelayUrl} from '@welshman/util'
|
||||
import {last} from "@welshman/lib"
|
||||
import {LOCAL_RELAY_URL, normalizeRelayUrl as _normalizeRelayUrl} from "@welshman/util"
|
||||
import {getRelayTags} from "src/util/nostr"
|
||||
|
||||
// Utils related to bare urls
|
||||
|
||||
@ -20,10 +21,10 @@ export const displayRelayUrl = (url: string) => last(url.split("://")).replace(/
|
||||
// Relay profiles
|
||||
|
||||
export type RelayProfile = {
|
||||
url: string,
|
||||
name?: string,
|
||||
url: string
|
||||
name?: string
|
||||
contact?: string
|
||||
description?: string,
|
||||
description?: string
|
||||
supported_nips?: number[]
|
||||
limitation?: {
|
||||
payment_required?: boolean
|
||||
@ -49,9 +50,17 @@ export type RelayPolicy = {
|
||||
write: boolean
|
||||
}
|
||||
|
||||
export const makeRelayPolicy = (relayPolicy: Partial<RelayPolicy> & {url: string}): RelayPolicy => ({
|
||||
export const makeRelayPolicy = (
|
||||
relayPolicy: Partial<RelayPolicy> & {url: string},
|
||||
): RelayPolicy => ({
|
||||
read: false,
|
||||
write: false,
|
||||
...relayPolicy,
|
||||
})
|
||||
|
||||
export const makeRelayPoliciesFromTags = (tags: string[][]) =>
|
||||
getRelayTags(tags).map(([_, url, mode]) => ({
|
||||
url: normalizeRelayUrl(url),
|
||||
write: !mode || mode === RelayMode.Write,
|
||||
read: !mode || mode === RelayMode.Read,
|
||||
}))
|
||||
|
@ -35,7 +35,7 @@ export const indexSingleton = (singleton: IndexableSingleton): Singleton => {
|
||||
return {...singleton, valuesByKey}
|
||||
}
|
||||
|
||||
export const makeSingleton = (singleton: SingletonParams): Singleton =>
|
||||
export const makeSingleton = (singleton: SingletonParams & Partial<Singleton>): Singleton =>
|
||||
indexSingleton({publicTags: [], privateTags: [], ...singleton})
|
||||
|
||||
const isValidTag = (tag: string[]) => {
|
||||
|
@ -700,7 +700,7 @@ export const unfollowPerson = (pubkey: string) => {
|
||||
if (canSign.get()) {
|
||||
updateSingleton(FOLLOWS, reject(nthEq(1, pubkey)))
|
||||
} else {
|
||||
anonymous.update($a => ({...$a, follows: append($a.follows, mention(pubkey))}))
|
||||
anonymous.update($a => ({...$a, follows: reject(nthEq(1, pubkey), $a.follows)}))
|
||||
}
|
||||
}
|
||||
|
||||
@ -733,10 +733,10 @@ export const requestRelayAccess = async (url: string, claim: string, sk?: string
|
||||
})
|
||||
|
||||
export const setRelayPolicies = async (modifyTags: ModifyTags) => {
|
||||
anonymous.update($a => ({...$a, relays: modifyTags($a.relays)}))
|
||||
|
||||
if (canSign.get()) {
|
||||
updateSingleton(RELAYS, modifyTags)
|
||||
} else {
|
||||
anonymous.update($a => ({...$a, relays: modifyTags($a.relays)}))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,25 +58,34 @@ const getFiltersForKey = (key: string, authors: string[]) => {
|
||||
}
|
||||
}
|
||||
|
||||
const loadPubkeysThrottled = batch(300, (requests: {key: string; pubkeys: string[]}[]) => {
|
||||
const pubkeysByKey = new Map<string, Set<string>>()
|
||||
const loadPubkeysThrottled = batch(
|
||||
300,
|
||||
async (requests: {key: string; pubkeys: string[]; resolve: () => void}[]) => {
|
||||
const pubkeysByKey = new Map<string, Set<string>>()
|
||||
|
||||
for (const {key, pubkeys} of requests) {
|
||||
for (const pubkey of pubkeys) {
|
||||
addToMapKey(pubkeysByKey, key, pubkey)
|
||||
for (const {key, pubkeys} of requests) {
|
||||
for (const pubkey of pubkeys) {
|
||||
addToMapKey(pubkeysByKey, key, pubkey)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const [key, pubkeys] of pubkeysByKey.entries()) {
|
||||
const authors = Array.from(pubkeys)
|
||||
await Promise.all([
|
||||
Array.from(pubkeysByKey.entries()).map(([key, pubkeys]) => {
|
||||
const authors = Array.from(pubkeys)
|
||||
|
||||
load({
|
||||
skipCache: true,
|
||||
filters: getFiltersForKey(key, authors),
|
||||
relays: withIndexers(hints.FromPubkeys(authors).getUrls()),
|
||||
})
|
||||
}
|
||||
})
|
||||
return load({
|
||||
skipCache: true,
|
||||
filters: getFiltersForKey(key, authors),
|
||||
relays: withIndexers(hints.FromPubkeys(authors).getUrls()),
|
||||
})
|
||||
}),
|
||||
])
|
||||
|
||||
for (const {resolve} of requests) {
|
||||
resolve()
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
type LoadPubkeyOpts = {
|
||||
force?: boolean
|
||||
@ -91,9 +100,13 @@ const loadPubkeyData = (
|
||||
const delta = force ? 5 : seconds(15, "minute")
|
||||
const pubkeys = getStalePubkeys(rawPubkeys, key, delta)
|
||||
|
||||
if (pubkeys.length > 0) {
|
||||
loadPubkeysThrottled({key, pubkeys})
|
||||
}
|
||||
return new Promise<void>(resolve => {
|
||||
if (pubkeys.length > 0) {
|
||||
loadPubkeysThrottled({key, pubkeys, resolve})
|
||||
} else {
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export const loadPubkeyLists = (pubkeys: string[], opts: LoadPubkeyOpts = {}) =>
|
||||
@ -108,10 +121,14 @@ export const loadPubkeyRelays = (pubkeys: string[], opts: LoadPubkeyOpts = {}) =
|
||||
export const loadPubkeyProfiles = (pubkeys: string[], opts: LoadPubkeyOpts = {}) =>
|
||||
loadPubkeyData("pubkey/profile", pubkeys, opts)
|
||||
|
||||
export const loadPubkeys = (pubkeys: string[], opts: LoadPubkeyOpts = {}) => {
|
||||
loadPubkeyRelays(pubkeys, opts)
|
||||
loadPubkeyProfiles(pubkeys, opts)
|
||||
}
|
||||
|
||||
export const loadPubkeyUserData = (pubkeys: string[], opts: LoadPubkeyOpts = {}) =>
|
||||
loadPubkeyData("pubkey/user", pubkeys, {force: true, ...opts})
|
||||
|
||||
export const loadPubkeys = async (pubkeys: string[], opts: LoadPubkeyOpts = {}) =>
|
||||
// Load relays, then load profiles so we have a better chance of finding them. But also
|
||||
// load profiles concurrently so that if we do find them it takes as little time as possible.
|
||||
// Requests will be deduplicated by tracking freshness and within welshman
|
||||
Promise.all([
|
||||
loadPubkeyRelays(pubkeys, opts).then(() => loadPubkeyProfiles(pubkeys, opts)),
|
||||
loadPubkeyProfiles(pubkeys, opts),
|
||||
])
|
||||
|
@ -104,6 +104,8 @@ import type {
|
||||
import {
|
||||
EDITABLE_LIST_KINDS,
|
||||
getSingletonValues,
|
||||
makeSingleton,
|
||||
makeRelayPoliciesFromTags,
|
||||
ListSearch,
|
||||
FeedSearch,
|
||||
profileHasName,
|
||||
@ -119,7 +121,6 @@ import {
|
||||
displayPubkey,
|
||||
readSingleton,
|
||||
asDecryptedEvent,
|
||||
RelayMode,
|
||||
normalizeRelayUrl,
|
||||
makeRelayPolicy,
|
||||
filterRelaysByNip,
|
||||
@ -571,7 +572,12 @@ export const getWotScore = (pk, tpk) => {
|
||||
|
||||
// User follows/mutes/network
|
||||
|
||||
export const userFollowList = derived([followListsByPubkey, pubkey], ([$m, $pk]) => $m.get($pk))
|
||||
export const userFollowList = derived(
|
||||
[followListsByPubkey, pubkey, anonymous],
|
||||
([$m, $pk, $anon]) => {
|
||||
return $pk ? $m.get($pk) : makeSingleton({kind: FOLLOWS, publicTags: $anon.follows})
|
||||
},
|
||||
)
|
||||
|
||||
export const userFollows = derived(userFollowList, l => getSingletonValues("p", l))
|
||||
|
||||
@ -1056,20 +1062,7 @@ export const relayPoliciesByPubkey = withGetter(
|
||||
const policies = new Map<string, RelayPolicy[]>()
|
||||
|
||||
for (const {event, publicTags} of $relayLists) {
|
||||
const policy = publicTags
|
||||
.filter(([_, url]) => isShareableRelayUrl(url))
|
||||
.map(([_, url, mode]) => {
|
||||
const write = !mode || mode === RelayMode.Write
|
||||
const read = !mode || mode === RelayMode.Read
|
||||
|
||||
if (!write && !read) {
|
||||
logger.warn(`Encountered unknown relay mode: ${mode}`)
|
||||
}
|
||||
|
||||
return {url: normalizeRelayUrl(url), write, read}
|
||||
})
|
||||
|
||||
policies.set(event.pubkey, policy)
|
||||
policies.set(event.pubkey, makeRelayPoliciesFromTags(publicTags))
|
||||
}
|
||||
|
||||
for (const {event, policy} of $legacyRelayLists) {
|
||||
@ -1089,8 +1082,10 @@ export const getPubkeyRelayPolicies = (pubkey: string, mode: string = null) => {
|
||||
}
|
||||
|
||||
export const userRelayPolicies = derived(
|
||||
[relayPoliciesByPubkey, pubkey],
|
||||
([$relayPoliciesByPubkey, $pubkey]) => $relayPoliciesByPubkey.get($pubkey),
|
||||
[relayPoliciesByPubkey, pubkey, anonymous],
|
||||
([$m, $pk, $anon]) => {
|
||||
return $pk ? $m.get($pk) : makeRelayPoliciesFromTags($anon.relays)
|
||||
},
|
||||
)
|
||||
|
||||
export const deriveUserRelayPolicy = url =>
|
||||
|
Loading…
Reference in New Issue
Block a user