Skip to content

Commit c0c3f49

Browse files
Merge pull request #21 from DanConwayDev/pr/make-getTtags-nip24-compliant
make getTtags nip24 compliant
2 parents 03c8f0d + a87ab90 commit c0c3f49

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/__tests__/storage.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe('Storage', () => {
7070
relays: ['relay1'],
7171
pubkey: ref.pubkey,
7272
})
73-
const event = fakeEvent({ content: `GM! ${nprofile} ${naddr} ${nevent} #asknostr` })
73+
const event = fakeEvent({ content: `GM! ${nprofile} ${naddr} ${nevent} #asknostr #Photography` })
7474

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

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

9394
// assert without relay hints
@@ -97,7 +98,8 @@ describe('Storage', () => {
9798
['a', `1:${ref.pubkey}:identifier`],
9899
['imeta', 'dim 500x500', 'm image/png', 'size 21792', `url https://localhost:3000/${hash1}.png`, `x ${hash1}`],
99100
['imeta', 'dim 500x500', 'm image/png', 'size 16630', `url https://localhost:3000/${hash2}.png`, `x ${hash2}`],
100-
['t', '#asknostr'],
101+
['t', 'asknostr'],
102+
['t', 'photography'],
101103
])
102104
})
103105
})

src/extensions/NostrExtension.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,12 @@ export const NostrExtension = Extension.create<NostrOptions, NostrStorage>({
195195
}
196196

197197
this.storage.getTtags = () => {
198-
return this.storage.getTags().map(({ tag }) => ['t', tag])
198+
const tags: string[][] = [];
199+
this.storage.getTags().forEach(({ tag }) => {
200+
const s = tag.slice(1).toLocaleLowerCase();
201+
if (!tags.some((t) => t[1] === s)) tags.push(['t',s]);
202+
});
203+
return tags
199204
}
200205

201206
this.storage.getPtags = (hints = true) => {

0 commit comments

Comments
 (0)