summaryrefslogtreecommitdiff
path: root/packages/frontend/src/custom-emojis.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2023-01-09 15:50:25 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2023-01-09 15:50:25 +0900
commit462acc9eee3f89a926fd4b46ffed0b066519759b (patch)
tree3e8df5e6f490966c078fce12fd2d89f1385f58c0 /packages/frontend/src/custom-emojis.ts
parentfix(server): アンテナタイムライン(ストリーミング)が、... (diff)
downloadmisskey-462acc9eee3f89a926fd4b46ffed0b066519759b.tar.gz
misskey-462acc9eee3f89a926fd4b46ffed0b066519759b.tar.bz2
misskey-462acc9eee3f89a926fd4b46ffed0b066519759b.zip
カスタム絵文字一覧情報をmetaから分離
Diffstat (limited to 'packages/frontend/src/custom-emojis.ts')
-rw-r--r--packages/frontend/src/custom-emojis.ts48
1 files changed, 48 insertions, 0 deletions
diff --git a/packages/frontend/src/custom-emojis.ts b/packages/frontend/src/custom-emojis.ts
new file mode 100644
index 0000000000..2a52753f84
--- /dev/null
+++ b/packages/frontend/src/custom-emojis.ts
@@ -0,0 +1,48 @@
+import { api } from './os';
+import { miLocalStorage } from './local-storage';
+
+const storageCache = miLocalStorage.getItem('emojis');
+let cached = storageCache ? JSON.parse(storageCache) : null;
+export async function getCustomEmojis() {
+ const now = Date.now();
+ const lastFetchedAt = miLocalStorage.getItem('lastEmojisFetchedAt');
+ if (cached && lastFetchedAt && (now - parseInt(lastFetchedAt)) < 1000 * 60 * 60) return cached;
+
+ const res = await api('emojis', {});
+
+ cached = res.emojis;
+ miLocalStorage.setItem('emojis', JSON.stringify(cached));
+ miLocalStorage.setItem('lastEmojisFetchedAt', now.toString());
+}
+
+let cachedCategories;
+export async function getCustomEmojiCategories() {
+ if (cachedCategories) return cachedCategories;
+
+ const customEmojis = await getCustomEmojis();
+
+ const categories = new Set();
+ for (const emoji of customEmojis) {
+ categories.add(emoji.category);
+ }
+ const res = Array.from(categories);
+ cachedCategories = res;
+ return res;
+}
+
+let cachedTags;
+export async function getCustomEmojiTags() {
+ if (cachedTags) return cachedTags;
+
+ const customEmojis = await getCustomEmojis();
+
+ const tags = new Set();
+ for (const emoji of customEmojis) {
+ for (const tag of emoji.aliases) {
+ tags.add(tag);
+ }
+ }
+ const res = Array.from(tags);
+ cachedTags = res;
+ return res;
+}