From 7d9d1ae7c26d97ba3aa4077f515d308e84a35a64 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 27 Jan 2023 11:28:51 +0900 Subject: [PATCH] enhance(client): tweak custom emoji cache --- packages/frontend/src/custom-emojis.ts | 15 ++++++++++----- packages/frontend/src/pages/settings/index.vue | 5 ++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/frontend/src/custom-emojis.ts b/packages/frontend/src/custom-emojis.ts index 0ba7cab5e2..9ce370e7e8 100644 --- a/packages/frontend/src/custom-emojis.ts +++ b/packages/frontend/src/custom-emojis.ts @@ -1,6 +1,6 @@ import { shallowRef, computed, markRaw } from 'vue'; import * as Misskey from 'misskey-js'; -import { apiGet } from './os'; +import { api, apiGet } from './os'; import { miLocalStorage } from './local-storage'; import { stream } from '@/stream'; @@ -28,12 +28,17 @@ stream.on('emojiDeleted', emojiData => { customEmojis.value = customEmojis.value.filter(item => !emojiData.emojis.some(search => search.name === item.name)); }); -export async function fetchCustomEmojis() { +export async function fetchCustomEmojis(force = false) { const now = Date.now(); - const lastFetchedAt = miLocalStorage.getItem('lastEmojisFetchedAt'); - if (lastFetchedAt && (now - parseInt(lastFetchedAt)) < 1000 * 60 * 60) return; - const res = await apiGet('emojis', {}); + let res; + if (force) { + res = await api('emojis', {}); + } else { + const lastFetchedAt = miLocalStorage.getItem('lastEmojisFetchedAt'); + if (lastFetchedAt && (now - parseInt(lastFetchedAt)) < 1000 * 60 * 60) return; + res = await apiGet('emojis', {}); + } customEmojis.value = res.emojis; miLocalStorage.setItem('emojis', JSON.stringify(res.emojis)); diff --git a/packages/frontend/src/pages/settings/index.vue b/packages/frontend/src/pages/settings/index.vue index e1e050ee70..4dbc6ec74c 100644 --- a/packages/frontend/src/pages/settings/index.vue +++ b/packages/frontend/src/pages/settings/index.vue @@ -34,6 +34,7 @@ import { useRouter } from '@/router'; import { definePageMetadata, provideMetadataReceiver, setPageMetadata } from '@/scripts/page-metadata'; import * as os from '@/os'; import { miLocalStorage } from '@/local-storage'; +import { fetchCustomEmojis } from '@/custom-emojis'; const indexInfo = { title: i18n.ts.settings, @@ -180,11 +181,13 @@ const menuDef = computed(() => [{ type: 'button', icon: 'ti ti-trash', text: i18n.ts.clearCache, - action: () => { + action: async () => { + os.waiting(); miLocalStorage.removeItem('locale'); miLocalStorage.removeItem('theme'); miLocalStorage.removeItem('emojis'); miLocalStorage.removeItem('lastEmojisFetchedAt'); + await fetchCustomEmojis(); unisonReload(); }, }, {