mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-09 00:28:51 +00:00
nip18: don't stringify protected event.
This commit is contained in:
@@ -100,3 +100,30 @@ describe('getRepostedEventPointer', () => {
|
|||||||
expect(repostedEventPointer!.relays).toEqual([relayUrl])
|
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('')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|||||||
2
nip18.ts
2
nip18.ts
@@ -29,7 +29,7 @@ export function finishRepostEvent(
|
|||||||
{
|
{
|
||||||
kind: Repost,
|
kind: Repost,
|
||||||
tags: [...(t.tags ?? []), ['e', reposted.id, relayUrl], ['p', reposted.pubkey]],
|
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,
|
created_at: t.created_at,
|
||||||
},
|
},
|
||||||
privateKey,
|
privateKey,
|
||||||
|
|||||||
Reference in New Issue
Block a user