mirror of
https://github.com/styppo/hamstr.git
synced 2024-10-18 05:23:28 +00:00
Implement NIP10 tag parsing
This commit is contained in:
parent
c770c4cead
commit
38b8c2cde2
@ -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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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() {
|
||||||
|
@ -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,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user