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 {
constructor(type, ref, relay = null, meta = null) {
constructor(type, ref, relay = null, marker = null) {
this.type = type
this.ref = ref
this.relay = relay
this.meta = meta
this.marker = marker
}
static from(array) {
@ -37,17 +37,20 @@ export class Tag {
}
export class EventRefs extends Array {
constructor(refs) {
// FIXME limit number of refs here
super(...refs)
constructor(tags) {
// FIXME limit number of tags here
super(...tags.map(tag => tag.ref))
this.tags = tags
}
root() {
return this[0]
return this.tags.find(tag => tag.marker === 'root')?.ref || this[0]
}
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() {
@ -109,6 +112,6 @@ export default class Event {
}
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() {
return !this.eventRefs().isEmpty()
return this.eventTags().some(tag => tag.marker !== 'mention')
}
canReply() {
@ -54,7 +54,7 @@ export default class Note {
}
eventRefs() {
return new EventRefs(this.eventTags().map(tag => tag.ref))
return new EventRefs(this.eventTags())
}
relatedPubkeys() {

View File

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