summaryrefslogtreecommitdiff
path: root/packages/frontend/src/scripts
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2024-04-25 11:31:35 +0100
committerdakkar <dakkar@thenautilus.net>2024-04-25 11:44:24 +0100
commit4fe8a260817d30385cddecad91a4e84c15889666 (patch)
tree70ef7d0215767befa923b41b53cff67a5130eda2 /packages/frontend/src/scripts
parentMerge branch 'develop' into future-2024-04-10-post (diff)
parentfeat: improve emoji endpoint (#13742) (diff)
downloadsharkey-4fe8a260817d30385cddecad91a4e84c15889666.tar.gz
sharkey-4fe8a260817d30385cddecad91a4e84c15889666.tar.bz2
sharkey-4fe8a260817d30385cddecad91a4e84c15889666.zip
Merge remote-tracking branch 'misskey/develop' into future-2024-04-25
Diffstat (limited to 'packages/frontend/src/scripts')
-rw-r--r--packages/frontend/src/scripts/get-note-menu.ts36
-rw-r--r--packages/frontend/src/scripts/idb-proxy.ts10
-rw-r--r--packages/frontend/src/scripts/upload.ts10
3 files changed, 50 insertions, 6 deletions
diff --git a/packages/frontend/src/scripts/get-note-menu.ts b/packages/frontend/src/scripts/get-note-menu.ts
index 40359a88bb..bbe1a52f8f 100644
--- a/packages/frontend/src/scripts/get-note-menu.ts
+++ b/packages/frontend/src/scripts/get-note-menu.ts
@@ -26,6 +26,14 @@ export async function getNoteClipMenu(props: {
isDeleted: Ref<boolean>;
currentClip?: Misskey.entities.Clip;
}) {
+ function getClipName(clip: Misskey.entities.Clip) {
+ if ($i && clip.userId === $i.id && clip.notesCount != null) {
+ return `${clip.name} (${clip.notesCount}/${$i.policies.noteEachClipsLimit})`;
+ } else {
+ return clip.name;
+ }
+ }
+
const isRenote = (
props.note.renote != null &&
props.note.text == null &&
@@ -37,7 +45,7 @@ export async function getNoteClipMenu(props: {
const clips = await clipsCache.fetch();
const menu: MenuItem[] = [...clips.map(clip => ({
- text: clip.name,
+ text: getClipName(clip),
action: () => {
claimAchievement('noteClipped1');
os.promiseDialog(
@@ -50,7 +58,18 @@ export async function getNoteClipMenu(props: {
text: i18n.tsx.confirmToUnclipAlreadyClippedNote({ name: clip.name }),
});
if (!confirm.canceled) {
- os.apiWithDialog('clips/remove-note', { clipId: clip.id, noteId: appearNote.id });
+ os.apiWithDialog('clips/remove-note', { clipId: clip.id, noteId: appearNote.id }).then(() => {
+ clipsCache.set(clips.map(c => {
+ if (c.id === clip.id) {
+ return {
+ ...c,
+ notesCount: Math.max(0, ((c.notesCount ?? 0) - 1)),
+ };
+ } else {
+ return c;
+ }
+ }));
+ });
if (props.currentClip?.id === clip.id) props.isDeleted.value = true;
}
} else {
@@ -60,7 +79,18 @@ export async function getNoteClipMenu(props: {
});
}
},
- );
+ ).then(() => {
+ clipsCache.set(clips.map(c => {
+ if (c.id === clip.id) {
+ return {
+ ...c,
+ notesCount: (c.notesCount ?? 0) + 1,
+ };
+ } else {
+ return c;
+ }
+ }));
+ });
},
})), { type: 'divider' }, {
icon: 'ph-plus ph-bold ph-lg',
diff --git a/packages/frontend/src/scripts/idb-proxy.ts b/packages/frontend/src/scripts/idb-proxy.ts
index 1ca0990ba9..6b511f2a5f 100644
--- a/packages/frontend/src/scripts/idb-proxy.ts
+++ b/packages/frontend/src/scripts/idb-proxy.ts
@@ -15,6 +15,16 @@ const fallbackName = (key: string) => `idbfallback::${key}`;
let idbAvailable = typeof window !== 'undefined' ? !!(window.indexedDB && window.indexedDB.open) : true;
+// iframe.contentWindow.indexedDB.deleteDatabase() がchromeのバグで使用できないため、indexedDBを無効化している。
+// バグが治って再度有効化するのであれば、cypressのコマンド内のコメントアウトを外すこと
+// see https://github.com/misskey-dev/misskey/issues/13605#issuecomment-2053652123
+// eslint-disable-next-line @typescript-eslint/ban-ts-comment
+// @ts-expect-error
+if (window.Cypress) {
+ idbAvailable = false;
+ console.log('Cypress detected. It will use localStorage.');
+}
+
if (idbAvailable) {
await iset('idb-test', 'test')
.catch(err => {
diff --git a/packages/frontend/src/scripts/upload.ts b/packages/frontend/src/scripts/upload.ts
index 6c46b2bc1b..3e947183c9 100644
--- a/packages/frontend/src/scripts/upload.ts
+++ b/packages/frontend/src/scripts/upload.ts
@@ -5,6 +5,7 @@
import { reactive, ref } from 'vue';
import * as Misskey from 'misskey-js';
+import { v4 as uuid } from 'uuid';
import { readAndCompressImage } from '@misskey-dev/browser-image-resizer';
import { getCompressionConfig } from './upload/compress-config.js';
import { defaultStore } from '@/store.js';
@@ -39,13 +40,16 @@ export function uploadFile(
if (folder && typeof folder === 'object') folder = folder.id;
return new Promise((resolve, reject) => {
- const id = Math.random().toString();
+ const id = uuid();
const reader = new FileReader();
reader.onload = async (): Promise<void> => {
+ const filename = name ?? file.name ?? 'untitled';
+ const extension = filename.split('.').length > 1 ? '.' + filename.split('.').pop() : '';
+
const ctx = reactive<Uploading>({
- id: id,
- name: name ?? file.name ?? 'untitled',
+ id,
+ name: defaultStore.state.keepOriginalFilename ? filename : id + extension,
progressMax: undefined,
progressValue: undefined,
img: window.URL.createObjectURL(file),