From db0bd21edcc4681dac033b7ec4184cb555940607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=81=E5=91=A8=E9=83=A8=E8=90=BD?= Date: Mon, 11 Mar 2024 08:33:47 +0800 Subject: [PATCH 1/7] feat(client): attachment without description opened when choose add alt --- packages/client/src/components/MkPostForm.vue | 81 ++++++++++++++++++- 1 file changed, 79 insertions(+), 2 deletions(-) diff --git a/packages/client/src/components/MkPostForm.vue b/packages/client/src/components/MkPostForm.vue index 3890908026..ad8c4c5ba3 100644 --- a/packages/client/src/components/MkPostForm.vue +++ b/packages/client/src/components/MkPostForm.vue @@ -500,6 +500,8 @@ const withHashtags = computed( ); const hashtags = computed(defaultStore.makeGetterSetter("postFormHashtags")); +let firstTryPost = true; + watch(text, () => { checkMissingMention(); }); @@ -1048,16 +1050,91 @@ async function post() { defaultStore.state.showNoAltTextWarning && files.value.some((f) => f.comment == null || f.comment.length === 0) ) { + if (firstTryPost) { + for (const file of files.value) { + if (file.comment == null || file.comment.length === 0) { + os.popup( + defineAsyncComponent( + () => import("@/components/MkMediaCaption.vue"), + ), + { + title: i18n.ts.describeFile, + input: { + placeholder: i18n.ts.inputNewDescription, + default: + file.comment !== null ? file.comment : "", + }, + image: file, + }, + { + done: (result) => { + if (!result || result.canceled) return; + const comment = + result.result.length === 0 + ? null + : result.result; + os.api("drive/files/update", { + fileId: file.id, + comment, + }).then(() => { + file.comment = comment; + }); + }, + }, + "closed", + ); + } + } + firstTryPost = false; + return; + } + // "canceled" means "post anyway" const { canceled } = await os.confirm({ type: "warning", text: i18n.ts.noAltTextWarning, - okText: i18n.ts.goBack, + okText: i18n.ts.describeFile, cancelText: i18n.ts.toPost, isPlaintext: true, }); - if (!canceled) return; + if (!canceled) { + for (const file of files.value) { + if (file.comment == null || file.comment.length === 0) { + os.popup( + defineAsyncComponent( + () => import("@/components/MkMediaCaption.vue"), + ), + { + title: i18n.ts.describeFile, + input: { + placeholder: i18n.ts.inputNewDescription, + default: + file.comment !== null ? file.comment : "", + }, + image: file, + }, + { + done: (result) => { + if (!result || result.canceled) return; + const comment = + result.result.length === 0 + ? null + : result.result; + os.api("drive/files/update", { + fileId: file.id, + comment, + }).then(() => { + file.comment = comment; + }); + }, + }, + "closed", + ); + } + } + return; + } } const processedText = preprocess(text.value); From 2267e90d3bfb9ac51ed6dcdaee051c39c594bd19 Mon Sep 17 00:00:00 2001 From: naskya Date: Mon, 25 Mar 2024 03:12:59 +0900 Subject: [PATCH 2/7] refactor (client): await asynchronous processes, remove duplicate code --- packages/client/src/components/MkPostForm.vue | 99 +++++++------------ 1 file changed, 35 insertions(+), 64 deletions(-) diff --git a/packages/client/src/components/MkPostForm.vue b/packages/client/src/components/MkPostForm.vue index ad8c4c5ba3..6478838f4e 100644 --- a/packages/client/src/components/MkPostForm.vue +++ b/packages/client/src/components/MkPostForm.vue @@ -309,6 +309,8 @@ import XNoteSimple from "@/components/MkNoteSimple.vue"; import XNotePreview from "@/components/MkNotePreview.vue"; import XPostFormAttaches from "@/components/MkPostFormAttaches.vue"; import XPollEditor from "@/components/MkPollEditor.vue"; +import XCheatSheet from "@/components/MkCheatSheetDialog.vue"; +import XMediaCaption from "@/components/MkMediaCaption.vue"; import { host, url } from "@/config"; import { erase, unique } from "@/scripts/array"; import { extractMentions } from "@/scripts/extract-mentions"; @@ -325,7 +327,6 @@ import { getAccounts, openAccountMenu as openAccountMenu_ } from "@/account"; import { me } from "@/me"; import { uploadFile } from "@/scripts/upload"; import { deepClone } from "@/scripts/clone"; -import XCheatSheet from "@/components/MkCheatSheetDialog.vue"; import preprocess from "@/scripts/preprocess"; import { vibrate } from "@/scripts/vibrate"; import { langmap } from "@/scripts/langmap"; @@ -500,7 +501,7 @@ const withHashtags = computed( ); const hashtags = computed(defaultStore.makeGetterSetter("postFormHashtags")); -let firstTryPost = true; +let isFirstPostAttempt = true; watch(text, () => { checkMissingMention(); @@ -1012,6 +1013,34 @@ function deleteDraft() { localStorage.setItem("drafts", JSON.stringify(draftData)); } +async function openFileDescriptionWindow(file: DriveFile) { + await os.popup( + XMediaCaption, + { + title: i18n.ts.describeFile, + input: { + placeholder: i18n.ts.inputNewDescription, + default: file.comment !== null ? file.comment : "", + }, + image: file, + }, + { + done: (result) => { + if (!result || result.canceled) return; + const comment = + result.result.length === 0 ? null : result.result; + os.api("drive/files/update", { + fileId: file.id, + comment, + }).then(() => { + file.comment = comment; + }); + }, + }, + "closed", + ); +} + async function post() { // For text that is too short, the false positive rate may be too high, so we don't show alarm. if (defaultStore.state.autocorrectNoteLanguage && text.value.length > 10) { @@ -1050,42 +1079,13 @@ async function post() { defaultStore.state.showNoAltTextWarning && files.value.some((f) => f.comment == null || f.comment.length === 0) ) { - if (firstTryPost) { + if (isFirstPostAttempt) { for (const file of files.value) { if (file.comment == null || file.comment.length === 0) { - os.popup( - defineAsyncComponent( - () => import("@/components/MkMediaCaption.vue"), - ), - { - title: i18n.ts.describeFile, - input: { - placeholder: i18n.ts.inputNewDescription, - default: - file.comment !== null ? file.comment : "", - }, - image: file, - }, - { - done: (result) => { - if (!result || result.canceled) return; - const comment = - result.result.length === 0 - ? null - : result.result; - os.api("drive/files/update", { - fileId: file.id, - comment, - }).then(() => { - file.comment = comment; - }); - }, - }, - "closed", - ); + await openFileDescriptionWindow(file); } } - firstTryPost = false; + isFirstPostAttempt = false; return; } @@ -1101,36 +1101,7 @@ async function post() { if (!canceled) { for (const file of files.value) { if (file.comment == null || file.comment.length === 0) { - os.popup( - defineAsyncComponent( - () => import("@/components/MkMediaCaption.vue"), - ), - { - title: i18n.ts.describeFile, - input: { - placeholder: i18n.ts.inputNewDescription, - default: - file.comment !== null ? file.comment : "", - }, - image: file, - }, - { - done: (result) => { - if (!result || result.canceled) return; - const comment = - result.result.length === 0 - ? null - : result.result; - os.api("drive/files/update", { - fileId: file.id, - comment, - }).then(() => { - file.comment = comment; - }); - }, - }, - "closed", - ); + await openFileDescriptionWindow(file); } } return; From f346d2e2f6b4674c9af03e761bf991b1c98f7d17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=81=E5=91=A8=E9=83=A8=E8=90=BD?= Date: Mon, 25 Mar 2024 22:52:37 +0800 Subject: [PATCH 3/7] feat: add showAddFileDescriptionAtFirstPost and allow cancel adding alt-text midway --- locales/en-US.yml | 2 + locales/zh-CN.yml | 1 + packages/client/src/components/MkPostForm.vue | 86 ++++++++++++------- .../client/src/pages/settings/general.vue | 6 ++ .../pages/settings/preferences-backups.vue | 1 + packages/client/src/store.ts | 4 + 6 files changed, 71 insertions(+), 29 deletions(-) diff --git a/locales/en-US.yml b/locales/en-US.yml index d736a7d881..116b8eabd0 100644 --- a/locales/en-US.yml +++ b/locales/en-US.yml @@ -1226,6 +1226,8 @@ publishTimelinesDescription: "If enabled, the Local and Global timelines will be on {url} even when signed out." noAltTextWarning: "Some attached file(s) have no description. Did you forget to write?" showNoAltTextWarning: "Show a warning if you attempt to post files without a description" +showAddFileDescriptionAtFirstPost: "Show add description page automatically when + first try to post a post attachment without a description" _emojiModPerm: unauthorized: "None" diff --git a/locales/zh-CN.yml b/locales/zh-CN.yml index f67bf4a600..8f5d009acc 100644 --- a/locales/zh-CN.yml +++ b/locales/zh-CN.yml @@ -2058,5 +2058,6 @@ searchRangeDescription: "如果您要过滤时间段,请按以下格式输入 messagingUnencryptedInfo: "Firefish 上的聊天没有经过端到端加密,请不要在聊天中分享您的敏感信息。" noAltTextWarning: 有些附件没有描述。您是否忘记写描述了? showNoAltTextWarning: 当您尝试发布没有描述的帖子附件时显示警告 +showAddFileDescriptionAtFirstPost: 当您首次尝试发布没有描述的帖子附件时自动弹出添加描述页面 autocorrectNoteLanguage: 当帖子语言不符合自动检测的结果的时候显示警告 incorrectLanguageWarning: "看上去您帖子使用的语言是{detected},但您选择的语言是{current}。\n要改为以{detected}发帖吗?" diff --git a/packages/client/src/components/MkPostForm.vue b/packages/client/src/components/MkPostForm.vue index 6478838f4e..fee812317e 100644 --- a/packages/client/src/components/MkPostForm.vue +++ b/packages/client/src/components/MkPostForm.vue @@ -1013,32 +1013,43 @@ function deleteDraft() { localStorage.setItem("drafts", JSON.stringify(draftData)); } -async function openFileDescriptionWindow(file: DriveFile) { - await os.popup( - XMediaCaption, - { - title: i18n.ts.describeFile, - input: { - placeholder: i18n.ts.inputNewDescription, - default: file.comment !== null ? file.comment : "", +/** + * @returns whether the file is described + */ + function openFileDescriptionWindow(file: entities.DriveFile) { + return new Promise((resolve, reject) => { + os.popup( + XMediaCaption, + { + title: i18n.ts.describeFile, + input: { + placeholder: i18n.ts.inputNewDescription, + default: file.comment !== null ? file.comment : "", + }, + image: file, }, - image: file, - }, - { - done: (result) => { - if (!result || result.canceled) return; - const comment = - result.result.length === 0 ? null : result.result; - os.api("drive/files/update", { - fileId: file.id, - comment, - }).then(() => { - file.comment = comment; - }); + { + done: (result) => { + if (!result || result.canceled) { + resolve(false); + return; + } + const comment = + result.result.length === 0 ? null : result.result; + os.api("drive/files/update", { + fileId: file.id, + comment, + }).then(() => { + resolve(true); + file.comment = comment; + }).catch((err: unknown) => { + reject(err); + }); + }, }, - }, - "closed", - ); + "closed", + ); + }) } async function post() { @@ -1076,19 +1087,30 @@ async function post() { } if ( - defaultStore.state.showNoAltTextWarning && + defaultStore.state.showAddFileDescriptionAtFirstPost && files.value.some((f) => f.comment == null || f.comment.length === 0) ) { if (isFirstPostAttempt) { for (const file of files.value) { if (file.comment == null || file.comment.length === 0) { - await openFileDescriptionWindow(file); + const described = await openFileDescriptionWindow(file); + if (!described) { + return; + } } } isFirstPostAttempt = false; - return; + // Continue if all files have alt-text added. + if (files.value.some((f) => f.comment == null || f.comment.length === 0)) { + return; + } } + } + if ( + defaultStore.state.showNoAltTextWarning && + files.value.some((f) => f.comment == null || f.comment.length === 0) + ) { // "canceled" means "post anyway" const { canceled } = await os.confirm({ type: "warning", @@ -1101,10 +1123,16 @@ async function post() { if (!canceled) { for (const file of files.value) { if (file.comment == null || file.comment.length === 0) { - await openFileDescriptionWindow(file); + const described = await openFileDescriptionWindow(file); + if (!described) { + return; + } } } - return; + // Continue if all files have alt-text added. + if (files.value.some((f) => f.comment == null || f.comment.length === 0)) { + return; + } } } diff --git a/packages/client/src/pages/settings/general.vue b/packages/client/src/pages/settings/general.vue index 15e1172169..bc21efc132 100644 --- a/packages/client/src/pages/settings/general.vue +++ b/packages/client/src/pages/settings/general.vue @@ -124,6 +124,9 @@ {{ i18n.ts.showNoAltTextWarning }} + {{ + i18n.ts.showAddFileDescriptionAtFirstPost + }} {{ i18n.ts.autocorrectNoteLanguage }} @@ -533,6 +536,9 @@ const pullToRefreshThreshold = computed( const showNoAltTextWarning = computed( defaultStore.makeGetterSetter("showNoAltTextWarning"), ); +const showAddFileDescriptionAtFirstPost = computed( + defaultStore.makeGetterSetter("showAddFileDescriptionAtFirstPost"), +); const autocorrectNoteLanguage = computed( defaultStore.makeGetterSetter("autocorrectNoteLanguage"), ); diff --git a/packages/client/src/pages/settings/preferences-backups.vue b/packages/client/src/pages/settings/preferences-backups.vue index 202de0a082..885fec70c1 100644 --- a/packages/client/src/pages/settings/preferences-backups.vue +++ b/packages/client/src/pages/settings/preferences-backups.vue @@ -125,6 +125,7 @@ const defaultStoreSaveKeys: (keyof (typeof defaultStore)["state"])[] = [ "enablePullToRefresh", "pullToRefreshThreshold", "showNoAltTextWarning", + "showAddFileDescriptionAtFirstPost", "autocorrectNoteLanguage", ]; const coldDeviceStorageSaveKeys: (keyof typeof ColdDeviceStorage.default)[] = [ diff --git a/packages/client/src/store.ts b/packages/client/src/store.ts index cf17917477..11abb2e30f 100644 --- a/packages/client/src/store.ts +++ b/packages/client/src/store.ts @@ -432,6 +432,10 @@ export const defaultStore = markRaw( where: "account", default: true, }, + showAddFileDescriptionAtFirstPost: { + where: "account", + default: false, + }, autocorrectNoteLanguage: { where: "account", default: true, From 46bf02cdd591df1bed64677ccb15e358aa6b921d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=81=E5=91=A8=E9=83=A8=E8=90=BD?= Date: Sun, 31 Mar 2024 06:44:00 +0800 Subject: [PATCH 4/7] chore: format --- packages/client/src/components/MkPostForm.vue | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/packages/client/src/components/MkPostForm.vue b/packages/client/src/components/MkPostForm.vue index fee812317e..ffeb1a1cc5 100644 --- a/packages/client/src/components/MkPostForm.vue +++ b/packages/client/src/components/MkPostForm.vue @@ -1016,7 +1016,7 @@ function deleteDraft() { /** * @returns whether the file is described */ - function openFileDescriptionWindow(file: entities.DriveFile) { +function openFileDescriptionWindow(file: entities.DriveFile) { return new Promise((resolve, reject) => { os.popup( XMediaCaption, @@ -1034,22 +1034,23 @@ function deleteDraft() { resolve(false); return; } - const comment = - result.result.length === 0 ? null : result.result; - os.api("drive/files/update", { + const comment = result.result.length === 0 ? null : result.result; + os.api("drive/files/update", { fileId: file.id, comment, - }).then(() => { - resolve(true); - file.comment = comment; - }).catch((err: unknown) => { - reject(err); - }); + }) + .then(() => { + resolve(true); + file.comment = comment; + }) + .catch((err: unknown) => { + reject(err); + }); }, }, "closed", ); - }) + }); } async function post() { @@ -1101,7 +1102,9 @@ async function post() { } isFirstPostAttempt = false; // Continue if all files have alt-text added. - if (files.value.some((f) => f.comment == null || f.comment.length === 0)) { + if ( + files.value.some((f) => f.comment == null || f.comment.length === 0) + ) { return; } } @@ -1130,7 +1133,9 @@ async function post() { } } // Continue if all files have alt-text added. - if (files.value.some((f) => f.comment == null || f.comment.length === 0)) { + if ( + files.value.some((f) => f.comment == null || f.comment.length === 0) + ) { return; } } From fbdc0681151e8eee959b3d50b842a19ee857683c Mon Sep 17 00:00:00 2001 From: naskya Date: Mon, 22 Apr 2024 07:09:54 +0900 Subject: [PATCH 5/7] locale: update en-US.yml --- locales/en-US.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/locales/en-US.yml b/locales/en-US.yml index 5d0e8ae2f8..a70eb2406f 100644 --- a/locales/en-US.yml +++ b/locales/en-US.yml @@ -1227,8 +1227,8 @@ publishTimelinesDescription: "If enabled, the Local and Global timelines will be on {url} even when signed out." noAltTextWarning: "Some attached file(s) have no description. Did you forget to write?" showNoAltTextWarning: "Show a warning if you attempt to post files without a description" -showAddFileDescriptionAtFirstPost: "Show add description page automatically when - first try to post a post attachment without a description" +showAddFileDescriptionAtFirstPost: "Automatically open a form to write a description when you + attempt to post files without a description" _emojiModPerm: unauthorized: "None" From 9a4988eaad2b305295308462f9424beb1579b72f Mon Sep 17 00:00:00 2001 From: naskya Date: Mon, 22 Apr 2024 07:14:56 +0900 Subject: [PATCH 6/7] chore (client): fix type errors --- packages/client/src/components/MkPostForm.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/client/src/components/MkPostForm.vue b/packages/client/src/components/MkPostForm.vue index 2d36408d9d..e7ec45a37b 100644 --- a/packages/client/src/components/MkPostForm.vue +++ b/packages/client/src/components/MkPostForm.vue @@ -1046,14 +1046,14 @@ function openFileDescriptionWindow(file: entities.DriveFile) { resolve(false); return; } - const comment = result.result.length === 0 ? null : result.result; + const comment = result.result?.length === 0 ? null : result.result; os.api("drive/files/update", { fileId: file.id, comment, }) .then(() => { resolve(true); - file.comment = comment; + file.comment = comment ?? null; }) .catch((err: unknown) => { reject(err); From 9ced0d96adca51b68dc574b396d9bd659cc391c1 Mon Sep 17 00:00:00 2001 From: naskya Date: Mon, 22 Apr 2024 07:20:07 +0900 Subject: [PATCH 7/7] chore (client): don't make a new post as soon as you add descriptions --- packages/client/src/components/MkPostForm.vue | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/packages/client/src/components/MkPostForm.vue b/packages/client/src/components/MkPostForm.vue index e7ec45a37b..5850fdf498 100644 --- a/packages/client/src/components/MkPostForm.vue +++ b/packages/client/src/components/MkPostForm.vue @@ -1113,12 +1113,7 @@ async function post() { } } isFirstPostAttempt = false; - // Continue if all files have alt-text added. - if ( - files.value.some((f) => f.comment == null || f.comment.length === 0) - ) { - return; - } + return; } } @@ -1144,12 +1139,7 @@ async function post() { } } } - // Continue if all files have alt-text added. - if ( - files.value.some((f) => f.comment == null || f.comment.length === 0) - ) { - return; - } + return; } }