forked from coracle/flotilla
Optionally protect profiles
This commit is contained in:
@@ -1,25 +1,37 @@
|
||||
<script lang="ts">
|
||||
import type {Profile} from "@welshman/util"
|
||||
import {
|
||||
getTag,
|
||||
createEvent,
|
||||
makeProfile,
|
||||
editProfile,
|
||||
createProfile,
|
||||
isPublishedProfile,
|
||||
uniqTags,
|
||||
} from "@welshman/util"
|
||||
import {Router, pubkey, profilesByPubkey, publishThunk} from "@welshman/app"
|
||||
import Button from "@lib/components/Button.svelte"
|
||||
import ProfileEditForm from "@app/components/ProfileEditForm.svelte"
|
||||
import {clearModals} from "@app/modal"
|
||||
import {pushToast} from "@app/toast"
|
||||
import {PROTECTED, getMembershipUrls, userMembership} from "@app/state"
|
||||
|
||||
const initialValues = {...($profilesByPubkey.get($pubkey!) || makeProfile())}
|
||||
const profile = $profilesByPubkey.get($pubkey!) || makeProfile()
|
||||
const shouldBroadcast = !getTag(PROTECTED, profile.event?.tags || [])
|
||||
const initialValues = {profile, shouldBroadcast}
|
||||
|
||||
const back = () => history.back()
|
||||
|
||||
const onsubmit = (profile: Profile) => {
|
||||
const relays = Router.get().FromUser().getUrls()
|
||||
const onsubmit = ({profile, shouldBroadcast}: {profile: Profile; shouldBroadcast: boolean}) => {
|
||||
const relays = shouldBroadcast
|
||||
? Router.get().FromUser().getUrls()
|
||||
: getMembershipUrls($userMembership)
|
||||
const template = isPublishedProfile(profile) ? editProfile(profile) : createProfile(profile)
|
||||
|
||||
if (!shouldBroadcast) {
|
||||
template.tags = uniqTags([...template.tags, PROTECTED])
|
||||
}
|
||||
|
||||
const event = createEvent(template.kind, template)
|
||||
|
||||
publishThunk({event, relays})
|
||||
|
||||
Reference in New Issue
Block a user