Fix some group related things

This commit is contained in:
Jon Staab 2024-06-17 12:28:19 -07:00
parent d87e8ca363
commit 0d8d832e87
8 changed files with 170 additions and 139 deletions

View File

@ -1,5 +1,6 @@
<script lang="ts"> <script lang="ts">
import {debounce} from "throttle-debounce" import {debounce} from "throttle-debounce"
import {equals} from "ramda"
import {isSearchFeed, makeSearchFeed, makeScopeFeed, Scope, getFeedArgs} from "@welshman/feeds" import {isSearchFeed, makeSearchFeed, makeScopeFeed, Scope, getFeedArgs} from "@welshman/feeds"
import {toSpliced} from "src/util/misc" import {toSpliced} from "src/util/misc"
import {boolCtrl} from "src/partials/utils" import {boolCtrl} from "src/partials/utils"
@ -11,6 +12,7 @@
import MenuItem from "src/partials/MenuItem.svelte" import MenuItem from "src/partials/MenuItem.svelte"
import FeedForm from "src/app/shared/FeedForm.svelte" import FeedForm from "src/app/shared/FeedForm.svelte"
import {router} from "src/app/util" import {router} from "src/app/util"
import {globalFeed} from "src/app/state"
import {normalizeFeedDefinition, displayList, readFeed, makeFeed, displayFeed} from "src/domain" import {normalizeFeedDefinition, displayList, readFeed, makeFeed, displayFeed} from "src/domain"
import {userListFeeds, canSign, deleteEvent, userFeeds} from "src/engine" import {userListFeeds, canSign, deleteEvent, userFeeds} from "src/engine"
@ -118,15 +120,27 @@
<Anchor modal href="/feeds/create"><i class="fa fa-plus" /></Anchor> <Anchor modal href="/feeds/create"><i class="fa fa-plus" /></Anchor>
</MenuItem> </MenuItem>
<div class="max-h-80 overflow-auto"> <div class="max-h-80 overflow-auto">
<MenuItem on:click={() => setFeed(followsFeed)}>Follows</MenuItem> <MenuItem
<MenuItem on:click={() => setFeed(networkFeed)}>Network</MenuItem> active={equals(followsFeed.definition, $globalFeed.definition)}
on:click={() => setFeed(followsFeed)}>
Follows
</MenuItem>
<MenuItem
active={equals(networkFeed.definition, $globalFeed.definition)}
on:click={() => setFeed(networkFeed)}>
Network
</MenuItem>
{#each $userFeeds as feed} {#each $userFeeds as feed}
<MenuItem on:click={() => setFeed(feed)}> <MenuItem
active={equals(feed.definition, $globalFeed.definition)}
on:click={() => setFeed(feed)}>
{displayFeed(feed)} {displayFeed(feed)}
</MenuItem> </MenuItem>
{/each} {/each}
{#each $userListFeeds as feed} {#each $userListFeeds as feed}
<MenuItem on:click={() => setFeed(feed)}> <MenuItem
active={equals(feed.definition, $globalFeed.definition)}
on:click={() => setFeed(feed)}>
{displayList(feed.list)} {displayList(feed.list)}
</MenuItem> </MenuItem>
{/each} {/each}

View File

@ -1,17 +1,19 @@
<script> <script>
import {ellipsize} from "hurdak" import {ellipsize} from "hurdak"
import {derived} from "svelte/store"
import {remove} from "@welshman/lib"
import Chip from "src/partials/Chip.svelte" import Chip from "src/partials/Chip.svelte"
import Card from "src/partials/Card.svelte" import Card from "src/partials/Card.svelte"
import GroupCircle from "src/app/shared/GroupCircle.svelte" import GroupCircle from "src/app/shared/GroupCircle.svelte"
import PersonCircles from "src/app/shared/PersonCircles.svelte" import PersonCircles from "src/app/shared/PersonCircles.svelte"
import {router} from "src/app/util/router" import {router} from "src/app/util/router"
import {displayGroup, deriveGroup, getWotCommunityMembers} from "src/engine" import {displayGroup, deriveGroup, userFollowsByCommunity, pubkey} from "src/engine"
export let address export let address
export let modal = false export let modal = false
const group = deriveGroup(address) const group = deriveGroup(address)
const members = $getWotCommunityMembers(address) const members = derived(userFollowsByCommunity, $m => remove($pubkey, $m.get(address) || []))
const enter = () => { const enter = () => {
const route = router.at("groups").of(address).at("notes") const route = router.at("groups").of(address).at("notes")
@ -45,9 +47,10 @@
{ellipsize($group.meta.about, 300)} {ellipsize($group.meta.about, 300)}
</p> </p>
{/if} {/if}
{#if members.length > 0} {#if $members.length > 0}
<p class="mt-4 text-lg text-neutral-300">Members:</p> <div class="pt-1">
<PersonCircles pubkeys={members.slice(0, 20)} /> <PersonCircles class="h-6 w-6" pubkeys={$members.slice(0, 20)} />
</div>
{/if} {/if}
</div> </div>
</Card> </Card>

View File

@ -44,6 +44,7 @@
{#await promise} {#await promise}
<!-- pass --> <!-- pass -->
{:then event} {:then event}
{#if event}
<div in:fly|local={{y: 20}}> <div in:fly|local={{y: 20}}>
<Card> <Card>
<FlexColumn> <FlexColumn>
@ -141,4 +142,5 @@
</FlexColumn> </FlexColumn>
</Card> </Card>
</div> </div>
{/if}
{/await} {/await}

View File

@ -1,7 +1,7 @@
import {partition, prop, uniqBy} from "ramda" import {partition, prop, uniqBy} from "ramda"
import {batch, tryFunc, seconds} from "hurdak" import {batch, tryFunc, seconds} from "hurdak"
import {writable, derived} from "svelte/store" import {writable, derived} from "svelte/store"
import {inc, pushToMapKey, sortBy, now} from "@welshman/lib" import {inc, assoc, pushToMapKey, sortBy, now} from "@welshman/lib"
import type {TrustedEvent} from "@welshman/util" import type {TrustedEvent} from "@welshman/util"
import { import {
Tags, Tags,
@ -127,14 +127,15 @@ export const createFeed = (opts: FeedOpts) => {
if (reqs && opts.shouldListen) { if (reqs && opts.shouldListen) {
const tracker = new Tracker() const tracker = new Tracker()
for (const {relays, filters} of reqs) { for (const request of reqs) {
for (const request of Array.from(getRequestItems({relays, filters}, opts))) { for (const {relays, filters} of Array.from(getRequestItems(request, opts))) {
subscribe({ subscribe({
...request, relays,
tracker, tracker,
skipCache: true, skipCache: true,
onEvent: prependEvent, onEvent: prependEvent,
signal: controller.signal, signal: controller.signal,
filters: filters.map(assoc('since', now())),
forcePlatform: opts.forcePlatform && (relays?.length || 0) === 0, forcePlatform: opts.forcePlatform && (relays?.length || 0) === 0,
}) })
} }

View File

@ -2,6 +2,7 @@
import cx from "classnames" import cx from "classnames"
import {onMount} from "svelte" import {onMount} from "svelte"
import {last, prop, objOf} from "ramda" import {last, prop, objOf} from "ramda"
import {tryCatch} from "@welshman/lib"
import {HANDLER_INFORMATION, NOSTR_CONNECT} from "@welshman/util" import {HANDLER_INFORMATION, NOSTR_CONNECT} from "@welshman/util"
import {tryJson} from "src/util/misc" import {tryJson} from "src/util/misc"
import {showWarning} from "src/partials/Toast.svelte" import {showWarning} from "src/partials/Toast.svelte"

View File

@ -11,6 +11,7 @@ import {
MUTES, MUTES,
FOLLOWS, FOLLOWS,
RELAYS, RELAYS,
COMMUNITIES,
} from "@welshman/util" } from "@welshman/util"
import {tryJson} from "src/util/misc" import {tryJson} from "src/util/misc"
import {appDataKeys, giftWrapKinds, getPublicKey} from "src/util/nostr" import {appDataKeys, giftWrapKinds, getPublicKey} from "src/util/nostr"
@ -195,9 +196,9 @@ projections.addHandler(27, (e: TrustedEvent) => {
} }
}) })
// Membership access/exit requests // Membership
projections.addHandler(10004, (e: TrustedEvent) => { projections.addHandler(COMMUNITIES, (e: TrustedEvent) => {
let session = getSession(e.pubkey) let session = getSession(e.pubkey)
if (!session) { if (!session) {

View File

@ -38,6 +38,7 @@ import {
sort, sort,
groupBy, groupBy,
indexBy, indexBy,
pushToMapKey,
} from "@welshman/lib" } from "@welshman/lib"
import { import {
WRAP, WRAP,
@ -689,7 +690,7 @@ export const communityLists = withGetter(
) )
export const communityListsByPubkey = withGetter( export const communityListsByPubkey = withGetter(
derived(muteLists, $ls => indexBy($l => $l.event.pubkey, $ls)), derived(communityLists, $ls => indexBy($l => $l.event.pubkey, $ls)),
) )
export const getCommunityList = (pk: string) => export const getCommunityList = (pk: string) =>
@ -703,16 +704,17 @@ export const getCommunities = (pk: string) => getSingletonValues("a", getCommuni
export const deriveCommunities = (pk: string) => export const deriveCommunities = (pk: string) =>
derived(communityListsByPubkey, m => getSingletonValues("a", m.get(pk))) derived(communityListsByPubkey, m => getSingletonValues("a", m.get(pk)))
export const getWotCommunityMembers = withGetter( export const userFollowsByCommunity = derived(communityLists, $communityLists => {
derived( const m = new Map<string, string[]>()
[userFollows, communityListsByPubkey],
([$userFollows, $communityListsByPubkey]) => for (const list of $communityLists) {
address => for (const a of getSingletonValues("a", list)) {
Array.from($userFollows).filter(pk => pushToMapKey(m, a, list.event.pubkey)
getSingletonValues("a", $communityListsByPubkey.get(pk)), }
), }
),
) return m
})
// Groups // Groups
@ -722,10 +724,12 @@ export const deriveGroup = address => {
return groups.key(address).derived(defaultTo({id, pubkey, address})) return groups.key(address).derived(defaultTo({id, pubkey, address}))
} }
export const searchGroups = groups.throttle(300).derived($groups => { export const searchGroups = derived(
[groups.throttle(300), userFollowsByCommunity],
([$groups, $userFollowsByCommunity]) => {
const options = $groups const options = $groups
.filter(group => !repository.deletes.has(group.address)) .filter(group => !repository.deletes.has(group.address))
.map(group => ({group, score: getWotCommunityMembers.get()(group.address).length})) .map(group => ({group, score: $userFollowsByCommunity.get(group.address)?.length || 0}))
const fuse = new Fuse(options, { const fuse = new Fuse(options, {
keys: [{name: "group.id", weight: 0.2}, "group.meta.name", "group.meta.about"], keys: [{name: "group.id", weight: 0.2}, "group.meta.name", "group.meta.about"],
@ -745,7 +749,8 @@ export const searchGroups = groups.throttle(300).derived($groups => {
$results => $results.map((r: any) => r.item.group), $results => $results.map((r: any) => r.item.group),
]) ])
} }
}) },
)
export const getRecipientKey = wrap => { export const getRecipientKey = wrap => {
const pubkey = Tags.fromEvent(wrap).values("p").first() const pubkey = Tags.fromEvent(wrap).values("p").first()
@ -1601,6 +1606,8 @@ export const publish = ({forcePlatform = true, ...request}: MyPublishRequest) =>
// Add the event to projections // Add the event to projections
if (canUnwrap(request.event)) { if (canUnwrap(request.event)) {
ensureUnwrapped(request.event).then(projections.push) ensureUnwrapped(request.event).then(projections.push)
} else {
projections.push(request.event)
} }
// Listen to updates and update our publish queue // Listen to updates and update our publish queue

View File

@ -3,12 +3,14 @@
import Anchor from "src/partials/Anchor.svelte" import Anchor from "src/partials/Anchor.svelte"
export let inert = false export let inert = false
export let active = false
</script> </script>
<Anchor <Anchor
{...$$props} {...$$props}
class={cx($$props.class, "block p-3 px-4", { class={cx($$props.class, "block p-3 px-4", {
"transition-all hover:bg-accent hover:text-white": !inert, "bg-accent text-neutral-100": active,
"transition-all hover:bg-accent hover:text-neutral-100": !inert,
})} })}
on:click> on:click>
<slot /> <slot />