From 2ee931e0c63d445f9aae2a57f12ee8f47f4bb408 Mon Sep 17 00:00:00 2001 From: futchitwo <74236683+futchitwo@users.noreply.github.com> Date: Sat, 18 Jun 2022 18:27:09 +0900 Subject: [PATCH] Improve: unclip (#8823) * Refactor clip page to use Composition API * Refactor clip page * Refactor clip page * Refactor clip page * Improve: unclip * Fix unclip * Fix unclip * chore: better type and name * Fix * Fix clipPage vue provider Co-authored-by: syuilo --- locales/ja-JP.yml | 2 + packages/backend/src/server/api/endpoints.ts | 2 + .../server/api/endpoints/clips/remove-note.ts | 57 +++++++++++++++++++ .../client/src/components/note-detailed.vue | 4 +- packages/client/src/components/note.vue | 8 ++- packages/client/src/pages/clip.vue | 4 +- packages/client/src/scripts/get-note-menu.ts | 42 +++++++++++++- 7 files changed, 110 insertions(+), 9 deletions(-) create mode 100644 packages/backend/src/server/api/endpoints/clips/remove-note.ts diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index c17e6959b..082b8a24b 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -643,6 +643,8 @@ clip: "クリップ" createNew: "新規作成" optional: "任意" createNewClip: "新しいクリップを作成" +unclip: "クリップ解除" +confirmToUnclipAlreadyClippedNote: "このノートはすでにクリップ「{name}」に含まれています。ノートをこのクリップから除外しますか?" public: "パブリック" i18nInfo: "Misskeyは有志によって様々な言語に翻訳されています。{link}で翻訳に協力できます。" manageAccessTokens: "アクセストークンの管理" diff --git a/packages/backend/src/server/api/endpoints.ts b/packages/backend/src/server/api/endpoints.ts index 1e7afd8cd..5fac7df23 100644 --- a/packages/backend/src/server/api/endpoints.ts +++ b/packages/backend/src/server/api/endpoints.ts @@ -99,6 +99,7 @@ import * as ep___charts_user_notes from './endpoints/charts/user/notes.js'; import * as ep___charts_user_reactions from './endpoints/charts/user/reactions.js'; import * as ep___charts_users from './endpoints/charts/users.js'; import * as ep___clips_addNote from './endpoints/clips/add-note.js'; +import * as ep___clips_removeNote from './endpoints/clips/remove-note.js'; import * as ep___clips_create from './endpoints/clips/create.js'; import * as ep___clips_delete from './endpoints/clips/delete.js'; import * as ep___clips_list from './endpoints/clips/list.js'; @@ -409,6 +410,7 @@ const eps = [ ['charts/user/reactions', ep___charts_user_reactions], ['charts/users', ep___charts_users], ['clips/add-note', ep___clips_addNote], + ['clips/remove-note', ep___clips_removeNote], ['clips/create', ep___clips_create], ['clips/delete', ep___clips_delete], ['clips/list', ep___clips_list], diff --git a/packages/backend/src/server/api/endpoints/clips/remove-note.ts b/packages/backend/src/server/api/endpoints/clips/remove-note.ts new file mode 100644 index 000000000..8b90e31f6 --- /dev/null +++ b/packages/backend/src/server/api/endpoints/clips/remove-note.ts @@ -0,0 +1,57 @@ +import define from '../../define.js'; +import { ClipNotes, Clips } from '@/models/index.js'; +import { ApiError } from '../../error.js'; +import { getNote } from '../../common/getters.js'; + +export const meta = { + tags: ['account', 'notes', 'clips'], + + requireCredential: true, + + kind: 'write:account', + + errors: { + noSuchClip: { + message: 'No such clip.', + code: 'NO_SUCH_CLIP', + id: 'b80525c6-97f7-49d7-a42d-ebccd49cfd52', + }, + + noSuchNote: { + message: 'No such note.', + code: 'NO_SUCH_NOTE', + id: 'aff017de-190e-434b-893e-33a9ff5049d8', + }, + }, +} as const; + +export const paramDef = { + type: 'object', + properties: { + clipId: { type: 'string', format: 'misskey:id' }, + noteId: { type: 'string', format: 'misskey:id' }, + }, + required: ['clipId', 'noteId'], +} as const; + +// eslint-disable-next-line import/no-default-export +export default define(meta, paramDef, async (ps, user) => { + const clip = await Clips.findOneBy({ + id: ps.clipId, + userId: user.id, + }); + + if (clip == null) { + throw new ApiError(meta.errors.noSuchClip); + } + + const note = await getNote(ps.noteId).catch(e => { + if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote); + throw e; + }); + + await ClipNotes.delete({ + noteId: note.id, + clipId: clip.id, + }); +}); diff --git a/packages/client/src/components/note-detailed.vue b/packages/client/src/components/note-detailed.vue index 6234b710d..ba47bfcd4 100644 --- a/packages/client/src/components/note-detailed.vue +++ b/packages/client/src/components/note-detailed.vue @@ -251,12 +251,12 @@ function onContextmenu(ev: MouseEvent): void { ev.preventDefault(); react(); } else { - os.contextMenu(getNoteMenu({ note: note, translating, translation, menuButton }), ev).then(focus); + os.contextMenu(getNoteMenu({ note: note, translating, translation, menuButton, isDeleted }), ev).then(focus); } } function menu(viaKeyboard = false): void { - os.popupMenu(getNoteMenu({ note: note, translating, translation, menuButton }), menuButton.value, { + os.popupMenu(getNoteMenu({ note: note, translating, translation, menuButton, isDeleted }), menuButton.value, { viaKeyboard, }).then(focus); } diff --git a/packages/client/src/components/note.vue b/packages/client/src/components/note.vue index e5744d1ce..b06f4edd0 100644 --- a/packages/client/src/components/note.vue +++ b/packages/client/src/components/note.vue @@ -105,7 +105,7 @@