summaryrefslogtreecommitdiff
path: root/packages/frontend/src/scripts/get-note-menu.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2023-09-24 18:21:31 +0900
committerGitHub <noreply@github.com>2023-09-24 18:21:31 +0900
commitf32915b515f4cbc3b1a877cfb8e8e35bf6a31efa (patch)
tree0f6f098cbb282e4b6619152b14b9e6f57e6b448f /packages/frontend/src/scripts/get-note-menu.ts
parentMerge pull request #11384 from misskey-dev/develop (diff)
parent2023.9.0 (diff)
downloadmisskey-f32915b515f4cbc3b1a877cfb8e8e35bf6a31efa.tar.gz
misskey-f32915b515f4cbc3b1a877cfb8e8e35bf6a31efa.tar.bz2
misskey-f32915b515f4cbc3b1a877cfb8e8e35bf6a31efa.zip
Merge pull request #11874 from misskey-dev/develop
Release: 2023.9.0
Diffstat (limited to 'packages/frontend/src/scripts/get-note-menu.ts')
-rw-r--r--packages/frontend/src/scripts/get-note-menu.ts146
1 files changed, 78 insertions, 68 deletions
diff --git a/packages/frontend/src/scripts/get-note-menu.ts b/packages/frontend/src/scripts/get-note-menu.ts
index 960f26ca67..734a632039 100644
--- a/packages/frontend/src/scripts/get-note-menu.ts
+++ b/packages/frontend/src/scripts/get-note-menu.ts
@@ -1,21 +1,27 @@
+/*
+ * SPDX-FileCopyrightText: syuilo and other misskey contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
import { defineAsyncComponent, Ref } from 'vue';
-import * as misskey from 'misskey-js';
-import { claimAchievement } from './achievements';
-import { $i } from '@/account';
-import { i18n } from '@/i18n';
-import { instance } from '@/instance';
-import * as os from '@/os';
-import copyToClipboard from '@/scripts/copy-to-clipboard';
-import { url } from '@/config';
-import { defaultStore, noteActions } from '@/store';
-import { miLocalStorage } from '@/local-storage';
-import { getUserMenu } from '@/scripts/get-user-menu';
-import { clipsCache } from '@/cache';
+import * as Misskey from 'misskey-js';
+import { claimAchievement } from './achievements.js';
+import { $i } from '@/account.js';
+import { i18n } from '@/i18n.js';
+import { instance } from '@/instance.js';
+import * as os from '@/os.js';
+import copyToClipboard from '@/scripts/copy-to-clipboard.js';
+import { url } from '@/config.js';
+import { defaultStore, noteActions } from '@/store.js';
+import { miLocalStorage } from '@/local-storage.js';
+import { getUserMenu } from '@/scripts/get-user-menu.js';
+import { clipsCache } from '@/cache.js';
+import { MenuItem } from '@/types/menu.js';
export async function getNoteClipMenu(props: {
- note: misskey.entities.Note;
+ note: Misskey.entities.Note;
isDeleted: Ref<boolean>;
- currentClip?: misskey.entities.Clip;
+ currentClip?: Misskey.entities.Clip;
}) {
const isRenote = (
props.note.renote != null &&
@@ -24,9 +30,9 @@ export async function getNoteClipMenu(props: {
props.note.poll == null
);
- const appearNote = isRenote ? props.note.renote as misskey.entities.Note : props.note;
+ const appearNote = isRenote ? props.note.renote as Misskey.entities.Note : props.note;
- const clips = await clipsCache.fetch(() => os.api('clips/list'));
+ const clips = await clipsCache.fetch();
return [...clips.map(clip => ({
text: clip.name,
action: () => {
@@ -86,13 +92,38 @@ export async function getNoteClipMenu(props: {
}];
}
+export function getAbuseNoteMenu(note: misskey.entities.Note, text: string): MenuItem {
+ return {
+ icon: 'ti ti-exclamation-circle',
+ text,
+ action: (): void => {
+ const u = note.url ?? note.uri ?? `${url}/notes/${note.id}`;
+ os.popup(defineAsyncComponent(() => import('@/components/MkAbuseReportWindow.vue')), {
+ user: note.user,
+ initialComment: `Note: ${u}\n-----\n`,
+ }, {}, 'closed');
+ },
+ };
+}
+
+export function getCopyNoteLinkMenu(note: misskey.entities.Note, text: string): MenuItem {
+ return {
+ icon: 'ti ti-link',
+ text,
+ action: (): void => {
+ copyToClipboard(`${url}/notes/${note.id}`);
+ os.success();
+ },
+ };
+}
+
export function getNoteMenu(props: {
- note: misskey.entities.Note;
+ note: Misskey.entities.Note;
menuButton: Ref<HTMLElement>;
translation: Ref<any>;
translating: Ref<boolean>;
isDeleted: Ref<boolean>;
- currentClip?: misskey.entities.Clip;
+ currentClip?: Misskey.entities.Clip;
}) {
const isRenote = (
props.note.renote != null &&
@@ -101,7 +132,9 @@ export function getNoteMenu(props: {
props.note.poll == null
);
- const appearNote = isRenote ? props.note.renote as misskey.entities.Note : props.note;
+ const appearNote = isRenote ? props.note.renote as Misskey.entities.Note : props.note;
+
+ const cleanups = [] as (() => void)[];
function del(): void {
os.confirm({
@@ -205,18 +238,6 @@ export function getNoteMenu(props: {
os.pageWindow(`/notes/${appearNote.id}`);
}
- function showReactions(): void {
- os.popup(defineAsyncComponent(() => import('@/components/MkReactedUsersDialog.vue')), {
- noteId: appearNote.id,
- }, {}, 'closed');
- }
-
- function showRenotes(): void {
- os.popup(defineAsyncComponent(() => import('@/components/MkRenotedUsersDialog.vue')), {
- noteId: appearNote.id,
- }, {}, 'closed');
- }
-
async function translate(): Promise<void> {
if (props.translation.value != null) return;
props.translating.value = true;
@@ -228,7 +249,7 @@ export function getNoteMenu(props: {
props.translation.value = res;
}
- let menu;
+ let menu: MenuItem[];
if ($i) {
const statePromise = os.api('notes/state', {
noteId: appearNote.id,
@@ -247,22 +268,11 @@ export function getNoteMenu(props: {
text: i18n.ts.details,
action: openDetail,
}, {
- icon: 'ti ti-repeat',
- text: i18n.ts.renotesList,
- action: showRenotes,
- }, {
- icon: 'ti ti-icons',
- text: i18n.ts.reactionsList,
- action: showReactions,
- }, {
icon: 'ti ti-copy',
text: i18n.ts.copyContent,
action: copyContent,
- }, {
- icon: 'ti ti-link',
- text: i18n.ts.copyLink,
- action: copyLink,
- }, (appearNote.url || appearNote.uri) ? {
+ }, getCopyNoteLinkMenu(appearNote, i18n.ts.copyLink)
+ , (appearNote.url || appearNote.uri) ? {
icon: 'ti ti-external-link',
text: i18n.ts.showOnRemote,
action: () => {
@@ -290,7 +300,7 @@ export function getNoteMenu(props: {
action: () => toggleFavorite(true),
}),
{
- type: 'parent',
+ type: 'parent' as const,
icon: 'ti ti-paperclip',
text: i18n.ts.clip,
children: () => getNoteClipMenu(props),
@@ -313,15 +323,17 @@ export function getNoteMenu(props: {
text: i18n.ts.pin,
action: () => togglePin(true),
} : undefined,
- appearNote.userId !== $i.id ? {
- type: 'parent',
+ {
+ type: 'parent' as const,
icon: 'ti ti-user',
text: i18n.ts.user,
children: async () => {
- const user = await os.api('users/show', { userId: appearNote.userId });
- return getUserMenu(user);
+ const user = appearNote.userId === $i?.id ? $i : await os.api('users/show', { userId: appearNote.userId });
+ const { menu, cleanup } = getUserMenu(user);
+ cleanups.push(cleanup);
+ return menu;
},
- } : undefined,
+ },
/*
...($i.isModerator || $i.isAdmin ? [
null,
@@ -334,17 +346,8 @@ export function getNoteMenu(props: {
),*/
...(appearNote.userId !== $i.id ? [
null,
- {
- icon: 'ti ti-exclamation-circle',
- text: i18n.ts.reportAbuse,
- action: () => {
- const u = appearNote.url ?? appearNote.uri ?? `${url}/notes/${appearNote.id}`;
- os.popup(defineAsyncComponent(() => import('@/components/MkAbuseReportWindow.vue')), {
- user: appearNote.user,
- initialComment: `Note: ${u}\n-----\n`,
- }, {}, 'closed');
- },
- }]
+ appearNote.userId !== $i.id ? getAbuseNoteMenu(appearNote, i18n.ts.reportAbuse) : undefined,
+ ]
: []
),
...(appearNote.userId === $i.id || $i.isModerator || $i.isAdmin ? [
@@ -372,11 +375,8 @@ export function getNoteMenu(props: {
icon: 'ti ti-copy',
text: i18n.ts.copyContent,
action: copyContent,
- }, {
- icon: 'ti ti-link',
- text: i18n.ts.copyLink,
- action: copyLink,
- }, (appearNote.url || appearNote.uri) ? {
+ }, getCopyNoteLinkMenu(appearNote, i18n.ts.copyLink)
+ , (appearNote.url || appearNote.uri) ? {
icon: 'ti ti-external-link',
text: i18n.ts.showOnRemote,
action: () => {
@@ -406,5 +406,15 @@ export function getNoteMenu(props: {
}]);
}
- return menu;
+ const cleanup = () => {
+ if (_DEV_) console.log('note menu cleanup', cleanups);
+ for (const cl of cleanups) {
+ cl();
+ }
+ };
+
+ return {
+ menu,
+ cleanup,
+ };
}