-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: delete replaceable event * feat: add NIP-51 set events * feat: FollowSet * style: format
- Loading branch information
Showing
22 changed files
with
537 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { Component } from 'solid-js'; | ||
|
||
import Users from 'heroicons/24/outline/users.svg'; | ||
import uniq from 'lodash/uniq'; | ||
|
||
import BasicColumnHeader from '@/components/column/BasicColumnHeader'; | ||
import Column from '@/components/column/Column'; | ||
import ColumnSettings from '@/components/column/ColumnSettings'; | ||
import LoadMore, { useLoadMore } from '@/components/column/LoadMore'; | ||
import Timeline from '@/components/timeline/Timeline'; | ||
import { FollowSetColumnType } from '@/core/column'; | ||
import { applyContentFilter } from '@/core/contentFilter'; | ||
import useConfig from '@/core/useConfig'; | ||
import { useTranslation } from '@/i18n/useTranslation'; | ||
import useFollowSet from '@/nostr/useFollowSet'; | ||
import useSubscription from '@/nostr/useSubscription'; | ||
|
||
type FollowingColumnDisplayProps = { | ||
columnIndex: number; | ||
lastColumn: boolean; | ||
column: FollowSetColumnType; | ||
}; | ||
|
||
const FollowingColumn: Component<FollowingColumnDisplayProps> = (props) => { | ||
const i18n = useTranslation(); | ||
const { config, removeColumn } = useConfig(); | ||
|
||
const { followSet, title, pubkeys } = useFollowSet(() => ({ | ||
author: props.column.author, | ||
identifier: props.column.identifier, | ||
})); | ||
|
||
const columnName = () => | ||
props.column.name || title() || followSet()?.identifier() || i18n.t('column.followSet'); | ||
|
||
const loadMore = useLoadMore(() => ({ duration: null })); | ||
|
||
const { events, eose } = useSubscription(() => { | ||
const authors = uniq([...pubkeys()]); | ||
if (authors.length === 0) return null; | ||
return { | ||
debugId: 'following', | ||
relayUrls: config().relayUrls, | ||
filters: [ | ||
{ | ||
kinds: [1, 6], | ||
authors, | ||
limit: 20, | ||
since: loadMore.since(), | ||
until: loadMore.until(), | ||
}, | ||
], | ||
eoseLimit: 20, | ||
continuous: loadMore.continuous(), | ||
onEOSE: () => { | ||
console.log('home: eose'); | ||
}, | ||
clientEventFilter: (event) => { | ||
if (props.column.contentFilter == null) return true; | ||
return applyContentFilter(props.column.contentFilter)(event.content); | ||
}, | ||
}; | ||
}); | ||
|
||
return ( | ||
<Column | ||
header={ | ||
<BasicColumnHeader | ||
name={columnName()} | ||
icon={<Users />} | ||
settings={() => <ColumnSettings column={props.column} columnIndex={props.columnIndex} />} | ||
onClose={() => removeColumn(props.column.id)} | ||
/> | ||
} | ||
width={props.column.width} | ||
columnIndex={props.columnIndex} | ||
lastColumn={props.lastColumn} | ||
> | ||
<LoadMore loadMore={loadMore} eose={eose()}> | ||
<Timeline events={events()} /> | ||
</LoadMore> | ||
</Column> | ||
); | ||
}; | ||
|
||
export default FollowingColumn; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { type Component, For, Show } from 'solid-js'; | ||
|
||
import { useTranslation } from '@/i18n/useTranslation'; | ||
import NostrSet from '@/nostr/event/sets/NostrSet'; | ||
import useFollowSets from '@/nostr/useFollowSets'; | ||
import ensureNonNull from '@/utils/ensureNonNull'; | ||
|
||
type FollowSetsDisplayProps = { | ||
pubkey?: string; | ||
onSelectFollowSet: (pubkey: string, identifier: string) => void; | ||
}; | ||
|
||
const FollowSetsDisplay: Component<FollowSetsDisplayProps> = (props) => { | ||
const i18n = useTranslation(); | ||
|
||
const { followSets } = useFollowSets(() => | ||
ensureNonNull([props.pubkey] as const)(([pubkeyNonNull]) => ({ | ||
author: pubkeyNonNull, | ||
})), | ||
); | ||
|
||
return ( | ||
<div class="p-8"> | ||
{i18n.t('column.addFollowSetColumn.numberOfFollowSets', { count: followSets().length })} | ||
<div class="flex flex-col divide-y divide-border rounded border border-border"> | ||
<For each={followSets()}> | ||
{(followSet) => { | ||
const event = new NostrSet(followSet); | ||
|
||
return ( | ||
<button | ||
type="button" | ||
class="flex items-center gap-2 p-2 hover:bg-bg-tertiary" | ||
onClick={() => props.onSelectFollowSet(event.pubkey, event.identifier())} | ||
> | ||
<div class="size-8 shrink-0 bg-fg-secondary"> | ||
<Show when={event.image()} keyed> | ||
{(url) => <img class="size-full object-cover" src={url} alt="icon" />} | ||
</Show> | ||
</div> | ||
<div class="shrink-0 grow truncate text-start"> | ||
{event.title() ?? event.identifier()} | ||
</div> | ||
<div class="px-2 text-fg-secondary">{event.pTags().length}</div> | ||
</button> | ||
); | ||
}} | ||
</For> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default FollowSetsDisplay; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,37 @@ | ||
import * as Kind from 'nostr-tools/kinds'; | ||
import { type UnsignedEvent } from 'nostr-tools/pure'; | ||
|
||
import { ReplaceableEventIdentifier, replaceableEventIdentifier } from '@/nostr/identifier'; | ||
import epoch from '@/utils/epoch'; | ||
|
||
const createDeletion = ({ | ||
pubkey, | ||
eventId, | ||
identifier, | ||
reason, | ||
kind, | ||
}: { | ||
pubkey: string; | ||
eventId: string; | ||
identifier: string | ReplaceableEventIdentifier; | ||
reason?: string; | ||
kind: number; | ||
}): UnsignedEvent => ({ | ||
kind: Kind.EventDeletion, | ||
pubkey, | ||
created_at: epoch(), | ||
tags: [ | ||
['e', eventId, ''], | ||
['k', kind.toString()], | ||
], | ||
content: '', | ||
}); | ||
}): UnsignedEvent => { | ||
const tags: string[][] = []; | ||
|
||
if (typeof identifier === 'string') { | ||
tags.push(['e', identifier]); | ||
} else { | ||
tags.push(['a', replaceableEventIdentifier(identifier)]); | ||
} | ||
|
||
tags.push(['k', kind.toString()]); | ||
|
||
return { | ||
kind: Kind.EventDeletion, | ||
pubkey, | ||
created_at: epoch(), | ||
tags, | ||
content: reason ?? '', | ||
}; | ||
}; | ||
|
||
export default createDeletion; |
Oops, something went wrong.