Fix tag normalization
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "paravel",
|
"name": "paravel",
|
||||||
"version": "0.4.1",
|
"version": "0.4.2",
|
||||||
"description": "Yet another toolkit for nostr",
|
"description": "Yet another toolkit for nostr",
|
||||||
"author": "hodlbod",
|
"author": "hodlbod",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
+20
-13
@@ -180,26 +180,33 @@ export class Tags extends Fluent<string[]> {
|
|||||||
|
|
||||||
// Support the deprecated version where tags are not marked as replies
|
// Support the deprecated version where tags are not marked as replies
|
||||||
normalize() {
|
normalize() {
|
||||||
const tags = this.type(["a", "e"]).filter(t => last(t) !== "mention")
|
const tags = this.type(["a", "e"])
|
||||||
const legacy = tags.any(t => !["reply", "root"].includes(last(t)))
|
|
||||||
|
|
||||||
if (!legacy) {
|
// If we have a mark, we're not using the legacy format
|
||||||
|
if (tags.any(t => ["reply", "root"].includes(last(t)))) {
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
const reply = tags.last()
|
const reply = tags.values().last()
|
||||||
const root = tags.count() > 1 ? tags.first() : null
|
const root = tags.count() > 1 ? tags.values().first() : null
|
||||||
const newTags = tags.reject(t => [reply?.[1], root?.[1]].includes(t[1])).all()
|
|
||||||
|
|
||||||
if (reply) {
|
return new Tags(tags.all().map(t => {
|
||||||
newTags.push(reply.slice(0, 3).concat("reply"))
|
t = t.slice(0, 3)
|
||||||
}
|
|
||||||
|
|
||||||
if (root) {
|
if (t.length === 2) {
|
||||||
newTags.push(root.slice(0, 3).concat("root"))
|
t.push("")
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Tags(newTags)
|
let mark = 'mention'
|
||||||
|
|
||||||
|
if (t[1] === reply) {
|
||||||
|
mark = 'reply'
|
||||||
|
} else if (t[1] === root) {
|
||||||
|
mark = 'root'
|
||||||
|
}
|
||||||
|
|
||||||
|
return [...t, mark]
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
getReply = () => {
|
getReply = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user