4 changed files with 139 additions and 65 deletions
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
import { ExtendedKind } from '@/constants' |
||||
import { |
||||
canPublishWithContent, |
||||
publishRequiresNonemptyContent, |
||||
PUBLISH_REQUIRES_NONEMPTY_CONTENT_KINDS |
||||
} from '@/lib/publish-content-required' |
||||
import { kinds } from 'nostr-tools' |
||||
import { describe, expect, it } from 'vitest' |
||||
|
||||
describe('publish-content-required', () => { |
||||
it('includes the listed text-bearing kinds', () => { |
||||
expect(PUBLISH_REQUIRES_NONEMPTY_CONTENT_KINDS.has(kinds.ShortTextNote)).toBe(true) |
||||
expect(PUBLISH_REQUIRES_NONEMPTY_CONTENT_KINDS.has(ExtendedKind.COMMENT)).toBe(true) |
||||
expect(PUBLISH_REQUIRES_NONEMPTY_CONTENT_KINDS.has(ExtendedKind.PUBLIC_MESSAGE)).toBe(true) |
||||
expect(PUBLISH_REQUIRES_NONEMPTY_CONTENT_KINDS.has(kinds.LongFormArticle)).toBe(true) |
||||
expect(PUBLISH_REQUIRES_NONEMPTY_CONTENT_KINDS.has(ExtendedKind.NOSTR_SPECIFICATION)).toBe(true) |
||||
expect(PUBLISH_REQUIRES_NONEMPTY_CONTENT_KINDS.has(ExtendedKind.WIKI_ARTICLE)).toBe(true) |
||||
expect(PUBLISH_REQUIRES_NONEMPTY_CONTENT_KINDS.has(ExtendedKind.PUBLICATION_CONTENT)).toBe(true) |
||||
}) |
||||
|
||||
it('rejects whitespace-only content for kind 1', () => { |
||||
expect(publishRequiresNonemptyContent(1)).toBe(true) |
||||
expect(canPublishWithContent(1, ' ')).toBe(false) |
||||
expect(canPublishWithContent(1, 'hello')).toBe(true) |
||||
}) |
||||
|
||||
it('allows empty content for other kinds', () => { |
||||
expect(canPublishWithContent(ExtendedKind.POLL, '')).toBe(true) |
||||
}) |
||||
}) |
||||
@ -0,0 +1,27 @@
@@ -0,0 +1,27 @@
|
||||
import { ExtendedKind } from '@/constants' |
||||
import { kinds } from 'nostr-tools' |
||||
|
||||
/** Kinds that must have non-whitespace `content` before Publish is enabled. */ |
||||
export const PUBLISH_REQUIRES_NONEMPTY_CONTENT_KINDS: ReadonlySet<number> = new Set([ |
||||
kinds.ShortTextNote, // 1 — notes and kind-1 replies
|
||||
ExtendedKind.COMMENT, // 1111
|
||||
ExtendedKind.PUBLIC_MESSAGE, // 24
|
||||
kinds.LongFormArticle, // 30023
|
||||
ExtendedKind.NOSTR_SPECIFICATION, // 30817
|
||||
ExtendedKind.WIKI_ARTICLE, // 30818
|
||||
ExtendedKind.PUBLICATION_CONTENT // 30041
|
||||
]) |
||||
|
||||
export function publishRequiresNonemptyContent(kind: number): boolean { |
||||
return PUBLISH_REQUIRES_NONEMPTY_CONTENT_KINDS.has(kind) |
||||
} |
||||
|
||||
export function hasNonemptyPublishContent(content: string): boolean { |
||||
return content.trim().length > 0 |
||||
} |
||||
|
||||
/** Whether Publish should be enabled for this kind and composer body. */ |
||||
export function canPublishWithContent(kind: number, content: string): boolean { |
||||
if (!publishRequiresNonemptyContent(kind)) return true |
||||
return hasNonemptyPublishContent(content) |
||||
} |
||||
Loading…
Reference in new issue