Skip to content

Commit

Permalink
Merge pull request #21 from DanConwayDev/pr/make-getTtags-nip24-compl…
Browse files Browse the repository at this point in the history
…iant

make getTtags nip24 compliant
  • Loading branch information
cesardeazevedo authored Jan 30, 2025
2 parents 03c8f0d + a87ab90 commit c0c3f49
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/__tests__/storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('Storage', () => {
relays: ['relay1'],
pubkey: ref.pubkey,
})
const event = fakeEvent({ content: `GM! ${nprofile} ${naddr} ${nevent} #asknostr` })
const event = fakeEvent({ content: `GM! ${nprofile} ${naddr} ${nevent} #asknostr #Photography` })

editor.commands.setEventContent(event)
fileUpload.uploader?.addFile(file, editor.$doc.size - 2)
Expand All @@ -79,15 +79,16 @@ describe('Storage', () => {
await fileUpload.uploader?.start()

expect(editor.getText({ blockSeparator: ' ' })).toStrictEqual(
`GM! nostr:${nprofile} nostr:${naddr} nostr:${nevent} #asknostr https://localhost:3000/6c36995913e97b73d5365f93a7b524a9e45edc68e4f11b78060154987c53602c.png https://localhost:3000/008a2224c4d2a513ab2a4add09a2ac20c2d9cec1144b5111bc1317edb2366eac.png`,
`GM! nostr:${nprofile} nostr:${naddr} nostr:${nevent} #asknostr #Photography https://localhost:3000/6c36995913e97b73d5365f93a7b524a9e45edc68e4f11b78060154987c53602c.png https://localhost:3000/008a2224c4d2a513ab2a4add09a2ac20c2d9cec1144b5111bc1317edb2366eac.png`,
)
expect(nostr.getEditorTags()).toStrictEqual([
['p', ref.pubkey, 'relay1'],
['q', ref.id, 'relay1', ref.pubkey],
['a', `1:${ref.pubkey}:identifier`, 'relay1'],
['imeta', 'dim 500x500', 'm image/png', 'size 21792', `url https://localhost:3000/${hash1}.png`, `x ${hash1}`],
['imeta', 'dim 500x500', 'm image/png', 'size 16630', `url https://localhost:3000/${hash2}.png`, `x ${hash2}`],
['t', '#asknostr'],
['t', 'asknostr'],
['t', 'photography'],
])

// assert without relay hints
Expand All @@ -97,7 +98,8 @@ describe('Storage', () => {
['a', `1:${ref.pubkey}:identifier`],
['imeta', 'dim 500x500', 'm image/png', 'size 21792', `url https://localhost:3000/${hash1}.png`, `x ${hash1}`],
['imeta', 'dim 500x500', 'm image/png', 'size 16630', `url https://localhost:3000/${hash2}.png`, `x ${hash2}`],
['t', '#asknostr'],
['t', 'asknostr'],
['t', 'photography'],
])
})
})
Expand Down
7 changes: 6 additions & 1 deletion src/extensions/NostrExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,12 @@ export const NostrExtension = Extension.create<NostrOptions, NostrStorage>({
}

this.storage.getTtags = () => {
return this.storage.getTags().map(({ tag }) => ['t', tag])
const tags: string[][] = [];
this.storage.getTags().forEach(({ tag }) => {
const s = tag.slice(1).toLocaleLowerCase();
if (!tags.some((t) => t[1] === s)) tags.push(['t',s]);
});
return tags
}

this.storage.getPtags = (hints = true) => {
Expand Down

0 comments on commit c0c3f49

Please sign in to comment.