Add emoji parsing and utils

This commit is contained in:
Jon Staab
2025-05-12 15:09:00 -07:00
parent ba48789a89
commit 7ab746c30d
4 changed files with 50 additions and 9 deletions
+10 -1
View File
@@ -1,4 +1,4 @@
import {uniqBy, mapVals, nth, nthEq, ensurePlural} from "@welshman/lib"
import {uniqBy, first, spec, mapVals, nth, nthEq, ensurePlural} from "@welshman/lib"
import {isRelayUrl} from "./Relay.js"
import {Address} from "./Address.js"
@@ -106,6 +106,15 @@ export const getReplyTags = (tags: string[][]) => {
export const getReplyTagValues = (tags: string[][]) =>
mapVals(tags => tags.map(nth(1)), getReplyTags(tags))
export const getEmojiTags = (name: string, tags: string[][]) => tags.filter(spec(["emoji", name]))
export const getEmojiTag = (name: string, tags: string[][]) => first(getEmojiTags(name, tags))
export const getEmojiTagUrls = (name: string, tags: string[][]) =>
getEmojiTags(name, tags).map(nth(2))
export const getEmojiTagUrl = (name: string, tags: string[][]) => first(getEmojiTagUrls(name, tags))
export const uniqTags = (tags: string[][]) => uniqBy(t => t.slice(0, 2).join(":"), tags)
export const tagsFromIMeta = (imeta: string[]) => imeta.map((m: string) => m.split(" "))