2024-05-29 02:59:49 +02:00
|
|
|
import { emojiValidatorWithColons } from "@/api";
|
2024-06-13 06:52:01 +02:00
|
|
|
import { type InferSelectModel, inArray } from "drizzle-orm";
|
|
|
|
|
import { Emojis, type Instances } from "~/drizzle/schema";
|
|
|
|
|
import { Emoji } from "~/packages/database-interface/emoji";
|
2023-09-12 22:48:10 +02:00
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export type EmojiWithInstance = InferSelectModel<typeof Emojis> & {
|
|
|
|
|
instance: InferSelectModel<typeof Instances> | null;
|
2024-04-11 13:39:07 +02:00
|
|
|
};
|
2023-09-12 22:48:10 +02:00
|
|
|
|
2023-11-11 03:36:06 +01:00
|
|
|
/**
|
|
|
|
|
* Used for parsing emojis from local text
|
|
|
|
|
* @param text The text to parse
|
|
|
|
|
* @returns An array of emojis
|
|
|
|
|
*/
|
2024-06-13 06:52:01 +02:00
|
|
|
export const parseEmojis = async (text: string): Promise<Emoji[]> => {
|
2024-05-13 03:07:55 +02:00
|
|
|
const matches = text.match(emojiValidatorWithColons);
|
2024-06-13 06:52:01 +02:00
|
|
|
if (!matches || matches.length === 0) {
|
2024-06-13 04:26:43 +02:00
|
|
|
return [];
|
|
|
|
|
}
|
2024-04-11 13:39:07 +02:00
|
|
|
|
2024-06-13 06:52:01 +02:00
|
|
|
return Emoji.manyFromSql(
|
|
|
|
|
inArray(
|
|
|
|
|
Emojis.shortcode,
|
|
|
|
|
matches.map((match) => match.replace(/:/g, "")),
|
|
|
|
|
),
|
|
|
|
|
);
|
2024-03-04 01:45:21 +01:00
|
|
|
};
|