Use social petnames

This commit is contained in:
Jonathan Staab 2023-06-28 16:20:45 -07:00
parent ee0b555bfe
commit 09fa5dd669
7 changed files with 21 additions and 48 deletions

View File

@ -116,28 +116,6 @@ export default {
getPetnames: () => profileCopy.petnames,
petnamePubkeys: derived(petnames, map(nth(1))) as Readable<Array<string>>,
getPetnamePubkeys: () => profileCopy.petnames.map(nth(1)),
updatePetnames(f) {
const $petnames = f(profileCopy.petnames)
profile.update(assoc("petnames", $petnames))
if (get(keys.canSign)) {
return cmd.setPetnames($petnames).publish(profileCopy.relays)
}
},
addPetname(pubkey, url, name) {
const tag = ["p", pubkey, url, name || ""]
return this.updatePetnames(
pipe(
reject(t => t[1] === pubkey),
concat([tag])
)
)
},
removePetname(pubkey) {
return this.updatePetnames(reject(t => t[1] === pubkey))
},
// Relays

View File

@ -6,7 +6,7 @@
import {modal} from "src/partials/state"
import Popover from "src/partials/Popover.svelte"
import OverflowMenu from "src/partials/OverflowMenu.svelte"
import {keys} from "src/system"
import {keys, social} from "src/system"
import {sampleRelays, getPubkeyWriteRelays} from "src/agent/relays"
import user from "src/agent/user"
import pool from "src/agent/pool"
@ -65,12 +65,10 @@
const follow = async () => {
const [{url}] = sampleRelays(getPubkeyWriteRelays(person.pubkey))
user.addPetname(person.pubkey, url, displayPerson(person))
social.follow(person.pubkey, url, displayPerson(person))
}
const unfollow = async () => {
user.removePetname(person.pubkey)
}
const unfollow = () => social.unfollow(person.pubkey)
const mute = async () => {
user.addMute("p", person.pubkey)

View File

@ -1,32 +1,31 @@
<script lang="ts">
import {last, nth} from "ramda"
import {last} from "ramda"
import {fly} from "src/util/transition"
import {displayPerson} from "src/util/nostr"
import {modal} from "src/partials/state"
import Anchor from "src/partials/Anchor.svelte"
import PersonCircle from "src/app/shared/PersonCircle.svelte"
import PersonAbout from "src/app/shared/PersonAbout.svelte"
import {keys} from "src/system"
import {keys, social} from "src/system"
import {watch} from "src/agent/db"
import {getPubkeyWriteRelays, sampleRelays} from "src/agent/relays"
import user from "src/agent/user"
const {canSign} = keys
const {petnames} = user
export let person
export let hasPetname = null
const removePetname = ({pubkey}) => user.removePetname(pubkey)
const unfollow = ({pubkey}) => social.unfollow(pubkey)
const addPetname = ({pubkey}) => {
const follow = ({pubkey}) => {
const [{url}] = sampleRelays(getPubkeyWriteRelays(pubkey))
user.addPetname(pubkey, url, displayPerson(person))
social.follow(pubkey, url, displayPerson(person))
}
$: isFollowing = hasPetname
? hasPetname(person.pubkey)
: $petnames.map(nth(1)).includes(person.pubkey)
const isFollowing = watch(social.graph, () =>
hasPetname ? hasPetname(person.pubkey) : social.isUserFollowing(person.pubkey)
)
</script>
<div in:fly={{y: 20}}>
@ -49,12 +48,11 @@
</div>
{#if $canSign}
{#if isFollowing}
<Anchor theme="button-accent" stopPropagation on:click={() => removePetname(person)}>
<Anchor theme="button-accent" stopPropagation on:click={() => unfollow(person)}>
Following
</Anchor>
{:else}
<Anchor theme="button" stopPropagation on:click={() => addPetname(person)}
>Follow</Anchor>
<Anchor theme="button" stopPropagation on:click={() => follow(person)}>Follow</Anchor>
{/if}
{/if}
</div>

View File

@ -2,7 +2,7 @@
import {last, nth} from "ramda"
import {displayPerson} from "src/util/nostr"
import Anchor from "src/partials/Anchor.svelte"
import {keys} from "src/system"
import {keys, social} from "src/system"
import user from "src/agent/user"
import {sampleRelays, getPubkeyWriteRelays} from "src/agent/relays"
import {getPersonWithFallback} from "src/agent/db"
@ -24,10 +24,10 @@
const follow = () => {
const [{url}] = getRelays()
user.addPetname(pubkey, url, displayPerson($person))
social.follow(pubkey, url, displayPerson($person))
}
const unfollow = () => user.removePetname(pubkey)
const unfollow = () => social.unfollow(pubkey)
const unmute = () => user.removeMute(pubkey)

View File

@ -45,7 +45,7 @@
user.updateRelays(() => user.getRelays()),
cmd.updateUser(profile).publish(user.getRelays()),
note && cmd.createNote(note).publish(user.getRelays()),
user.updatePetnames(() =>
social.updatePetnames(
user.getPetnamePubkeys().map(pubkey => {
const [{url}] = sampleRelays(getPubkeyWriteRelays(pubkey))
const name = displayPerson(getPersonWithFallback(pubkey))

View File

@ -6,7 +6,7 @@
import Heading from "src/partials/Heading.svelte"
import Content from "src/partials/Content.svelte"
import PersonInfo from "src/app/shared/PersonInfo.svelte"
import {DEFAULT_FOLLOWS} from "src/system"
import {DEFAULT_FOLLOWS, social} from "src/system"
import {getPersonWithFallback, searchPeople} from "src/agent/db"
import {sampleRelays, getPubkeyWriteRelays} from "src/agent/relays"
import {modal} from "src/partials/state"
@ -15,7 +15,7 @@
const {petnamePubkeys} = user
if ($petnamePubkeys.length === 0) {
user.updatePetnames(() =>
social.updatePetnames(
DEFAULT_FOLLOWS.map(pubkey => {
const [{url}] = sampleRelays(getPubkeyWriteRelays(pubkey))
const name = displayPerson(getPersonWithFallback(pubkey))

View File

@ -72,7 +72,6 @@ export default ({keys, sync, cmd, getUserWriteRelays}) => {
const getUserKey = () => keys.getPubkey() || "anonymous"
const getUserPetnames = () => getPetnames(getUserKey())
const getUserPetnamePubkeys = () => getPetnamePubkeys(getUserKey())
const getUserFollows = () => getFollows(getUserKey())
const getUserNetwork = () => getNetwork(getUserKey())
const isUserFollowing = pubkey => isFollowing(getUserKey(), pubkey)
@ -106,10 +105,10 @@ export default ({keys, sync, cmd, getUserWriteRelays}) => {
getNetwork,
isFollowing,
getUserPetnames,
getUserPetnamePubkeys,
getUserFollows,
getUserNetwork,
isUserFollowing,
updatePetnames,
follow,
unfollow,
sortByGraph,