Browse Source

make sure only the author can delete events

imwald
Silberengel 1 month ago
parent
commit
12777d6e75
  1. 4
      src/components/NoteOptions/useMenuActions.tsx
  2. 11
      src/pages/primary/SpellsPage/index.tsx
  3. 6
      src/pages/secondary/FollowSetsSettingsPage/index.tsx

4
src/components/NoteOptions/useMenuActions.tsx

@ -850,8 +850,8 @@ export function useMenuActions({
}) })
} }
// Delete functionality only available for own notes // Delete only when signed in as the author with a signing key (not read-only npub)
if (pubkey && event.pubkey === pubkey) { if (canSignEvents && pubkey && event.pubkey === pubkey) {
actions.push({ actions.push({
icon: Trash2, icon: Trash2,
label: t('Try deleting this note'), label: t('Try deleting this note'),

11
src/pages/primary/SpellsPage/index.tsx

@ -310,7 +310,8 @@ const SpellsPage = forwardRef<TPageRef>(function SpellsPage(
) { ) {
const { t } = useTranslation() const { t } = useTranslation()
const { navigate: navigatePrimary } = usePrimaryPage() const { navigate: navigatePrimary } = usePrimaryPage()
const { pubkey, relayList, attemptDelete, bookmarkListEvent, interestListEvent } = useNostr() const { pubkey, account, relayList, attemptDelete, bookmarkListEvent, interestListEvent } =
useNostr()
const { addBookmark, removeBookmark } = useBookmarks() const { addBookmark, removeBookmark } = useBookmarks()
const { hideUntrustedNotifications } = useUserTrust() const { hideUntrustedNotifications } = useUserTrust()
const { isSmallScreen } = useScreenSize() const { isSmallScreen } = useScreenSize()
@ -1179,7 +1180,9 @@ const SpellsPage = forwardRef<TPageRef>(function SpellsPage(
[logSpellFeedPickerSelection, navigatePrimary, selectedFauxSpell, selectedSpell] [logSpellFeedPickerSelection, navigatePrimary, selectedFauxSpell, selectedSpell]
) )
const selectedSpellIsOwn = !!(pubkey && selectedSpell && selectedSpell.pubkey === pubkey) const canSignSpellActions = account != null && account.signerType !== 'npub'
const selectedSpellIsAuthor = !!(pubkey && selectedSpell && selectedSpell.pubkey === pubkey)
const selectedSpellCanEditOrDelete = selectedSpellIsAuthor && canSignSpellActions
const handleSpellFeedFirstPaint = useCallback( const handleSpellFeedFirstPaint = useCallback(
(detail: { eventCount: number; firstEventId: string }) => { (detail: { eventCount: number; firstEventId: string }) => {
@ -1588,7 +1591,7 @@ const SpellsPage = forwardRef<TPageRef>(function SpellsPage(
</Button> </Button>
</DropdownMenuTrigger> </DropdownMenuTrigger>
<DropdownMenuContent align="end"> <DropdownMenuContent align="end">
{selectedSpellIsOwn ? ( {selectedSpellCanEditOrDelete ? (
<DropdownMenuItem <DropdownMenuItem
className="gap-2" className="gap-2"
onClick={() => { onClick={() => {
@ -1617,7 +1620,7 @@ const SpellsPage = forwardRef<TPageRef>(function SpellsPage(
<FileText className="size-4" /> <FileText className="size-4" />
{t('View definition')} {t('View definition')}
</DropdownMenuItem> </DropdownMenuItem>
{selectedSpellIsOwn ? ( {selectedSpellCanEditOrDelete ? (
<> <>
<DropdownMenuSeparator /> <DropdownMenuSeparator />
<DropdownMenuItem <DropdownMenuItem

6
src/pages/secondary/FollowSetsSettingsPage/index.tsx

@ -59,7 +59,7 @@ const FOLLOW_SET_FETCH_OPTS = {
const FollowSetsSettingsPage = forwardRef( const FollowSetsSettingsPage = forwardRef(
({ index, hideTitlebar = false }: { index?: number; hideTitlebar?: boolean }, ref) => { ({ index, hideTitlebar = false }: { index?: number; hideTitlebar?: boolean }, ref) => {
const { t } = useTranslation() const { t } = useTranslation()
const { pubkey, publish, attemptDelete, checkLogin, relayList } = useNostr() const { pubkey, account, publish, attemptDelete, checkLogin, relayList } = useNostr()
const { favoriteRelays, blockedRelays } = useFavoriteRelays() const { favoriteRelays, blockedRelays } = useFavoriteRelays()
const [lists, setLists] = useState<Event[]>([]) const [lists, setLists] = useState<Event[]>([])
const [loading, setLoading] = useState(true) const [loading, setLoading] = useState(true)
@ -74,6 +74,8 @@ const FollowSetsSettingsPage = forwardRef(
const [deleteTarget, setDeleteTarget] = useState<Event | null>(null) const [deleteTarget, setDeleteTarget] = useState<Event | null>(null)
const [deleting, setDeleting] = useState(false) const [deleting, setDeleting] = useState(false)
const canSignEvents = account != null && account.signerType !== 'npub'
const { registerPrimaryPanelRefresh } = usePrimaryNoteView() const { registerPrimaryPanelRefresh } = usePrimaryNoteView()
const buildReadRelays = useCallback((): string[] => { const buildReadRelays = useCallback((): string[] => {
@ -275,6 +277,7 @@ const FollowSetsSettingsPage = forwardRef(
<Pencil className="size-4" /> <Pencil className="size-4" />
<span className="sr-only">{t('Edit')}</span> <span className="sr-only">{t('Edit')}</span>
</Button> </Button>
{canSignEvents && ev.pubkey === pubkey ? (
<Button <Button
type="button" type="button"
variant="outline" variant="outline"
@ -286,6 +289,7 @@ const FollowSetsSettingsPage = forwardRef(
<Trash2 className="size-4" /> <Trash2 className="size-4" />
<span className="sr-only">{t('Delete')}</span> <span className="sr-only">{t('Delete')}</span>
</Button> </Button>
) : null}
</div> </div>
</li> </li>
))} ))}

Loading…
Cancel
Save