feat: generate new account & profile editor
This commit is contained in:
parent
3f031da748
commit
78629dd64f
33 changed files with 535 additions and 142 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { COMMENT_EVENT_KIND, PICTURE_EVENT_KIND } from '@/constants'
|
||||
import { TDraftEvent, TRelaySet } from '@/types'
|
||||
import { TDraftEvent, TMailboxRelay, TRelaySet } from '@/types'
|
||||
import dayjs from 'dayjs'
|
||||
import { Event, kinds } from 'nostr-tools'
|
||||
import {
|
||||
|
|
@ -182,6 +182,35 @@ export async function createCommentDraftEvent(
|
|||
}
|
||||
}
|
||||
|
||||
export function createRelayListDraftEvent(mailboxRelays: TMailboxRelay[]): TDraftEvent {
|
||||
return {
|
||||
kind: kinds.RelayList,
|
||||
content: '',
|
||||
tags: mailboxRelays.map(({ url, scope }) =>
|
||||
scope === 'both' ? ['r', url] : ['r', url, scope]
|
||||
),
|
||||
created_at: dayjs().unix()
|
||||
}
|
||||
}
|
||||
|
||||
export function createFollowListDraftEvent(tags: string[][], content?: string): TDraftEvent {
|
||||
return {
|
||||
kind: kinds.Contacts,
|
||||
content: content ?? '',
|
||||
created_at: dayjs().unix(),
|
||||
tags
|
||||
}
|
||||
}
|
||||
|
||||
export function createProfileDraftEvent(content: string, tags: string[][] = []): TDraftEvent {
|
||||
return {
|
||||
kind: kinds.Metadata,
|
||||
content,
|
||||
tags,
|
||||
created_at: dayjs().unix()
|
||||
}
|
||||
}
|
||||
|
||||
function generateImetaTags(imageUrls: string[], pictureInfos: { url: string; tags: string[][] }[]) {
|
||||
return imageUrls.map((imageUrl) => {
|
||||
const pictureInfo = pictureInfos.find((info) => info.url === imageUrl)
|
||||
|
|
|
|||
|
|
@ -110,15 +110,16 @@ export function getRelayListFromRelayListEvent(event?: Event) {
|
|||
export function getProfileFromProfileEvent(event: Event) {
|
||||
try {
|
||||
const profileObj = JSON.parse(event.content)
|
||||
const username =
|
||||
profileObj.display_name?.trim() ||
|
||||
profileObj.name?.trim() ||
|
||||
profileObj.nip05?.split('@')[0]?.trim()
|
||||
return {
|
||||
pubkey: event.pubkey,
|
||||
banner: profileObj.banner,
|
||||
avatar: profileObj.picture,
|
||||
username:
|
||||
profileObj.display_name?.trim() ||
|
||||
profileObj.name?.trim() ||
|
||||
profileObj.nip05?.split('@')[0]?.trim() ||
|
||||
formatPubkey(event.pubkey),
|
||||
username: username || formatPubkey(event.pubkey),
|
||||
original_username: username,
|
||||
nip05: profileObj.nip05,
|
||||
about: profileObj.about,
|
||||
created_at: event.created_at
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ export const toFollowingList = (pubkey: string) => {
|
|||
}
|
||||
export const toRelaySettings = () => '/relay-settings'
|
||||
export const toSettings = () => '/settings'
|
||||
export const toProfileEditor = () => '/profile-editor'
|
||||
|
||||
export const toNoStrudelProfile = (id: string) => `https://nostrudel.ninja/#/u/${id}`
|
||||
export const toNoStrudelNote = (id: string) => `https://nostrudel.ninja/#/n/${id}`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue