diff --git a/nip18.test.ts b/nip18.test.ts index d424090..139779b 100644 --- a/nip18.test.ts +++ b/nip18.test.ts @@ -100,3 +100,30 @@ describe('getRepostedEventPointer', () => { expect(repostedEventPointer!.relays).toEqual([relayUrl]) }) }) + +describe('finishRepostEvent', () => { + const privateKey = hexToBytes('d217c1ff2f8a65c3e3a1740db3b9f58b8c848bb45e26d00ed4714e4a0f4ceecf') + + test('should create an event with empty content if the reposted event is protected', () => { + const repostedEvent = finalizeEvent( + { + kind: ShortTextNote, + tags: [ + ['e', 'replied event id'], + ['p', 'replied event pubkey'], + ['-'], + ], + content: 'Replied to a post', + created_at: 1617932115, + }, + privateKey, + ) + const template = { + created_at: 1617932115, + } + + const event = finishRepostEvent(template, repostedEvent, relayUrl, privateKey) + + expect(event.content).toBe('') + }) +}) diff --git a/nip18.ts b/nip18.ts index a721bb8..9fd6065 100644 --- a/nip18.ts +++ b/nip18.ts @@ -29,7 +29,7 @@ export function finishRepostEvent( { kind: Repost, tags: [...(t.tags ?? []), ['e', reposted.id, relayUrl], ['p', reposted.pubkey]], - content: t.content === '' ? '' : JSON.stringify(reposted), + content: t.content === '' || reposted.tags?.find(tag => tag[0] === '-') ? '' : JSON.stringify(reposted), created_at: t.created_at, }, privateKey,