Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

何らかの理由によりクライアントの絵文字キャッシュが削除された場合ただちに再取得するように修正 #163

Merged
merged 3 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/frontend/src/custom-emojis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { shallowRef, computed, markRaw, watch } from 'vue';
import * as Misskey from 'misskey-js';
import { api, apiGet } from './os';
import { useStream } from '@/stream';
import { get, set } from '@/scripts/idb-proxy';
import { get, set, exist } from '@/scripts/idb-proxy';

const storageCache = await get('emojis');
export const customEmojis = shallowRef<Misskey.entities.CustomEmoji[]>(Array.isArray(storageCache) ? storageCache : []);
Expand Down Expand Up @@ -50,12 +50,13 @@ stream.on('emojiDeleted', emojiData => {
export async function fetchCustomEmojis(force = false) {
const now = Date.now();

const emojiCacheExist = await exist('emojis');
CyberRex0 marked this conversation as resolved.
Show resolved Hide resolved
let res;
if (force) {
res = await api('emojis', {});
} else {
const lastFetchedAt = await get('lastEmojisFetchedAt');
if (lastFetchedAt && (now - lastFetchedAt) < 1000 * 60 * 60) return;
if (lastFetchedAt && (now - lastFetchedAt) < 1000 * 60 * 60 && emojiCacheExist) return;
riku6460 marked this conversation as resolved.
Show resolved Hide resolved
res = await apiGet('emojis', {});
}

Expand Down
13 changes: 13 additions & 0 deletions packages/frontend/src/scripts/idb-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
get as iget,
set as iset,
del as idel,
keys as ikeys,
} from 'idb-keyval';

const fallbackName = (key: string) => `idbfallback::${key}`;
Expand Down Expand Up @@ -40,3 +41,15 @@ export async function del(key: string) {
if (idbAvailable) return idel(key);
return window.localStorage.removeItem(fallbackName(key));
}

export async function exist(key: string) {
if (idbAvailable) {
const keys = await ikeys();
return (keys.indexOf(key) !== -1);
CyberRex0 marked this conversation as resolved.
Show resolved Hide resolved
}
const targetKey = fallbackName(key);
for (let index = 0, len = window.localStorage.length; index < len; index++) {
CyberRex0 marked this conversation as resolved.
Show resolved Hide resolved
if (window.localStorage.key(index) === targetKey) return true;
}
return false;
}
riku6460 marked this conversation as resolved.
Show resolved Hide resolved