Implement NIP10 tag parsing

This commit is contained in:
styppo 2023-02-01 00:16:59 +00:00
parent c770c4cead
commit 38b8c2cde2
No known key found for this signature in database
GPG Key ID: 3AAA685C50724C28
3 changed files with 14 additions and 11 deletions

View File

@ -18,11 +18,11 @@ export const TagType = {
} }
export class Tag { export class Tag {
constructor(type, ref, relay = null, meta = null) { constructor(type, ref, relay = null, marker = null) {
this.type = type this.type = type
this.ref = ref this.ref = ref
this.relay = relay this.relay = relay
this.meta = meta this.marker = marker
} }
static from(array) { static from(array) {
@ -37,17 +37,20 @@ export class Tag {
} }
export class EventRefs extends Array { export class EventRefs extends Array {
constructor(refs) { constructor(tags) {
// FIXME limit number of refs here // FIXME limit number of tags here
super(...refs) super(...tags.map(tag => tag.ref))
this.tags = tags
} }
root() { root() {
return this[0] return this.tags.find(tag => tag.marker === 'root')?.ref || this[0]
} }
ancestor() { ancestor() {
return this[this.length - 1] return this.tags.find(tag => tag.marker === 'reply')?.ref
|| this.tags.find(tag => tag.marker === 'root')?.ref
|| this[this.length - 1]
} }
isEmpty() { isEmpty() {
@ -109,6 +112,6 @@ export default class Event {
} }
eventRefs() { eventRefs() {
return new EventRefs(this.eventTags().map(tag => tag.ref)) return new EventRefs(this.eventTags())
} }
} }

View File

@ -26,7 +26,7 @@ export default class Note {
} }
hasAncestor() { hasAncestor() {
return !this.eventRefs().isEmpty() return this.eventTags().some(tag => tag.marker !== 'mention')
} }
canReply() { canReply() {
@ -54,7 +54,7 @@ export default class Note {
} }
eventRefs() { eventRefs() {
return new EventRefs(this.eventTags().map(tag => tag.ref)) return new EventRefs(this.eventTags())
} }
relatedPubkeys() { relatedPubkeys() {

View File

@ -30,7 +30,7 @@ export const useContactStore = defineStore('contact', {
newContacts.push({ newContacts.push({
pubkey: tag.ref, pubkey: tag.ref,
relay: tag.relay, relay: tag.relay,
name: tag.meta, name: tag.marker,
}) })
} }