feat: custom emoji reactions

This commit is contained in:
Alejandro Gomez
2023-07-13 13:42:20 +02:00
parent f5f2df5eba
commit 8211ab99f9
5 changed files with 231 additions and 167 deletions

View File

@ -12,6 +12,11 @@ import { findTag } from "utils";
import type { EmojiTag } from "../element/emoji";
import uniqBy from "lodash.uniqby";
export interface Emoji {
native?: string;
id?: string;
}
export interface EmojiPack {
address: string;
name: string;
@ -19,13 +24,19 @@ export interface EmojiPack {
emojis: EmojiTag[];
}
function cleanShortcode(shortcode?: string) {
return shortcode?.replace(/\s+/, "_");
}
function toEmojiPack(ev: NostrEvent): EmojiPack {
const d = findTag(ev, "d") || "";
return {
address: `${ev.kind}:${ev.pubkey}:${d}`,
name: d,
author: ev.pubkey,
emojis: ev.tags.filter((t) => t.at(0) === "emoji") as EmojiTag[],
emojis: ev.tags
.filter((t) => t.at(0) === "emoji")
.map((t) => ["emoji", cleanShortcode(t.at(1)), t.at(2)]) as EmojiTag[],
};
}