Compare commits

...

7 Commits

Author SHA1 Message Date
Jon Staab e212297396 Bump welshman/net 2024-06-20 12:12:48 -07:00
Jon Staab c9db37c92a Fix profile loading, improve feed list item updating 2024-06-20 11:08:13 -07:00
Jon Staab 148a63d95f Bump versions 2024-06-20 10:25:48 -07:00
Jon Staab a5517f2eff Add feed favorites 2024-06-20 10:15:28 -07:00
Jon Staab b92b0b71b5 Add global feeds 2024-06-19 14:52:29 -07:00
Jon Staab c6cdcfb2f8 Fix some note rendering bugs, throw error when dufflepud is not configured 2024-06-19 11:16:30 -07:00
Jon Staab c80988882b Pull group meta directly from events 2024-06-18 17:20:12 -07:00
52 changed files with 647 additions and 547 deletions

View File

@ -10,6 +10,8 @@
- [x] Fix several community and calendar related bugs
- [x] Add reports using tagr-bot
- [x] Open links to coracle in same tab
- [x] Add global feeds
- [x] Add feed favorites
# 0.4.6

67
package-lock.json generated
View File

@ -19,10 +19,10 @@
"@getalby/bitcoin-connect": "^3.2.2",
"@scure/base": "^1.1.6",
"@welshman/content": "^0.0.5",
"@welshman/feeds": "^0.0.11",
"@welshman/lib": "^0.0.9",
"@welshman/net": "^0.0.13",
"@welshman/util": "^0.0.14",
"@welshman/feeds": "^0.0.12",
"@welshman/lib": "^0.0.10",
"@welshman/net": "^0.0.14",
"@welshman/util": "^0.0.15",
"bowser": "^2.11.0",
"classnames": "^2.5.1",
"compressorjs": "^1.2.1",
@ -4603,14 +4603,14 @@
}
},
"node_modules/@welshman/feeds": {
"version": "0.0.11",
"resolved": "https://registry.npmjs.org/@welshman/feeds/-/feeds-0.0.11.tgz",
"integrity": "sha512-PxK5VKoq4oZXCvj5RuefSvUZczCE3xbtJ9zdfuYbdyMlRkQA3dS50zNZkPeDJat3ww0zH2PCYRjBmJcZQoZGYg==",
"version": "0.0.12",
"resolved": "https://registry.npmjs.org/@welshman/feeds/-/feeds-0.0.12.tgz",
"integrity": "sha512-TRKxwplWN4ojQwJTe68YAw/8Ti4Fsmz2pUiGEcdzEKYRmWyuZJ+H3Gcvv8D+9fSK6apA6vdjCIdugho8RusWQg==",
"dependencies": {
"@welshman/util": "0.0.14"
}
},
"node_modules/@welshman/lib": {
"node_modules/@welshman/feeds/node_modules/@welshman/lib": {
"version": "0.0.9",
"resolved": "https://registry.npmjs.org/@welshman/lib/-/lib-0.0.9.tgz",
"integrity": "sha512-1wR/FtrmGfKWPCLpySyOlQoJ4sBvMvXBjNfQseYeBJNCLrdn4eN3hJc8M3URPaLSLuP4/uB6DD54wntfnJ43kA==",
@ -4622,18 +4622,7 @@
"throttle-debounce": "^5.0.0"
}
},
"node_modules/@welshman/net": {
"version": "0.0.13",
"resolved": "https://registry.npmjs.org/@welshman/net/-/net-0.0.13.tgz",
"integrity": "sha512-Rx08jQdGNj6Xb0tcXIxVZcMUQO/n0wzdMvHBVu5PI1Kd6nhbj6tgQ47nS+dV1kmlE3pTe8U1l3VOXkW3YdFxpQ==",
"dependencies": {
"@welshman/lib": "0.0.9",
"@welshman/util": "0.0.14",
"isomorphic-ws": "^5.0.0",
"ws": "^8.16.0"
}
},
"node_modules/@welshman/util": {
"node_modules/@welshman/feeds/node_modules/@welshman/util": {
"version": "0.0.14",
"resolved": "https://registry.npmjs.org/@welshman/util/-/util-0.0.14.tgz",
"integrity": "sha512-kpSJ3Ve2oQei/wA1Y6ZuhQr1v46dSUzta/YnUIC1sBmamGXpsYlXG4QrKQpqtB15dJyGRhxTILIvJ/529y3LMA==",
@ -4642,6 +4631,38 @@
"nostr-tools": "^2.3.2"
}
},
"node_modules/@welshman/lib": {
"version": "0.0.10",
"resolved": "https://registry.npmjs.org/@welshman/lib/-/lib-0.0.10.tgz",
"integrity": "sha512-qg7erF16oIZy9zWYIxidqrRwVY0pveHN9aEPRia6/CUnN4g6PuSAPCCeQbKG0HkWLsY9/E/vvmGNAfwKlAIaIw==",
"dependencies": {
"@scure/base": "^1.1.6",
"@types/events": "^3.0.3",
"@types/throttle-debounce": "^5.0.2",
"events": "^3.3.0",
"throttle-debounce": "^5.0.0"
}
},
"node_modules/@welshman/net": {
"version": "0.0.14",
"resolved": "https://registry.npmjs.org/@welshman/net/-/net-0.0.14.tgz",
"integrity": "sha512-fHW+EEMT/dsxwKrhIEntsZbv7uGtYrdNt/lIbLnc4h0F9n2fdi/3HBMBINbxeUb+3eAindeIuYrCnD72sKpkhA==",
"dependencies": {
"@welshman/lib": "0.0.10",
"@welshman/util": "0.0.15",
"isomorphic-ws": "^5.0.0",
"ws": "^8.16.0"
}
},
"node_modules/@welshman/util": {
"version": "0.0.15",
"resolved": "https://registry.npmjs.org/@welshman/util/-/util-0.0.15.tgz",
"integrity": "sha512-v82QSwDSc48URqXA7SaL5FZLOBN1LHmamIBXart1iGBheXdA+VSDEJG2HjI8Iq6RanKQRBVzbTP+rwUXq1lePw==",
"dependencies": {
"@welshman/lib": "0.0.10",
"nostr-tools": "^2.3.2"
}
},
"node_modules/@xmldom/xmldom": {
"version": "0.8.10",
"resolved": "https://registry.npmjs.org/@xmldom/xmldom/-/xmldom-0.8.10.tgz",
@ -14671,9 +14692,9 @@
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="
},
"node_modules/ws": {
"version": "8.17.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.17.0.tgz",
"integrity": "sha512-uJq6108EgZMAl20KagGkzCKfMEjxmKvZHG7Tlq0Z6nOky7YF7aq4mOx6xK8TJ/i1LeK4Qus7INktacctDgY8Ow==",
"version": "8.17.1",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz",
"integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==",
"engines": {
"node": ">=10.0.0"
},

View File

@ -56,10 +56,10 @@
"@getalby/bitcoin-connect": "^3.2.2",
"@scure/base": "^1.1.6",
"@welshman/content": "^0.0.5",
"@welshman/feeds": "^0.0.11",
"@welshman/lib": "^0.0.9",
"@welshman/net": "^0.0.13",
"@welshman/util": "^0.0.14",
"@welshman/feeds": "^0.0.12",
"@welshman/lib": "^0.0.10",
"@welshman/net": "^0.0.14",
"@welshman/util": "^0.0.15",
"bowser": "^2.11.0",
"classnames": "^2.5.1",
"compressorjs": "^1.2.1",

View File

@ -236,3 +236,9 @@ body,
.react-switch-bg {
border: 1px solid var(--neutral-600);
}
/* note content */
.note-content a {
text-decoration: underline;
}

View File

@ -1,4 +1,5 @@
<script lang="ts">
import cx from "classnames"
import {NAMED_BOOKMARKS, toNostrURI, Address} from "@welshman/util"
import {slide} from "src/util/transition"
import {boolCtrl} from "src/partials/utils"
@ -9,8 +10,15 @@
import CopyValueSimple from "src/partials/CopyValueSimple.svelte"
import FeedSummary from "src/app/shared/FeedSummary.svelte"
import PersonBadgeSmall from "src/app/shared/PersonBadgeSmall.svelte"
import {readFeed, readList, displayFeed, mapListToFeed} from "src/domain"
import {repository} from "src/engine"
import {readFeed, readList, displayFeed, mapListToFeed, getSingletonValues} from "src/domain"
import {
hints,
pubkey,
repository,
addFeedFavorite,
removeFeedFavorite,
userFeedFavorites,
} from "src/engine"
import {globalFeed} from "src/app/state"
import {router} from "src/app/util"
@ -19,14 +27,19 @@
const expandDefinition = boolCtrl()
const event = repository.getEvent(address)
const deleted = repository.isDeleted(event)
const naddr = Address.from(address, hints.Event(event).getUrls()).toNaddr()
const feed = address.startsWith(NAMED_BOOKMARKS)
? mapListToFeed(readList(event))
: readFeed(event)
const toggleFavorite = () => (isFavorite ? removeFeedFavorite(address) : addFeedFavorite(address))
const loadFeed = () => {
globalFeed.set(feed)
router.at("notes").push()
}
$: isFavorite = getSingletonValues("a", $userFeedFavorites).has(address)
</script>
<Card class="flex gap-3">
@ -69,7 +82,15 @@
<i class="fa fa-angle-right" />
{/if}
</div>
<CopyValueSimple label="Feed address" value={toNostrURI(Address.from(address).toNaddr())} />
<div
class={cx("p-1 text-neutral-400 transition-colors hover:text-neutral-100", {
"cursor-pointer": feed.event.pubkey !== $pubkey,
"pointer-events-none opacity-25": feed.event.pubkey === $pubkey,
})}
on:click={toggleFavorite}>
<i class="fa fa-bookmark" class:text-accent={isFavorite} />
</div>
<CopyValueSimple label="Feed address" value={toNostrURI(naddr)} />
</div>
</div>
{#if $expandDefinition.enabled}

View File

@ -1,6 +1,8 @@
<script lang="ts">
import {debounce} from "throttle-debounce"
import {equals} from "ramda"
import {sortBy, uniqBy} from "@welshman/lib"
import {getAddress} from "@welshman/util"
import {isSearchFeed, makeSearchFeed, makeScopeFeed, Scope, getFeedArgs} from "@welshman/feeds"
import {toSpliced} from "src/util/misc"
import {boolCtrl} from "src/partials/utils"
@ -13,8 +15,8 @@
import FeedForm from "src/app/shared/FeedForm.svelte"
import {router} from "src/app/util"
import {globalFeed} from "src/app/state"
import {normalizeFeedDefinition, displayList, readFeed, makeFeed, displayFeed} from "src/domain"
import {userListFeeds, canSign, deleteEvent, userFeeds} from "src/engine"
import {normalizeFeedDefinition, readFeed, makeFeed, displayFeed} from "src/domain"
import {userListFeeds, canSign, deleteEvent, userFeeds, userFavoritedFeeds} from "src/engine"
export let feed
export let updateFeed
@ -25,6 +27,10 @@
const listMenu = boolCtrl()
const followsFeed = makeFeed({definition: normalizeFeedDefinition(makeScopeFeed(Scope.Follows))})
const networkFeed = makeFeed({definition: normalizeFeedDefinition(makeScopeFeed(Scope.Network))})
const allFeeds = uniqBy(
feed => getAddress(feed.event),
sortBy(displayFeed, [...$userFeeds, ...$userListFeeds, ...$userFavoritedFeeds]),
)
const openForm = () => {
savePoint = {...feed}
@ -130,20 +136,13 @@
on:click={() => setFeed(networkFeed)}>
Network
</MenuItem>
{#each $userFeeds as feed}
{#each allFeeds as feed}
<MenuItem
active={equals(feed.definition, $globalFeed.definition)}
on:click={() => setFeed(feed)}>
{displayFeed(feed)}
</MenuItem>
{/each}
{#each $userListFeeds as feed}
<MenuItem
active={equals(feed.definition, $globalFeed.definition)}
on:click={() => setFeed(feed)}>
{displayList(feed.list)}
</MenuItem>
{/each}
</div>
{#if $canSign}
<div class="bg-neutral-900">

View File

@ -11,15 +11,18 @@
isRelayFeed,
isListFeed,
isDVMFeed,
isGlobalFeed,
makeListFeed,
makeDVMFeed,
makeScopeFeed,
makeTagFeed,
makeRelayFeed,
makeGlobalFeed,
Scope,
} from "@welshman/feeds"
import {toSpliced} from "src/util/misc"
import Icon from "src/partials/Icon.svelte"
import SelectButton from "src/partials/SelectButton.svelte"
import SelectTiles from "src/partials/SelectTiles.svelte"
import Card from "src/partials/Card.svelte"
import FlexColumn from "src/partials/FlexColumn.svelte"
@ -29,6 +32,7 @@
export let feed
enum FormType {
Global = "global",
Advanced = "advanced",
DVMs = "dvms",
Lists = "lists",
@ -60,25 +64,12 @@
const inferFormType = feed => {
for (const subFeed of getFeedArgs(normalize(feed))) {
if ([FeedType.Scope, FeedType.Author].includes(subFeed[0])) {
return FormType.People
}
if (subFeed[0] === FeedType.Tag && subFeed[1] === "#t") {
return FormType.Topics
}
if (subFeed[0] === FeedType.Relay) {
return FormType.Relays
}
if (subFeed[0] === FeedType.List) {
return FormType.Lists
}
if (subFeed[0] === FeedType.DVM) {
return FormType.DVMs
}
if (isGlobalFeed(subFeed)) return FormType.Global
if (isScopeFeed(subFeed) || isAuthorFeed(subFeed)) return FormType.People
if (isTagFeed(subFeed) && subFeed[1] === "#t") return FormType.Topics
if (isRelayFeed(subFeed)) return FormType.Relays
if (isListFeed(subFeed)) return FormType.Lists
if (isDVMFeed(subFeed)) return FormType.DVMs
}
return FormType.Advanced
@ -96,7 +87,9 @@
// Remove filters directly related to the previous type
if (newFormType !== FormType.Advanced) {
if (formType === FormType.People) {
if (formType === FormType.Global) {
removeSubFeed(isGlobalFeed)
} else if (formType === FormType.People) {
removeSubFeed(isPeopleFeed)
} else if (formType === FormType.Topics) {
removeSubFeed(isTopicsFeed)
@ -112,7 +105,9 @@
formType = newFormType
// Add a default filter depending on the new form type
if (formType === FormType.People) {
if (formType === FormType.Global) {
prependDefaultSubFeed(isGlobalFeed, makeGlobalFeed())
} else if (formType === FormType.People) {
prependDefaultSubFeed(isPeopleFeed, makeScopeFeed(Scope.Follows))
} else if (formType === FormType.Topics) {
prependDefaultSubFeed(isTopicsFeed, makeTagFeed("#t"))
@ -132,25 +127,55 @@
let formType = inferFormType(feed)
$: formTypeOptions = [
FormType.Global,
FormType.People,
FormType.Topics,
FormType.Relays,
FormType.Lists,
FormType.DVMs,
FormType.Advanced,
]
</script>
<FlexColumn>
<Card class="-mb-8">
<Card>
<FlexColumn small>
<span class="staatliches text-lg">Choose a feed type</span>
<SelectButton
class="sm:hidden"
options={formTypeOptions}
onChange={onFormTypeChange}
value={formType}>
<div slot="item" class="flex items-center gap-2" let:option let:active>
{#if option === FormType.Global}
<i class="fa fa-earth-europe" /> Global
{:else if option === FormType.People}
<i class="fa fa-person" /> People
{:else if option === FormType.Topics}
<i class="fa fa-tags" /> Topics
{:else if option === FormType.Relays}
<i class="fa fa-server" /> Relays
{:else if option === FormType.Lists}
<i class="fa fa-bars-staggered" /> Lists
{:else if option === FormType.DVMs}
<i class="fa fa-circle-nodes" /> DVMs
{:else if option === FormType.Advanced}
<i class="fa fa-cogs" /> Advanced
{/if}
</div>
</SelectButton>
<SelectTiles
class="grid-cols-2 xs:grid-cols-3 md:grid-cols-5"
class="hidden grid-cols-4 sm:grid"
options={formTypeOptions}
onChange={onFormTypeChange}
value={formType}>
<div slot="item" class="flex flex-col items-center" let:option let:active>
{#if option === FormType.People}
{#if option === FormType.Global}
<span class="flex h-12 w-12 items-center justify-center" class:text-accent={active}>
<i class="fa fa-2xl fa-earth-europe" />
</span>
<span class="staatliches text-2xl">Global</span>
{:else if option === FormType.People}
<Icon icon="people-nearby" class="h-12 w-12" color={active ? "accent" : "tinted-800"} />
<span class="staatliches text-2xl">People</span>
{:else if option === FormType.Topics}
@ -169,17 +194,25 @@
{:else if option === FormType.DVMs}
<Icon icon="network" class="h-12 w-12" color={active ? "accent" : "tinted-800"} />
<span class="staatliches text-2xl">DVMs</span>
{:else if option === FormType.Advanced}
<span class="flex h-12 w-12 items-center justify-center" class:text-accent={active}>
<i class="fa fa-2xl fa-cogs" />
</span>
<span class="staatliches text-2xl">Advanced</span>
{/if}
</div>
</SelectTiles>
<div
class="flex cursor-pointer items-center justify-end gap-2 text-neutral-500"
on:click={() => onFormTypeChange(FormType.Advanced)}>
<span class="staatliches underline">Advanced Mode</span>
</div>
</FlexColumn>
</Card>
<FlexColumn>
{#if formType === FormType.Global && feed.length === 2}
<Card class="flex gap-4 items-center">
<i class="fa fa-triangle-exclamation text-warning fa-xl" />
<p>
Be aware that feeds with no filters can result in obscene or otherwise objectionable content being displayed.
</p>
</Card>
{/if}
{#if formType === FormType.Advanced}
<FeedFormAdvanced {feed} onChange={onFeedChange} />
{:else}

View File

@ -11,7 +11,15 @@
import Anchor from "src/partials/Anchor.svelte"
import FeedField from "src/app/shared/FeedField.svelte"
import {makeFeed, createFeed, editFeed, isMentionFeed, displayFeed} from "src/domain"
import {canSign, deleteEvent, createAndPublish, loadPubkeys, hints} from "src/engine"
import {
pubkey,
displayProfileByPubkey,
canSign,
deleteEvent,
createAndPublish,
loadPubkeys,
hints,
} from "src/engine"
export let feed
export let exit
@ -98,9 +106,18 @@
<Anchor underline on:click={openSave} class="text-neutral-400">Save this feed</Anchor>
</Card>
{:else if draft.event || draft.list}
{@const event = draft.event || draft.list.event}
<Card class="flex flex-col justify-between sm:flex-row">
<p>You are currently editing your {displayFeed(draft)} feed.</p>
<Anchor underline on:click={startClone} class="text-neutral-400">
{#if event.pubkey === $pubkey}
<p>You are currently editing "{displayFeed(draft)}" feed.</p>
{:else}
<p>
You are currently cloning "{displayFeed(draft)}" by @{displayProfileByPubkey(
event.pubkey,
)}.
</p>
{/if}
<Anchor underline on:click={startClone} class="whitespace-nowrap text-neutral-400">
Create a new feed instead
</Anchor>
</Card>
@ -108,7 +125,7 @@
<Card class="flex flex-col justify-between sm:flex-row">
<p>You are currently creating a new feed.</p>
<Anchor underline on:click={stopClone} class="text-neutral-400">
Edit your {displayFeed(feed)} feed instead
Edit "{displayFeed(feed)}" instead
</Anchor>
</Card>
{/if}

View File

@ -1,8 +1,8 @@
<script lang="ts">
import {tryCatch} from "@welshman/lib"
import Card from "src/partials/Card.svelte"
import Field from "src/partials/Field.svelte"
import Textarea from "src/partials/Textarea.svelte"
import FlexColumn from "src/partials/FlexColumn.svelte"
export let feed
export let onChange
@ -35,18 +35,19 @@
</script>
<Card>
<Field label="Enter your custom feed below">
<FlexColumn>
<span class="staatliches text-lg">Enter your custom feed below</span>
<Textarea
class="h-72 whitespace-pre-wrap"
value={json}
on:input={onInput}
on:focus={onFocus}
on:blur={onBlur} />
</Field>
{#if !isValid && !isFocused}
<p>
<i class="fa fa-triangle-exclamation" />
Your feed is currently invalid. Please double check that it is valid JSON.
</p>
{/if}
{#if !isValid && !isFocused}
<p>
<i class="fa fa-triangle-exclamation" />
Your feed is currently invalid. Please double check that it is valid JSON.
</p>
{/if}
</FlexColumn>
</Card>

View File

@ -2,6 +2,7 @@
import {toTitle} from "hurdak"
import {
getFeedArgs,
isGlobalFeed,
isCreatedAtFeed,
isAuthorFeed,
isKindFeed,
@ -68,41 +69,48 @@
{#each subFeeds as subFeed, i}
{@const idx = i + 1}
{@const change = f => onSubFeedChange(idx, f)}
<Card class="relative">
<FlexColumn>
<FlexColumn small>
{#if isPeopleFeed(subFeed)}
<FeedFormSectionPeople feed={subFeed} onChange={change} />
{:else if isRelayFeed(subFeed)}
<FeedFormSectionRelays feed={subFeed} onChange={change} />
{:else if isTopicFeed(subFeed)}
<FeedFormSectionTopics feed={subFeed} onChange={change} />
{:else if isMentionFeed(subFeed)}
<FeedFormSectionMentions feed={subFeed} onChange={change} />
{:else if isKindFeed(subFeed)}
<FeedFormSectionKinds feed={subFeed} onChange={change} />
{:else if isCreatedAtFeed(subFeed)}
<FeedFormSectionCreatedAt feed={subFeed} onChange={change} />
{:else if isListFeed(subFeed)}
<FeedFormSectionList feed={subFeed} onChange={change} />
{:else if isDVMFeed(subFeed)}
<FeedFormSectionDVM feed={subFeed} onChange={change} />
{:else}
No support for editing {toTitle(subFeed[0])} filters. Click "Advanced" to edit manually.
{@const canSave =
isAuthorFeed(subFeed) ||
isRelayFeed(subFeed) ||
isTopicFeed(subFeed) ||
isMentionFeed(subFeed)}
{#if canSave || !isGlobalFeed(subFeed)}
<Card class="relative">
<FlexColumn>
<FlexColumn small>
{#if isPeopleFeed(subFeed)}
<FeedFormSectionPeople feed={subFeed} onChange={change} />
{:else if isRelayFeed(subFeed)}
<FeedFormSectionRelays feed={subFeed} onChange={change} />
{:else if isTopicFeed(subFeed)}
<FeedFormSectionTopics feed={subFeed} onChange={change} />
{:else if isMentionFeed(subFeed)}
<FeedFormSectionMentions feed={subFeed} onChange={change} />
{:else if isKindFeed(subFeed)}
<FeedFormSectionKinds feed={subFeed} onChange={change} />
{:else if isCreatedAtFeed(subFeed)}
<FeedFormSectionCreatedAt feed={subFeed} onChange={change} />
{:else if isListFeed(subFeed)}
<FeedFormSectionList feed={subFeed} onChange={change} />
{:else if isDVMFeed(subFeed)}
<FeedFormSectionDVM feed={subFeed} onChange={change} />
{:else}
No support for editing {toTitle(subFeed[0])} filters. Click "Advanced" to edit manually.
{/if}
</FlexColumn>
{#if canSave}
<FeedFormSaveAsList feed={subFeed} onChange={change} />
{/if}
</FlexColumn>
{#if isAuthorFeed(subFeed) || isRelayFeed(subFeed) || isTopicFeed(subFeed) || isMentionFeed(subFeed)}
<FeedFormSaveAsList feed={subFeed} onChange={change} />
{#if i > 0}
<div
class="absolute right-2 top-2 h-4 w-4 cursor-pointer"
on:click={() => onSubFeedRemove(idx)}>
<i class="fa fa-times" />
</div>
{/if}
</FlexColumn>
{#if i > 0}
<div
class="absolute right-2 top-2 h-4 w-4 cursor-pointer"
on:click={() => onSubFeedRemove(idx)}>
<i class="fa fa-times" />
</div>
{/if}
</Card>
</Card>
{/if}
{/each}
{/key}

View File

@ -21,7 +21,7 @@
$: addresses = feed.slice(1).flatMap(it => it.addresses)
</script>
<span>Which lists would you like to use?</span>
<span class="staatliches text-lg">Which lists would you like to use?</span>
<SearchSelect
multiple
value={addresses}

View File

@ -23,7 +23,7 @@
$: scopes = isScopeFeed(feed) ? feed.slice(1) : ["custom"]
</script>
<span>Which authors would you like to see?</span>
<span class="staatliches text-lg">Which authors would you like to see?</span>
<SelectButton
multiple
value={scopes}

View File

@ -1,15 +1,15 @@
<script lang="ts">
import NoteContentKind1 from "src/app/shared/NoteContentKind1.svelte"
import {groups} from "src/engine"
import {deriveGroupMeta} from "src/engine"
export let address
export let truncate = true
const group = groups.key(address)
const meta = deriveGroupMeta(address)
</script>
<NoteContentKind1
note={{content: $group?.meta?.about || ""}}
note={{content: $meta?.about || ""}}
minLength={100}
maxLength={140}
showEntire={!truncate} />

View File

@ -1,15 +1,15 @@
<script lang="ts">
import ImageCircle from "src/partials/ImageCircle.svelte"
import PlaceholderCircle from "src/app/shared/PlaceholderCircle.svelte"
import {groups} from "src/engine"
import {deriveGroupMeta} from "src/engine"
export let address
const group = groups.key(address)
const meta = deriveGroupMeta(address)
</script>
{#if $group?.meta?.picture}
<ImageCircle src={$group.meta.picture} class={$$props.class} />
{#if $meta?.image}
<ImageCircle src={$meta.image} class={$$props.class} />
{:else}
<PlaceholderCircle pubkey={address} class={$$props.class} />
{/if}

View File

@ -1,24 +1,7 @@
<script context="module" lang="ts">
export type Values = {
id?: string
type: string
feeds: string[][]
relays: string[]
members?: string[]
list_publicly: boolean
meta: {
name: string
about: string
picture: string
banner: string
}
}
</script>
<script lang="ts">
import {join, uniqBy} from "ramda"
import {ucFirst} from "hurdak"
import {Address} from "@welshman/util"
import {Address, GROUP, COMMUNITY} from "@welshman/util"
import {toSpliced} from "src/util/misc"
import {fly} from "src/util/transition"
import {formCtrl} from "src/partials/utils"
@ -35,11 +18,12 @@
import FlexColumn from "src/partials/FlexColumn.svelte"
import Heading from "src/partials/Heading.svelte"
import PersonSelect from "src/app/shared/PersonSelect.svelte"
import type {GroupMeta} from "src/domain"
import {normalizeRelayUrl} from "src/domain"
import {env, hints, relaySearch, feedSearch} from "src/engine"
export let onSubmit
export let values: Values
export let values: GroupMeta & {members: string[]}
export let mode = "create"
export let showMembers = false
export let buttonText = "Save"
@ -83,7 +67,7 @@
<div class="mb-4 flex flex-col items-center justify-center">
<Heading>{ucFirst(mode)} Group</Heading>
<p>
{#if values.type === "open"}
{#if values.kind === COMMUNITY}
An open forum where anyone can participate.
{:else}
A private place where members can talk.
@ -92,30 +76,30 @@
</div>
<div class="flex w-full flex-col gap-8">
<Field label="Name">
<Input bind:value={values.meta.name}>
<Input bind:value={values.name}>
<i slot="before" class="fa fa-clipboard" />
</Input>
<div slot="info">The name of the group</div>
</Field>
<Field label="Picture">
<ImageInput
bind:value={values.meta.picture}
bind:value={values.image}
icon="image-portrait"
maxWidth={480}
maxHeight={480} />
<div slot="info">A picture for the group</div>
</Field>
<Field label="Banner">
<ImageInput bind:value={values.meta.banner} icon="image" maxWidth={4000} maxHeight={4000} />
<ImageInput bind:value={values.banner} icon="image" maxWidth={4000} maxHeight={4000} />
<div slot="info">A banner image for the group</div>
</Field>
<Field label="About">
<Textarea bind:value={values.meta.about} />
<Textarea bind:value={values.about} />
<div slot="info">The group's decription</div>
</Field>
{#if values.type === "closed"}
{#if values.kind === GROUP}
<FieldInline label="List Publicly">
<Toggle bind:value={values.list_publicly} />
<Toggle bind:value={values.listing_is_public} />
<div slot="info">
If enabled, this will generate a public listing for the group. The member list and group
messages will not be published.

View File

@ -1,11 +1,12 @@
<script lang="ts">
import Anchor from "src/partials/Anchor.svelte"
import {router} from "src/app/util/router"
import {deriveGroup, displayGroup, loadGroups} from "src/engine"
import {displayGroupMeta} from "src/domain"
import {deriveGroupMeta, loadGroups} from "src/engine"
export let address
const group = deriveGroup(address)
const meta = deriveGroupMeta(address)
const path = router.at("groups").of(address).at("notes").toString()
loadGroups([address])
@ -13,6 +14,6 @@
<span class={$$props.class}>
<Anchor modal underline href={path}>
{displayGroup($group)}
{displayGroupMeta($meta)}
</Anchor>
</span>

View File

@ -2,17 +2,19 @@
import {ellipsize} from "hurdak"
import {derived} from "svelte/store"
import {remove, intersection} from "@welshman/lib"
import {isGroupAddress, isCommunityAddress} from "@welshman/util"
import Chip from "src/partials/Chip.svelte"
import Card from "src/partials/Card.svelte"
import GroupCircle from "src/app/shared/GroupCircle.svelte"
import PersonCircles from "src/app/shared/PersonCircles.svelte"
import {router} from "src/app/util/router"
import {displayGroup, deriveGroup, userFollows, communityListsByAddress, pubkey} from "src/engine"
import {displayGroupMeta} from "src/domain"
import {deriveGroupMeta, userFollows, communityListsByAddress, pubkey} from "src/engine"
export let address
export let modal = false
const group = deriveGroup(address)
const meta = deriveGroupMeta(address)
const members = derived(communityListsByAddress, $m => {
const allMembers = $m.get(address)?.map(l => l.event.pubkey) || []
const otherMembers = remove($pubkey, allMembers)
@ -37,20 +39,20 @@
<div class="flex min-w-0 flex-grow flex-col justify-start gap-1">
<div class="flex justify-between gap-2">
<h2 class="text-xl font-bold">
{displayGroup($group)}
{displayGroupMeta($meta)}
</h2>
<slot name="actions">
{#if address.startsWith("34550:")}
{#if isCommunityAddress(address)}
<Chip class="text-sm text-neutral-200"><i class="fa fa-unlock" /> Open</Chip>
{/if}
{#if address.startsWith("35834:")}
{#if isGroupAddress(address)}
<Chip class="text-sm text-neutral-200"><i class="fa fa-lock" /> Closed</Chip>
{/if}
</slot>
</div>
{#if $group.meta?.about}
{#if $meta?.about}
<p class="text-start text-neutral-100">
{ellipsize($group.meta.about, 300)}
{ellipsize($meta.about, 300)}
</p>
{/if}
{#if $members.length > 0}

View File

@ -1,9 +1,10 @@
<script lang="ts">
import {groups, displayGroup} from "src/engine"
import {displayGroupMeta} from "src/domain"
import {deriveGroupMeta} from "src/engine"
export let address
const group = groups.key(address)
const meta = deriveGroupMeta(address)
</script>
<span class={$$props.class}>{displayGroup($group)}</span>
<span class={$$props.class}>{displayGroupMeta($meta)}</span>

View File

@ -9,12 +9,11 @@
import Feed from "src/app/shared/Feed.svelte"
import NoteCreateInline from "src/app/shared/NoteCreateInline.svelte"
import {makeFeed, readFeed} from "src/domain"
import {hints, repository, canSign, deriveGroup, load} from "src/engine"
import {hints, repository, canSign, deriveGroupMeta, load} from "src/engine"
export let address
const group = deriveGroup(address)
const meta = deriveGroupMeta(address)
const mainFeed = feedFromFilter({kinds: remove(30402, noteKinds), "#a": [address]})
const setActiveTab = tab => {
@ -27,7 +26,7 @@
let feeds = [{name: "feed", feed: makeFeed({definition: mainFeed})}]
let feed = makeFeed({definition: mainFeed})
for (const feed of $group.feeds || []) {
for (const feed of $meta?.feeds || []) {
const [address, relay = "", name = ""] = feed.slice(1)
if (!Address.isAddress(address)) {

View File

@ -1,14 +1,15 @@
<script lang="ts">
import {isCommunityAddress} from "@welshman/util"
import Chip from "src/partials/Chip.svelte"
import GroupCircle from "src/app/shared/GroupCircle.svelte"
import GroupAbout from "src/app/shared/GroupAbout.svelte"
import GroupName from "src/app/shared/GroupName.svelte"
import {groups} from "src/engine"
import {deriveGroupMeta} from "src/engine"
export let address
export let hideAbout = false
const group = groups.key(address)
const meta = deriveGroupMeta(address)
</script>
<div class="flex gap-4 text-neutral-100">
@ -18,7 +19,7 @@
<div class="flex items-center">
<GroupName class="text-2xl" {address} />
<Chip class="scale-75 border-neutral-200 text-neutral-200">
{#if address.startsWith("34550:")}
{#if isCommunityAddress(address)}
<i class="fa fa-unlock" />
Open
{:else}
@ -29,7 +30,7 @@
</div>
<slot name="actions" class="hidden xs:block" />
</div>
{#if !hideAbout && $group?.meta?.about}
{#if !hideAbout && $meta?.about}
<GroupAbout {address} />
{/if}
</div>

View File

@ -1,5 +1,4 @@
<script lang="ts">
import {without} from "ramda"
import {
parse,
truncate,
@ -16,7 +15,6 @@
isAddress,
isNewline,
} from "@welshman/content"
import MediaSet from "src/partials/MediaSet.svelte"
import QRCode from "src/partials/QRCode.svelte"
import NoteContentNewline from "src/app/shared/NoteContentNewline.svelte"
import NoteContentEllipsis from "src/app/shared/NoteContentEllipsis.svelte"
@ -44,16 +42,15 @@
const isBoundary = i => {
const parsed = shortContent[i]
if (!parsed || isBoundary(parsed)) return true
if (!parsed || isNewline(parsed)) return true
if (isText(parsed)) return parsed.value.match(/^\s+$/)
return false
}
const isStartOrEnd = i => Boolean(isBoundary(i - 1) || isBoundary(i + 1))
const isStartAndEnd = i => Boolean(isBoundary(i - 1) && isBoundary(i + 1))
const getLinks = content =>
content.filter(x => isLink(x) && x.value.isMedia).map(x => x.value.url.toString())
const isStartOrEnd = i => Boolean(isBoundary(i - 1) || isBoundary(i + 1))
$: shortContent = showEntire
? fullContent
@ -66,13 +63,11 @@
},
)
$: links = getLinks(shortContent)
$: extraLinks = without(links, getLinks(fullContent))
$: ellipsize = expandable && shortContent.find(isEllipsis)
</script>
<div
class="flex flex-col gap-2 overflow-hidden text-ellipsis"
class="note-content flex flex-col gap-2 overflow-hidden text-ellipsis"
style={ellipsize && "mask-image: linear-gradient(0deg, transparent 0px, black 100px)"}>
<div>
{#each shortContent as parsed, i}
@ -91,7 +86,7 @@
<QRCode copyOnClick code={parsed.value} />
</div>
{:else if isLink(parsed)}
<NoteContentLink value={parsed.value} showMedia={showMedia && isStartOrEnd(i)} />
<NoteContentLink value={parsed.value} showMedia={showMedia && isStartAndEnd(i)} />
{:else if isProfile(parsed)}
<PersonLink pubkey={parsed.value.pubkey} />
{:else if (isEvent(parsed) || isAddress(parsed)) && isStartOrEnd(i) && depth < 2}
@ -100,16 +95,11 @@
<slot name="note-content" {quote} />
</div>
</NoteContentQuote>
{:else if !expandable && isEllipsis(parsed)}
{@html renderParsed(parsed)}
{:else}
{@html renderParsed(parsed)}
{/if}
{/each}
</div>
{#if showMedia && extraLinks.length > 0}
<MediaSet links={extraLinks} />
{/if}
</div>
{#if ellipsize}

View File

@ -10,6 +10,8 @@
const url = value.url.toString()
const coracleRegexp = /^(https?:\/\/)?(app\.)?coracle.social/
const close = () => {
hidden = true
}
@ -17,18 +19,16 @@
let hidden = false
</script>
{#if url.includes('coracle.social/')}
{#if url.match(coracleRegexp)}
<Anchor
modal
stopPropagation
class="overflow-hidden text-ellipsis whitespace-nowrap underline"
href={url.replace(/(https?:\/\/)?(app\.)?coracle.social/, '')}>
href={url.replace(coracleRegexp, '')}>
{displayUrl(url)}
</Anchor>
{:else if showMedia && value.isMedia && !hidden}
<div class="py-2">
<Media url={url} onClose={close} />
</div>
{:else if showMedia && !hidden}
<Media url={url} onClose={close} />
{:else if isShareableRelayUrl(url)}
<Anchor
modal

View File

@ -1,11 +1,12 @@
<script lang="ts">
import {derived} from "svelte/store"
import {uniq} from "@welshman/lib"
import {parseAnything} from "src/util/nostr"
import Anchor from "src/partials/Anchor.svelte"
import SearchSelect from "src/partials/SearchSelect.svelte"
import PersonBadge from "src/app/shared/PersonBadge.svelte"
import {router} from "src/app/util/router"
import {profileSearch, createPeopleLoader} from "src/engine"
import {profileSearch, loadPubkeyProfiles, createPeopleLoader} from "src/engine"
export let value
export let multiple = false
@ -16,27 +17,33 @@
const {loading, load} = createPeopleLoader()
const search = term => {
load(term)
const search = derived(profileSearch, $profileSearch => {
return term => {
load(term)
parseAnything(term).then(result => {
if (result?.type === "npub") {
value = uniq(value.concat(result.data))
input.clearTerm()
}
parseAnything(term).then(result => {
if (result?.type === "npub") {
loadPubkeyProfiles([result.data])
value = uniq(value.concat(result.data))
input.clearTerm()
onChange(value)
}
if (result?.type === "nprofile") {
value = uniq(value.concat(result.data.pubkey))
input.clearTerm()
}
})
if (result?.type === "nprofile") {
loadPubkeyProfiles([result.data.pubkey])
value = uniq(value.concat(result.data.pubkey))
input.clearTerm()
onChange(value)
}
})
return $profileSearch.searchValues(term)
}
return $profileSearch.searchValues(term)
}
})
</script>
<SearchSelect
{search}
search={$search}
{onChange}
{multiple}
{autofocus}

View File

@ -96,7 +96,7 @@
<p class="mt-4 text-lg">The following relays are still pending:</p>
<div class="grid gap-2 sm:grid-cols-2">
{#each pending as url}
<RelayCard hideActions {url} />
<RelayCard hideDescription hideActions {url} />
{/each}
</div>
{/if}
@ -104,7 +104,7 @@
<p class="mt-4 text-lg">The following relays accepted your note:</p>
<div class="grid gap-2 sm:grid-cols-2">
{#each success as url}
<RelayCard hideActions {url} />
<RelayCard hideDescription hideActions {url} />
{/each}
</div>
{/if}

View File

@ -18,6 +18,7 @@
export let claim = null
export let ratings = null
export let showStatus = false
export let hideDescription = false
export let hideRatingsCount = false
export let hideActions = false
export let showControls = false
@ -64,30 +65,32 @@
</slot>
{/if}
</div>
<slot name="description">
{#if $relay.description}
<p>{$relay.description}</p>
{#if !hideDescription}
<slot name="description">
{#if $relay.description}
<p>{$relay.description}</p>
{/if}
</slot>
{#if !isNil($relay.count)}
<span class="flex items-center gap-1 text-sm text-neutral-400">
{#if $relay.contact}
<Anchor external underline href={$relay.contact}>{displayUrl($relay.contact)}</Anchor>
&bull;
{/if}
{#if $relay.supported_nips}
<Popover>
<span slot="trigger" class="cursor-pointer underline">
{$relay.supported_nips.length} NIPs
</span>
<span slot="tooltip">
NIPs supported: {$relay.supported_nips.join(", ")}
</span>
</Popover>
&bull;
{/if}
Seen {quantify($relay.count || 0, "time")}
</span>
{/if}
</slot>
{#if !isNil($relay.count)}
<span class="flex items-center gap-1 text-sm text-neutral-400">
{#if $relay.contact}
<Anchor external underline href={$relay.contact}>{displayUrl($relay.contact)}</Anchor>
&bull;
{/if}
{#if $relay.supported_nips}
<Popover>
<span slot="trigger" class="cursor-pointer underline">
{$relay.supported_nips.length} NIPs
</span>
<span slot="tooltip">
NIPs supported: {$relay.supported_nips.join(", ")}
</span>
</Popover>
&bull;
{/if}
Seen {quantify($relay.count || 0, "time")}
</span>
{/if}
{#if showControls && $canSign}
<div class="-mx-6 my-1 h-px bg-tinted-700" />

View File

@ -1,4 +1,5 @@
<script lang="ts">
import {sortBy, uniqBy} from "@welshman/lib"
import {getAddress} from "@welshman/util"
import {onMount} from "svelte"
import {createScroller} from "src/util/misc"
@ -8,15 +9,18 @@
import Input from "src/partials/Input.svelte"
import FeedCard from "src/app/shared/FeedCard.svelte"
import {router} from "src/app/util/router"
import {displayFeed} from "src/domain"
import {
pubkey,
userFeeds,
feedSearch,
userListFeeds,
loadPubkeyFeeds,
userFavoritedFeeds,
userFollows,
} from "src/engine"
const favoritedFeeds = $userFavoritedFeeds
const createFeed = () => router.at("feeds/create").open()
const editFeed = address => router.at("feeds").of(address).open()
@ -29,6 +33,13 @@
let limit = 20
let element
$: allUserFeeds = [...$userFeeds, ...$userListFeeds]
$: feeds = uniqBy(
feed => getAddress(feed.event),
sortBy(displayFeed, [...allUserFeeds, ...favoritedFeeds]),
)
loadPubkeyFeeds(Array.from($userFollows))
onMount(() => {
@ -48,7 +59,7 @@
<i class="fa fa-plus" /> Feed
</Anchor>
</div>
{#each $userFeeds as feed (getAddress(feed.event))}
{#each feeds as feed (feed.event.id)}
{@const address = getAddress(feed.event)}
<div in:fly={{y: 20}}>
<FeedCard {address}>
@ -60,7 +71,7 @@
</FeedCard>
</div>
{/each}
{#each $userListFeeds as feed (getAddress(feed.list.event))}
{#each $userListFeeds as feed (feed.list.event.id)}
{@const address = getAddress(feed.list.event)}
<div in:fly={{y: 20}}>
<FeedCard {address}>
@ -85,7 +96,7 @@
</Input>
{#each $feedSearch
.searchValues(q)
.filter(address => !address.includes($pubkey))
.filter(address => !feeds.find(feed => getAddress(feed.event) === address))
.slice(0, limit) as address (address)}
<FeedCard {address} />
{/each}

View File

@ -1,9 +1,11 @@
<script lang="ts">
import {nth} from "@welshman/lib"
import {COMMUNITY, GROUP} from "@welshman/util"
import Card from "src/partials/Card.svelte"
import Heading from "src/partials/Heading.svelte"
import FlexColumn from "src/partials/FlexColumn.svelte"
import type {Values} from "src/app/shared/GroupDetailsForm.svelte"
import GroupDetailsForm from "src/app/shared/GroupDetailsForm.svelte"
import type {GroupMeta} from "src/domain"
import {
env,
pubkey,
@ -19,34 +21,38 @@
import {router} from "src/app/util/router"
const initialValues = {
type: null,
kind: null,
name: "",
about: "",
image: "",
banner: "",
feeds: [],
relays: $env.PLATFORM_RELAYS,
relays: $env.PLATFORM_RELAYS.map(url => ["relay", url]),
listing_is_public: false,
members: [$pubkey],
list_publicly: false,
meta: {
name: "",
about: "",
picture: "",
banner: "",
},
moderators: [],
identifier: "",
}
const setType = type => {
initialValues.type = type
const setKind = kind => {
initialValues.kind = kind
}
const onSubmit = async ({type, feeds, relays, members, list_publicly, meta}: Values) => {
const kind = type === "open" ? 34550 : 35834
const {id, address} = initGroup(kind, relays)
const onSubmit = async ({
kind,
members,
listing_is_public,
...meta
}: GroupMeta & {members: string[]}) => {
const {identifier, address} = initGroup(kind, meta.relays.map(nth(1)))
await publishAdminKeyShares(address, [$pubkey])
if (type === "open") {
await publishCommunityMeta(address, id, feeds, relays, meta)
if (kind === COMMUNITY) {
await publishCommunityMeta(address, identifier, meta)
await publishCommunitiesList(deriveUserCommunities().get().concat(address))
} else {
await publishGroupMeta(address, id, feeds, relays, meta, list_publicly)
await publishGroupMeta(address, identifier, meta, listing_is_public)
await publishGroupMembers(address, "set", members)
await publishGroupInvites(address, members)
}
@ -55,12 +61,12 @@
}
</script>
{#if !initialValues.type}
{#if !initialValues.kind}
<div class="mb-4 flex flex-col items-center justify-center">
<Heading>Create Group</Heading>
<p>What type of group would you like to create?</p>
</div>
<Card interactive on:click={() => setType("open")}>
<Card interactive on:click={() => setKind(COMMUNITY)}>
<FlexColumn>
<div class="flex items-center justify-between">
<p class="flex items-center gap-4 text-xl">
@ -75,7 +81,7 @@
</p>
</FlexColumn>
</Card>
<Card interactive on:click={() => setType("closed")}>
<Card interactive on:click={() => setKind(GROUP)}>
<FlexColumn>
<div class="flex items-center justify-between">
<p class="flex items-center gap-4 text-xl">
@ -94,11 +100,11 @@
<div class="relative">
<i
class="fa fa-2x fa-arrow-left absolute top-12 cursor-pointer"
on:click={() => setType(null)} />
on:click={() => setKind(null)} />
<GroupDetailsForm
{onSubmit}
values={initialValues}
showMembers={initialValues.type === "closed"}
buttonText={`Create ${initialValues.type} group`} />
showMembers={initialValues.kind === GROUP}
buttonText={initialValues.kind === GROUP ? "Create closed group" : "Create open group"} />
</div>
{/if}

View File

@ -2,12 +2,13 @@
import {showInfo} from "src/partials/Toast.svelte"
import Anchor from "src/partials/Anchor.svelte"
import Subheading from "src/partials/Subheading.svelte"
import {groups, createAndPublish, hints, deriveAdminKeyForGroup, displayGroup} from "src/engine"
import {displayGroupMeta} from "src/domain"
import {deriveGroupMeta, createAndPublish, hints, deriveAdminKeyForGroup} from "src/engine"
import {router} from "src/app/util/router"
export let address
const group = groups.key(address)
const meta = deriveGroupMeta(address)
const adminKey = deriveAdminKeyForGroup(address)
const abort = () => router.pop()
@ -31,7 +32,7 @@
</script>
<Subheading>Delete Group</Subheading>
<p>Are you sure you want to delete {displayGroup($group)}?</p>
<p>Are you sure you want to delete {displayGroupMeta($meta)}?</p>
<p>
This will only hide this group from supporting clients. Messages sent to the group may not be
deleted from relays.

View File

@ -13,13 +13,14 @@
import GroupMembers from "src/app/shared/GroupMembers.svelte"
import GroupAdmin from "src/app/shared/GroupAdmin.svelte"
import GroupRestrictAccess from "src/app/shared/GroupRestrictAccess.svelte"
import {displayGroupMeta} from "src/domain"
import {
env,
GroupAccess,
displayGroup,
loadPubkeys,
groupRequests,
deriveGroup,
deriveGroupMeta,
deriveAdminKeyForGroup,
deriveSharedKeyForGroup,
deriveIsGroupMember,
@ -35,6 +36,7 @@
export let claim = ""
const group = deriveGroup(address)
const meta = deriveGroupMeta(address)
const status = deriveGroupStatus(address)
const isGroupMember = deriveIsGroupMember(address)
const sharedKey = deriveSharedKeyForGroup(address)
@ -86,21 +88,21 @@
$: ({rgb, rgba} = $themeBackgroundGradient)
document.title = $group?.meta?.name || "Group Detail"
document.title = $meta?.name || "Group Detail"
</script>
<div
class="absolute left-0 top-0 h-64 w-full"
style={`z-index: -1;
background-size: cover;
background-image: linear-gradient(to bottom, ${rgba}, ${rgb}), url('${$group?.meta?.banner}')`} />
background-image: linear-gradient(to bottom, ${rgba}, ${rgb}), url('${$meta?.banner}')`} />
<div class="flex gap-4 text-neutral-100">
<GroupCircle {address} class="mt-1 h-10 w-10 sm:h-32 sm:w-32" />
<div class="flex min-w-0 flex-grow flex-col gap-4">
<div class="flex items-center justify-between gap-4">
<Anchor on:click={() => setActiveTab("notes")} class="text-2xl"
>{displayGroup($group)}</Anchor>
>{displayGroupMeta($meta)}</Anchor>
<GroupActions {address} {claim} />
</div>
<GroupAbout {address} />

View File

@ -1,46 +1,39 @@
<script lang="ts">
import {prop} from "ramda"
import {COMMUNITY} from "@welshman/util"
import {showInfo} from "src/partials/Toast.svelte"
import type {Values} from "src/app/shared/GroupDetailsForm.svelte"
import GroupDetailsForm from "src/app/shared/GroupDetailsForm.svelte"
import type {GroupMeta} from "src/domain"
import {
deriveGroup,
deleteGroupMeta,
publishGroupMeta,
publishCommunityMeta,
getGroupId,
getGroupName,
deriveGroup,
deriveGroupMeta,
} from "src/engine"
import {router} from "src/app/util/router"
export let address
const group = deriveGroup(address)
const meta = deriveGroupMeta(address)
const initialValues = {...$meta, members: $group?.members || []}
const initialValues = {
id: getGroupId($group),
type: address.startsWith("34550:") ? "open" : "closed",
feeds: $group.feeds || [],
relays: $group.relays || [],
list_publicly: $group.listing_is_public,
meta: {
name: getGroupName($group),
about: $group.meta?.about || "",
picture: $group.meta?.picture || "",
banner: $group.meta?.banner || "",
},
}
const onSubmit = async ({id, type, list_publicly, feeds, relays, meta}: Values) => {
const onSubmit = async ({
kind,
identifier,
listing_is_public,
...meta
}: GroupMeta & {members: string[]}) => {
// If we're switching group listing visibility, delete the old listing
if ($group.listing_is_public && !list_publicly) {
await prop("result", await deleteGroupMeta($group.address))
if (listing_is_public && !initialValues.listing_is_public) {
await prop("result", await deleteGroupMeta(address))
}
if (type === "open") {
await publishCommunityMeta(address, id, feeds, relays, meta)
if (kind === COMMUNITY) {
await publishCommunityMeta(address, identifier, meta)
} else {
await publishGroupMeta(address, id, feeds, relays, meta, list_publicly)
await publishGroupMeta(address, identifier, meta, listing_is_public)
}
showInfo("Your group has been updated!")

View File

@ -1,18 +1,20 @@
<script lang="ts">
import {toNostrURI} from "@welshman/util"
import {nth} from "@welshman/lib"
import {toNostrURI, Address} from "@welshman/util"
import {nsecEncode} from "src/util/nostr"
import Anchor from "src/partials/Anchor.svelte"
import Popover from "src/partials/Popover.svelte"
import FlexColumn from "src/partials/FlexColumn.svelte"
import CopyValue from "src/partials/CopyValue.svelte"
import RelayCard from "src/app/shared/RelayCard.svelte"
import {groups, deriveAdminKeyForGroup, getGroupNaddr} from "src/engine"
import {deriveGroupMeta, deriveAdminKeyForGroup} from "src/engine"
import {router} from "src/app/util/router"
export let address
const group = groups.key(address)
const meta = deriveGroupMeta(address)
const adminKey = deriveAdminKeyForGroup(address)
const naddr = Address.from(address, $meta?.relays.map(nth(1)) || []).toNaddr()
const shareAdminKey = () => {
popover?.hide()
@ -24,7 +26,7 @@
<h1 class="staatliches text-2xl">Details</h1>
<CopyValue label="Group ID" value={address} />
<CopyValue label="Link" value={toNostrURI(getGroupNaddr($group))} />
<CopyValue label="Link" value={toNostrURI(naddr)} />
{#if $adminKey}
<CopyValue isPassword label="Admin key" value={$adminKey.privkey} encode={nsecEncode}>
<div slot="label" class="flex gap-2">
@ -46,12 +48,12 @@
</div>
</CopyValue>
{/if}
{#if $group.relays?.length > 0}
{#if $meta?.relays.length > 0}
<h1 class="staatliches text-2xl">Relays</h1>
<p>This group uses the following relays:</p>
<div class="flex flex-col gap-2">
{#each $group.relays as url}
<RelayCard {url} />
{#each $meta.relays as tag}
<RelayCard url={tag[1]} />
{/each}
</div>
{/if}

View File

@ -1,8 +1,9 @@
<script>
import {onMount} from "svelte"
import {filter, assoc} from "ramda"
import {filter, reject, assoc} from "ramda"
import {derived} from "svelte/store"
import {now, shuffle} from "@welshman/lib"
import {GROUP, COMMUNITY, getIdFilters} from "@welshman/util"
import {GROUP, COMMUNITY, getAddress, getIdFilters} from "@welshman/util"
import {createScroller} from "src/util/misc"
import Anchor from "src/partials/Anchor.svelte"
import FlexColumn from "src/partials/FlexColumn.svelte"
@ -12,40 +13,37 @@
load,
hints,
groups,
repository,
loadGiftWraps,
loadGroupMessages,
deriveIsGroupMember,
updateCurrentSession,
communityListsByAddress,
searchGroups,
searchGroupMeta,
groupMeta,
} from "src/engine"
const loadMore = async () => {
limit += 20
}
const userIsMember = g => deriveIsGroupMember(g.address, true).get()
const userIsMember = meta => deriveIsGroupMember(getAddress(meta.event), true).get()
const userGroups = groups.derived(
filter(g => !repository.deletes.has(g.address) && userIsMember(g)),
)
const userGroupMeta = derived(groupMeta, filter(userIsMember))
let q = ""
let limit = 20
let element = null
$: otherGroups = $searchGroups(q)
.filter(g => !userIsMember(g))
.slice(0, limit)
$: otherGroupMeta = reject(userIsMember, $searchGroupMeta(q)).slice(0, limit)
document.title = "Groups"
onMount(() => {
const loader = loadGiftWraps()
const scroller = createScroller(loadMore, {element})
const communityAddrs = Array.from($communityListsByAddress.keys())
.filter(a => !groups.key(a).get()?.meta)
const communityAddrs = Array.from($communityListsByAddress.keys()).filter(
a => !groups.key(a).get()?.meta,
)
updateCurrentSession(assoc("groups_last_synced", now()))
@ -81,8 +79,8 @@
<i class="fa-solid fa-plus" /> Create
</Anchor>
</div>
{#each $userGroups as group (group.address)}
<GroupListItem address={group.address} />
{#each $userGroupMeta as meta (meta.event.id)}
<GroupListItem address={getAddress(meta.event)} />
{:else}
<p class="text-center py-8">You haven't yet joined any groups.</p>
{/each}
@ -90,7 +88,7 @@
<Input bind:value={q} type="text" class="flex-grow" placeholder="Search groups">
<i slot="before" class="fa-solid fa-search" />
</Input>
{#each otherGroups as group (group.address)}
<GroupListItem address={group.address} />
{#each otherGroupMeta as meta (meta.event.id)}
<GroupListItem address={getAddress(meta.event)} />
{/each}
</FlexColumn>

View File

@ -1,5 +1,5 @@
<script lang="ts">
import {without} from "ramda"
import {without} from "@welshman/lib"
import {difference} from "hurdak"
import {showInfo} from "src/partials/Toast.svelte"
import Field from "src/partials/Field.svelte"
@ -11,9 +11,11 @@
import PersonSelect from "src/app/shared/PersonSelect.svelte"
import type {GroupRequest} from "src/engine"
import {
hints,
groups,
groupRequests,
initSharedKey,
deriveGroupMeta,
deriveSharedKeyForGroup,
publishGroupInvites,
publishGroupEvictions,
@ -27,6 +29,7 @@
export let removeMembers = []
const group = groups.key(address)
const meta = deriveGroupMeta(address)
const sharedKey = deriveSharedKeyForGroup(address)
const initialMembers = new Set(
without(removeMembers, [...($group?.members || []), ...addMembers]),
@ -34,7 +37,7 @@
const onSubmit = () => {
if (!soft || !$sharedKey) {
initSharedKey(address)
initSharedKey(address, hints.WithinContext(address).getUrls())
}
const allMembers = new Set(members)
@ -81,8 +84,8 @@
}
// Re-publish group info
if (!soft && !$group.listing_is_public) {
publishGroupMeta(address, $group.id, $group.feeds, $group.relays, $group.meta, false)
if (!soft && !$meta.listing_is_public) {
publishGroupMeta(address, $meta.identifier, $meta, false)
}
// Re-send invites. This could be optimized further, but it's useful to re-send to different relays.

View File

@ -1,6 +1,6 @@
<script lang="ts">
import {zipObj, uniq, pluck} from "ramda"
import {normalizeRelayUrl, Address} from "@welshman/util"
import {zipObj, pluck} from "ramda"
import {normalizeRelayUrl} from "@welshman/util"
import {updateIn} from "src/util/misc"
import Card from "src/partials/Card.svelte"
import Heading from "src/partials/Heading.svelte"
@ -12,7 +12,7 @@
import GroupActions from "src/app/shared/GroupActions.svelte"
import RelayCard from "src/app/shared/RelayCard.svelte"
import Onboarding from "src/app/views/Onboarding.svelte"
import {session, loadGroups, groups as allGroups} from "src/engine"
import {session, loadGroups, groupHints} from "src/engine"
export let people = []
export let relays = []
@ -30,24 +30,9 @@
loadGroups(pluck("address", parsedGroups) as string[], pluck("relay", parsedGroups) as string[])
// Add relay hints to groups so we can use them deep in the call stack
for (const {address, relay} of parsedGroups) {
const group = allGroups.key(address)
if (relay) {
const {identifier, pubkey} = Address.from(address)
group.update($g => {
const {relays = []} = $g
return {
...$g,
address,
id: identifier,
pubkey: pubkey,
relays: uniq([...relays, relay]),
}
})
groupHints.update($gh => ({...$gh, [address]: [...$gh[address], relay]}))
}
}
</script>

View File

@ -1,6 +1,6 @@
<script lang="ts">
import {prop} from "ramda"
import {without, identity} from "@welshman/lib"
import {getAddress} from "@welshman/util"
import {onMount} from "svelte"
import {pickVals, toSpliced} from "src/util/misc"
import Card from "src/partials/Card.svelte"
@ -15,8 +15,8 @@
import GroupCircle from "src/app/shared/GroupCircle.svelte"
import PersonSelect from "src/app/shared/PersonSelect.svelte"
import {router} from "src/app/util/router"
import {displayRelayUrl} from "src/domain"
import {hints, relaySearch, searchGroups, displayGroup, deriveGroup} from "src/engine"
import {displayRelayUrl, displayGroupMeta} from "src/domain"
import {hints, relaySearch, searchGroupMeta, groupMetaByAddress} from "src/engine"
export let initialPubkey = null
export let initialGroupAddress = null
@ -70,7 +70,7 @@
groups = toSpliced(groups, i, 1)
}
const displayGroupFromAddress = a => displayGroup(deriveGroup(a).get())
const displayGroupFromAddress = a => displayGroupMeta($groupMetaByAddress.get(a))
let relayInput, groupInput
let sections = []
@ -194,14 +194,14 @@
<SearchSelect
value={null}
bind:this={groupInput}
search={$searchGroups}
getKey={prop("address")}
onChange={g => g && addGroup(g.address)}
displayItem={g => (g ? displayGroup(g) : "")}>
search={$searchGroupMeta}
displayItem={displayGroupMeta}
getKey={groupMeta => getAddress(groupMeta.event)}
onChange={groupMeta => groupMeta && addGroup(getAddress(groupMeta.event))}>
<i slot="before" class="fa fa-search" />
<div slot="item" let:item class="flex items-center gap-4 text-neutral-100">
<GroupCircle address={item.address} class="h-5 w-5" />
<GroupName address={item.address} />
<GroupCircle address={getAddress(item.event)} class="h-5 w-5" />
<GroupName address={getAddress(item.event)} />
</div>
</SearchSelect>
</FlexColumn>

View File

@ -33,7 +33,7 @@
<div class="flex items-center justify-between">
<div class="flex items-center gap-2">
<i class="fa fa-list fa-lg" />
<h2 class="staatliches text-2xl">Your feeds</h2>
<h2 class="staatliches text-2xl">Your lists</h2>
</div>
<Anchor button accent on:click={createList}>
<i class="fa fa-plus" /> List

View File

@ -5,7 +5,7 @@
import {join, whereEq, identity} from "ramda"
import {throttle, commaFormat, toTitle, switcherFn} from "hurdak"
import {now, writable} from "@welshman/lib"
import {createEvent, Tags} from "@welshman/util"
import {createEvent} from "@welshman/util"
import {currencyOptions} from "src/util/i18n"
import {dateToSeconds} from "src/util/misc"
import {showWarning, showPublishInfo} from "src/partials/Toast.svelte"
@ -44,11 +44,7 @@
export let group = null
export let initialValues = {}
const defaultGroups = $env.FORCE_GROUP
? [$env.FORCE_GROUP]
: quote
? Tags.fromEvent(quote).context().values().valueOf()
: [group].filter(identity)
const defaultGroups = $env.FORCE_GROUP ? [$env.FORCE_GROUP] : [group].filter(identity)
let images, compose
let charCount = 0

41
src/domain/group.ts Normal file
View File

@ -0,0 +1,41 @@
import {fromPairs, nthEq} from '@welshman/lib'
import type {TrustedEvent} from "@welshman/util"
import {isSignedEvent} from "@welshman/util"
export type GroupMeta = {
kind: number
feeds: string[][]
relays: string[][]
moderators: string[][]
identifier: string
name: string
about: string
banner: string
image: string
listing_is_public: boolean
event?: TrustedEvent
}
export type PublishedGroupMeta = Omit<GroupMeta, "event"> & {
event: TrustedEvent
}
export const readGroupMeta = (event: TrustedEvent) => {
const meta = fromPairs(event.tags)
return {
event,
kind: event.kind,
feeds: event.tags.filter(nthEq(0, 'feed')),
relays: event.tags.filter(nthEq(0, 'relay')),
moderators: event.tags.filter(nthEq(0, 'p')),
identifier: meta.d,
name: meta.name,
about: meta.about,
banner: meta.banner,
image: meta.image || meta.picture,
listing_is_public: isSignedEvent(event),
} as PublishedGroupMeta
}
export const displayGroupMeta = (meta: GroupMeta) => meta?.name || meta?.identifier || "[no name]"

View File

@ -1,5 +1,6 @@
export * from "./collection"
export * from "./feed"
export * from "./group"
export * from "./handle"
export * from "./handler"
export * from "./kind"

View File

@ -10,6 +10,7 @@ import {
Address,
isSignedEvent,
normalizeRelayUrl,
FEEDS,
FOLLOWS,
RELAYS,
PROFILE,
@ -51,7 +52,6 @@ import {
loadOne,
createAndPublish,
deriveAdminKeyForGroup,
deriveGroup,
deriveIsGroupMember,
deriveSharedKeyForGroup,
displayProfileByPubkey,
@ -250,7 +250,7 @@ export const updateZapper = async ({pubkey, created_at}, {lud16, lud06}) => {
// Key state management
export const initSharedKey = address => {
export const initSharedKey = (address: string, relays: string[]) => {
const privkey = generatePrivateKey()
const pubkey = getPublicKey(privkey)
const key = {
@ -258,6 +258,7 @@ export const initSharedKey = address => {
pubkey: pubkey,
privkey: privkey,
created_at: now(),
hints: relays,
}
groupSharedKeys.key(pubkey).set(key)
@ -266,24 +267,24 @@ export const initSharedKey = address => {
}
export const initGroup = (kind, relays) => {
const id = randomId()
const identifier = randomId()
const privkey = generatePrivateKey()
const pubkey = getPublicKey(privkey)
const address = `${kind}:${pubkey}:${id}`
const sharedKey = kind === 35834 ? initSharedKey(address) : null
const address = `${kind}:${pubkey}:${identifier}`
const sharedKey = kind === 35834 ? initSharedKey(address, relays) : null
const adminKey = {
group: address,
pubkey: pubkey,
privkey: privkey,
created_at: now(),
relays,
hints: relays,
}
groupAdminKeys.key(pubkey).set(adminKey)
groups.key(address).set({id, pubkey, address, relays})
groups.key(address).set({id: identifier, pubkey, address})
return {id, address, adminKey, sharedKey}
return {identifier, address, adminKey, sharedKey}
}
// Most people don't have access to nip44 yet, send nip04-encrypted fallbacks for:
@ -485,7 +486,7 @@ export const publishKeyShares = async (address, pubkeys, template) => {
}
export const publishAdminKeyShares = async (address, pubkeys) => {
const {relays} = deriveGroup(address).get()
const relays = hints.WithinContext(address).getUrls()
const {privkey} = deriveAdminKeyForGroup(address).get()
const template = createEvent(24, {
tags: [
@ -501,7 +502,7 @@ export const publishAdminKeyShares = async (address, pubkeys) => {
}
export const publishGroupInvites = async (address, pubkeys, gracePeriod = 0) => {
const {relays} = deriveGroup(address).get()
const relays = hints.WithinContext(address).getUrls()
const adminKey = deriveAdminKeyForGroup(address).get()
const {privkey} = deriveSharedKeyForGroup(address).get()
const template = createEvent(24, {
@ -535,40 +536,44 @@ export const publishGroupMembers = async (address, op, pubkeys) => {
return publishAsGroupAdminPrivately(address, template)
}
export const publishCommunityMeta = (address, id, feeds, relays, meta) => {
export const publishCommunityMeta = (address, identifier, meta) => {
const template = createEvent(34550, {
tags: [
["d", id],
["d", identifier],
["name", meta.name],
["description", meta.about],
["banner", meta.banner],
["image", meta.picture],
["picture", meta.image],
["image", meta.image],
...meta.feeds,
...meta.relays,
...meta.moderators,
...getClientTags(),
...(feeds || []),
...(relays || []).map(url => ["relay", url]),
],
})
return publishAsGroupAdminPublicly(address, template, relays)
return publishAsGroupAdminPublicly(address, template, meta.relays)
}
export const publishGroupMeta = (address, id, feeds, relays, meta, listPublicly) => {
export const publishGroupMeta = (address, identifier, meta, listPublicly) => {
const template = createEvent(35834, {
tags: [
["d", id],
["d", identifier],
["name", meta.name],
["about", meta.about],
["banner", meta.banner],
["picture", meta.picture],
["picture", meta.image],
["image", meta.image],
...meta.feeds,
...meta.relays,
...meta.moderators,
...getClientTags(),
...(feeds || []),
...(relays || []).map(url => ["relay", url]),
],
})
return listPublicly
? publishAsGroupAdminPublicly(address, template, relays)
: publishAsGroupAdminPrivately(address, template, relays)
? publishAsGroupAdminPublicly(address, template, meta.relays)
: publishAsGroupAdminPrivately(address, template, meta.relays)
}
export const deleteGroupMeta = address =>
@ -739,6 +744,12 @@ export const unmuteNote = (id: string) => updateSingleton(MUTES, tags => reject(
export const muteNote = (id: string) => updateSingleton(MUTES, tags => append(tags, ["e", id]))
export const removeFeedFavorite = (address: string) =>
updateSingleton(FEEDS, tags => reject(nthEq(1, address), tags))
export const addFeedFavorite = (address: string) =>
updateSingleton(FEEDS, tags => append(tags, ["a", address]))
// Relays
export const requestRelayAccess = async (url: string, claim: string, sk?: string) =>

View File

@ -22,27 +22,12 @@ export enum GroupAccess {
Revoked = "revoked",
}
export type GroupMeta = {
name?: string
about?: string
banner?: string
picture?: string
}
export type Group = {
id: string
pubkey: string
address: string
meta?: GroupMeta
meta_updated_at?: number
feeds?: string[][]
feeds_updated_at?: number
relays?: string[]
relays_updated_at?: number
members?: string[]
recent_member_updates?: TrustedEvent[]
listing_is_public?: boolean
listing_is_public_updated?: boolean
}
export type GroupKey = {

View File

@ -5,8 +5,6 @@ import type {TrustedEvent} from "@welshman/util"
import {
Tags,
isShareableRelayUrl,
Address,
getAddress,
getIdFilters,
MUTES,
FOLLOWS,
@ -43,7 +41,6 @@ import {
modifyGroupStatus,
setGroupStatus,
updateRecord,
updateStore,
updateSession,
setSession,
updateZapper,
@ -109,63 +106,11 @@ projections.addHandler(24, (e: TrustedEvent) => {
groupAlerts.key(e.id).set({...e, group: address, type: "exit"})
}
if (relays.length > 0) {
const {pubkey, identifier} = Address.from(address)
if (!groups.key(address).get()) {
groups.key(address).set({address, pubkey, id: identifier, relays})
}
}
setGroupStatus(recipient, address, e.created_at, {
access: privkey ? GroupAccess.Granted : GroupAccess.Revoked,
})
})
// Group metadata
projections.addHandler(35834, (e: TrustedEvent) => {
const tags = Tags.fromEvent(e)
const meta = tags.asObject()
const address = getAddress(e)
const group = groups.key(address)
group.merge({address, id: meta.d, pubkey: e.pubkey})
updateStore(group, e.created_at, {
feeds: tags.whereKey("feed").unwrap(),
relays: tags.values("relay").valueOf(),
listing_is_public: !e.wrap,
meta: {
name: meta.name,
about: meta.about,
banner: meta.banner,
picture: meta.picture,
},
})
})
projections.addHandler(34550, (e: TrustedEvent) => {
const tags = Tags.fromEvent(e)
const meta = tags.asObject()
const address = getAddress(e)
const group = groups.key(address)
group.merge({address, id: meta.d, pubkey: e.pubkey})
updateStore(group, e.created_at, {
feeds: tags.whereKey("feed").unwrap(),
relays: tags.values("relay").valueOf(),
listing_is_public: true,
meta: {
name: meta.name,
about: meta.description,
banner: meta.banner,
picture: meta.image,
},
})
})
projections.addHandler(27, (e: TrustedEvent) => {
const address = Tags.fromEvent(e).groups().values().first()

View File

@ -90,7 +90,7 @@ export const deriveEventsMapped = <T>({
if (dirty) {
if (debug) {
if (new Set(data.map(item => itemToEvent(item).id)).size < data.length) {
console.error(`Duplicate records found:`, copy, data, updates)
console.error(`Duplicate records found:`, copy, [...data], updates)
}
}

View File

@ -1,5 +1,6 @@
import {debounce} from "throttle-debounce"
import {batch, Fetch, noop, tryFunc, seconds, createMapOf, sleep, switcherFn} from "hurdak"
import {get} from "svelte/store"
import type {LoadOpts} from "@welshman/feeds"
import {
FeedLoader,
@ -38,7 +39,6 @@ import {
deriveUserCircles,
getGroupReqInfo,
getCommunityReqInfo,
groups,
dvmRequest,
env,
getFollows,
@ -60,6 +60,7 @@ import {
subscribe,
subscribePersistent,
dufflepud,
deriveGroupMeta,
} from "src/engine/state"
import {updateCurrentSession, updateSession} from "src/engine/commands"
import {loadPubkeyRelays} from "src/engine/requests/pubkeys"
@ -140,9 +141,14 @@ export const getStaleAddrs = (addrs: string[]) => {
for (const addr of addrs) {
const attempts = attemptedAddrs.get(addr) | 0
const group = groups.key(addr).get()
if (!group?.meta || attempts === 0) {
if (attempts > 0) {
continue
}
const meta = get(deriveGroupMeta(addr))
if (!meta) {
stale.add(addr)
}

View File

@ -8,6 +8,7 @@ import {
NAMED_BOOKMARKS,
COMMUNITIES,
FEED,
FEEDS,
MUTES,
FOLLOWS,
APP_DATA,
@ -55,7 +56,7 @@ const getFiltersForKey = (key: string, authors: string[]) => {
return [{authors, kinds: [PROFILE, FOLLOWS, HANDLER_INFORMATION, COMMUNITIES]}]
case "pubkey/user":
return [
{authors, kinds: [PROFILE, RELAYS, MUTES, FOLLOWS, COMMUNITIES, APP_DATA]},
{authors, kinds: [PROFILE, RELAYS, MUTES, FOLLOWS, COMMUNITIES, FEEDS]},
{authors, kinds: [APP_DATA], "#d": Object.values(appDataKeys)},
]
}

View File

@ -2,7 +2,7 @@ import Fuse from "fuse.js"
import {openDB, deleteDB} from "idb"
import type {IDBPDatabase} from "idb"
import {throttle} from "throttle-debounce"
import {derived, writable} from "svelte/store"
import {get, derived, writable} from "svelte/store"
import {defer, doPipe, batch, randomInt, seconds, sleep, switcher} from "hurdak"
import {
any,
@ -43,6 +43,9 @@ import {
} from "@welshman/lib"
import {
WRAP,
FEEDS,
COMMUNITY,
GROUP,
WRAP_NIP04,
COMMUNITIES,
READ_RECEIPT,
@ -103,6 +106,7 @@ import type {
PublishedListFeed,
PublishedSingleton,
PublishedList,
PublishedGroupMeta,
RelayPolicy,
Handle,
} from "src/domain"
@ -130,6 +134,7 @@ import {
makeRelayPolicy,
filterRelaysByNip,
displayRelayUrl,
readGroupMeta,
} from "src/domain"
import type {
Channel,
@ -178,6 +183,7 @@ export const handles = withGetter(writable<Record<string, Handle>>({}))
export const zappers = withGetter(writable<Record<string, Zapper>>({}))
export const plaintext = withGetter(writable<Record<string, string>>({}))
export const anonymous = withGetter(writable<AnonymousUserState>({follows: [], relays: []}))
export const groupHints = withGetter(writable<Record<string, string[]>>({}))
export const groups = new CollectionStore<Group>("address")
export const relays = new CollectionStore<RelayInfo>("url")
@ -250,7 +256,15 @@ export const imgproxy = (url: string, {w = 640, h = 1024} = {}) => {
}
}
export const dufflepud = (path: string) => `${getSetting("dufflepud_url")}/${path}`
export const dufflepud = (path: string) => {
const base = getSetting("dufflepud_url")
if (!base) {
throw new Error("Dufflepud is not enabled")
}
return `${base}/${path}`
}
export const session = new Derived(
[pubkey, sessions],
@ -719,46 +733,53 @@ export const deriveCommunities = (pk: string) =>
// Groups
export const deriveGroup = address => {
const {pubkey, identifier: id} = Address.from(address)
export const groupMeta = deriveEventsMapped<PublishedGroupMeta>({
filters: [{kinds: [GROUP, COMMUNITY]}],
itemToEvent: prop("event"),
eventToItem: readGroupMeta,
})
return groups.key(address).derived(defaultTo({id, pubkey, address}))
}
export const groupMetaByAddress = withGetter(
derived(groupMeta, $metas => indexBy($meta => getAddress($meta.event), $metas)),
)
export const searchGroups = derived(
[groups.throttle(300), communityListsByAddress, userFollows],
([$groups, $communityListsByAddress, $userFollows]) => {
const options = $groups
.filter(group => !repository.deletes.has(group.address))
.map(group => {
const lists = $communityListsByAddress.get(group.address) || []
const members = lists.map(l => l.event.pubkey)
const followedMembers = intersection(members, $userFollows)
export const deriveGroupMeta = (address: string) =>
derived(groupMetaByAddress, $m => $m.get(address))
return {group, score: followedMembers.length}
})
export const searchGroupMeta = derived(
[groupMeta, communityListsByAddress, userFollows],
([$groupMeta, $communityListsByAddress, $userFollows]) => {
const options = $groupMeta.map(meta => {
const lists = $communityListsByAddress.get(getAddress(meta.event)) || []
const members = lists.map(l => l.event.pubkey)
const followedMembers = intersection(members, Array.from($userFollows))
return {...meta, score: followedMembers.length}
})
const fuse = new Fuse(options, {
keys: [{name: "group.id", weight: 0.2}, "group.meta.name", "group.meta.about"],
keys: [{name: "identifier", weight: 0.2}, "name", {name: "about", weight: 0.5}],
threshold: 0.3,
shouldSort: false,
includeScore: true,
})
return (term: string) => {
if (!term) {
return sortBy(item => -item.score, options).map(item => item.group)
}
const sortFn = (r: any) => r.score - Math.pow(Math.max(0, r.item.score), 1 / 100)
return doPipe(fuse.search(term), [
$results =>
sortBy((r: any) => r.score - Math.pow(Math.max(0, r.item.score), 1 / 100), $results),
$results => $results.map((r: any) => r.item.group),
])
}
return (term: string) =>
term
? sortBy(sortFn, fuse.search(term)).map((r: any) => r.item.meta)
: sortBy(meta => -meta.score, options)
},
)
// Legacy
export const deriveGroup = address => {
const {pubkey, identifier: id} = Address.from(address)
return groups.key(address).derived(defaultTo({id, pubkey, address}))
}
export const getRecipientKey = wrap => {
const pubkey = Tags.fromEvent(wrap).values("p").first()
const sharedKey = groupSharedKeys.key(pubkey).get()
@ -943,8 +964,7 @@ export const groupNotifications = new Derived(
const $isEventMuted = isEventMuted.get()
const shouldSkip = e => {
const tags = Tags.fromEvent(e)
const context = tags.context().values().valueOf()
const context = e.tags.filter(t => t[0] === "a")
return (
!context.some(a => addresses.has(a)) ||
@ -952,7 +972,7 @@ export const groupNotifications = new Derived(
!noteKinds.includes(e.kind) ||
e.pubkey === $session.pubkey ||
// Skip mentions since they're covered in normal notifications
tags.values("p").has($session.pubkey) ||
e.tags.find(t => t[0] === "p" && t[1] === $session.pubkey) ||
$isEventMuted(e)
)
}
@ -1147,20 +1167,21 @@ export const deriveUserRelayPolicy = url =>
// Relay selection
export const getGroupRelayUrls = address => {
const group = groups.key(address).get()
const keys = groupSharedKeys.get()
const meta = groupMetaByAddress.get().get(address)
if (group?.relays) {
return group.relays
if (meta?.relays) {
return meta.relays.map(nth(1))
}
const latestKey = last(sortBy(prop("created_at"), keys.filter(whereEq({group: address}))))
const latestKey = last(
sortBy(prop("created_at"), get(groupSharedKeys).filter(whereEq({group: address}))),
)
if (latestKey?.hints) {
return latestKey.hints
}
return []
return get(groupHints)[address] || []
}
export const forceRelays = (relays: string[], forceRelays: string[]) =>
@ -1257,15 +1278,36 @@ export const listSearch = derived(lists, $lists => new ListSearch($lists))
export const feeds = deriveEventsMapped<PublishedFeed>({
filters: [{kinds: [FEED]}],
eventToItem: readFeed,
itemToEvent: prop("event"),
eventToItem: readFeed,
})
export const userFeeds = derived([feeds, pubkey], ([$feeds, $pubkey]: [PublishedFeed[], string]) =>
sortBy(
f => f.title.toLowerCase(),
$feeds.filter(feed => feed.event.pubkey === $pubkey),
),
$feeds.filter(feed => feed.event.pubkey === $pubkey),
)
export const feedFavorites = deriveEventsMapped<PublishedSingleton>({
filters: [{kinds: [FEEDS]}],
itemToEvent: prop("event"),
eventToItem: event =>
readSingleton(
asDecryptedEvent(event, {
content: getPlaintext(event),
}),
),
})
export const userFeedFavorites = derived(
[feedFavorites, pubkey],
([$singletons, $pubkey]: [PublishedSingleton[], string]) =>
$singletons.find(singleton => singleton.event.pubkey === $pubkey),
)
export const userFavoritedFeeds = derived(userFeedFavorites, $singleton =>
Array.from(getSingletonValues("a", $singleton))
.map(repository.getEvent)
.filter(identity)
.map(readFeed),
)
export const feedSearch = derived(feeds, $feeds => new FeedSearch($feeds))
@ -1495,6 +1537,7 @@ export const onAuth = async (url, challenge) => {
export type MySubscribeRequest = SubscribeRequest & {
onEvent?: (event: TrustedEvent) => void
onEose?: (url: string) => void
onComplete?: () => void
skipCache?: boolean
forcePlatform?: boolean
@ -1539,6 +1582,10 @@ export const subscribe = ({forcePlatform = true, ...request}: MySubscribeRequest
projections.push(await ensureUnwrapped(event))
})
if (request.onEose) {
sub.emitter.on("eose", request.onEose)
}
if (request.onComplete) {
sub.emitter.on("complete", request.onComplete)
}
@ -1577,7 +1624,14 @@ export const subscribePersistent = (request: MySubscribeRequest) => {
export const LOAD_OPTS = {timeout: 3000, closeOnEose: true}
export const load = (request: MySubscribeRequest) => subscribe({...request, ...LOAD_OPTS}).result
export const load = (request: MySubscribeRequest) =>
new Promise(resolve => {
const events = []
const sub = subscribe({...request, ...LOAD_OPTS})
sub.emitter.on("event", (url: string, event: TrustedEvent) => events.push(event))
sub.emitter.on("complete", (url: string) => resolve(events))
})
export const loadOne = (request: MySubscribeRequest) =>
new Promise<TrustedEvent | null>(resolve => {
@ -1986,16 +2040,19 @@ class IndexedDBAdapter {
const removedRecords = prev.filter(r => !currentIds.has(r[key]))
if (newRecords.length > 0) {
console.log("putting", name, newRecords.length, current.length)
await storage.bulkPut(name, newRecords)
}
if (removedRecords.length > 0) {
console.trace("deleting", name, removedRecords.length, current.length)
await storage.bulkDelete(name, removedRecords.map(prop(key)))
}
// If we have much more than our limit, prune our store. This will get persisted
// the next time around.
if (current.length > limit * 1.5) {
console.log("pruning", name, current.length)
set((sort ? sort(current) : current).slice(0, limit))
}

View File

@ -1,11 +0,0 @@
import {ellipsize} from "hurdak"
import {Address} from "@welshman/util"
import type {Group} from "src/engine/model"
export const getGroupNaddr = (group: Group) => Address.from(group.address, group.relays).toNaddr()
export const getGroupId = (group: Group) => group.address.split(":").slice(2).join(":")
export const getGroupName = (group: Group) => group.meta?.name || group.id || ""
export const displayGroup = (group: Group) => ellipsize(group ? getGroupName(group) : "No name", 60)

View File

@ -12,7 +12,6 @@ export * from "./nip59"
export * from "./signer"
export * from "./connect"
export * from "./events"
export * from "./groups"
export const getConnect = memoize(session => new Connect(session))

View File

@ -18,8 +18,8 @@
const loadPreview = async () => {
const json = await Fetch.postJson(dufflepud("link/preview"), {url})
if (!json.title && !json.image) {
throw new Error("Unable to load preview")
if (!json?.title && !json?.image) {
throw new Error("Failed to load link preview")
}
return json
@ -81,7 +81,7 @@
</div>
{/if}
{:catch}
<p class="mb-1 px-12 py-24 text-center text-neutral-600">
<p class="mb-1 p-12 text-center text-neutral-600">
Unable to load a preview for {url}
</p>
{/await}

View File

@ -1,31 +0,0 @@
<script lang="ts">
import Media from "src/partials/Media.svelte"
import Anchor from "src/partials/Anchor.svelte"
import Modal from "src/partials/Modal.svelte"
export let links
let showModal = false
const openModal = () => {
showModal = true
}
const closeModal = () => {
showModal = false
}
</script>
<div class="my-8 flex justify-center">
<Anchor button on:click={openModal}>
<i class="fa fa-plus" /> Show all {links.length} link previews
</Anchor>
</div>
{#if showModal}
<Modal onEscape={closeModal}>
{#each links as url}
<Media {url} />
{/each}
</Modal>
{/if}

View File

@ -5,16 +5,18 @@
export let displayOption = x => x
const getClassName = active =>
cx("px-4 h-7 transition-all rounded-full mr-2 mb-2 inline-flex items-center", {
cx("px-4 h-6 transition-all rounded-full mr-2 mb-2 inline-block items-center", {
"bg-neutral-900 dark:bg-tinted-100 text-accent": active,
"bg-neutral-900 text-neutral-400": !active,
})
</script>
<div class="-mb-2 inline-block">
<SelectList {...$$props} class="staatliches inline-flex">
<div class={cx($$props.class, "-mb-2 inline-block")}>
<SelectList {...$$props} optionClass="staatliches inline-block">
<div slot="item" let:i let:active let:option class={getClassName(active)}>
{displayOption(option)}
<slot name="item" {option} {active}>
{displayOption(option)}
</slot>
</div>
</SelectList>
</div>

View File

@ -6,6 +6,7 @@
export let onChange = null
export let disabled = false
export let multiple = false
export let optionClass = ""
const onClick = option => {
if (multiple) {
@ -24,7 +25,7 @@
class:opacity-75={disabled}
class:cursor-pointer={!disabled}>
{#each options as option, i}
<div on:click={() => onClick(option)}>
<div class={optionClass} on:click={() => onClick(option)}>
<slot
name="item"
{i}