summaryrefslogtreecommitdiff
path: root/packages/client/src/scripts/get-note-menu.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/client/src/scripts/get-note-menu.ts')
-rw-r--r--packages/client/src/scripts/get-note-menu.ts270
1 files changed, 153 insertions, 117 deletions
diff --git a/packages/client/src/scripts/get-note-menu.ts b/packages/client/src/scripts/get-note-menu.ts
index 78749ad6bb..632143f514 100644
--- a/packages/client/src/scripts/get-note-menu.ts
+++ b/packages/client/src/scripts/get-note-menu.ts
@@ -1,5 +1,6 @@
-import { defineAsyncComponent, Ref } from 'vue';
+import { defineAsyncComponent, Ref, inject } from 'vue';
import * as misskey from 'misskey-js';
+import { pleaseLogin } from './please-login';
import { $i } from '@/account';
import { i18n } from '@/i18n';
import { instance } from '@/instance';
@@ -7,13 +8,14 @@ import * as os from '@/os';
import copyToClipboard from '@/scripts/copy-to-clipboard';
import { url } from '@/config';
import { noteActions } from '@/store';
-import { pleaseLogin } from './please-login';
export function getNoteMenu(props: {
note: misskey.entities.Note;
menuButton: Ref<HTMLElement>;
translation: Ref<any>;
translating: Ref<boolean>;
+ isDeleted: Ref<boolean>;
+ currentClipPage?: Ref<misskey.entities.Clip>;
}) {
const isRenote = (
props.note.renote != null &&
@@ -32,7 +34,7 @@ export function getNoteMenu(props: {
if (canceled) return;
os.api('notes/delete', {
- noteId: appearNote.id
+ noteId: appearNote.id,
});
});
}
@@ -45,7 +47,7 @@ export function getNoteMenu(props: {
if (canceled) return;
os.api('notes/delete', {
- noteId: appearNote.id
+ noteId: appearNote.id,
});
os.post({ initialNote: appearNote, renote: appearNote.renote, reply: appearNote.reply, channel: appearNote.channel });
@@ -54,19 +56,19 @@ export function getNoteMenu(props: {
function toggleFavorite(favorite: boolean): void {
os.apiWithDialog(favorite ? 'notes/favorites/create' : 'notes/favorites/delete', {
- noteId: appearNote.id
+ noteId: appearNote.id,
});
}
function toggleWatch(watch: boolean): void {
os.apiWithDialog(watch ? 'notes/watching/create' : 'notes/watching/delete', {
- noteId: appearNote.id
+ noteId: appearNote.id,
});
}
function toggleThreadMute(mute: boolean): void {
os.apiWithDialog(mute ? 'notes/thread-muting/create' : 'notes/thread-muting/delete', {
- noteId: appearNote.id
+ noteId: appearNote.id,
});
}
@@ -82,12 +84,12 @@ export function getNoteMenu(props: {
function togglePin(pin: boolean): void {
os.apiWithDialog(pin ? 'i/pin' : 'i/unpin', {
- noteId: appearNote.id
+ noteId: appearNote.id,
}, undefined, null, res => {
if (res.id === '72dab508-c64d-498f-8740-a8eec1ba385a') {
os.alert({
type: 'error',
- text: i18n.ts.pinLimitExceeded
+ text: i18n.ts.pinLimitExceeded,
});
}
});
@@ -102,35 +104,60 @@ export function getNoteMenu(props: {
const { canceled, result } = await os.form(i18n.ts.createNewClip, {
name: {
type: 'string',
- label: i18n.ts.name
+ label: i18n.ts.name,
},
description: {
type: 'string',
required: false,
multiline: true,
- label: i18n.ts.description
+ label: i18n.ts.description,
},
isPublic: {
type: 'boolean',
label: i18n.ts.public,
- default: false
- }
+ default: false,
+ },
});
if (canceled) return;
const clip = await os.apiWithDialog('clips/create', result);
os.apiWithDialog('clips/add-note', { clipId: clip.id, noteId: appearNote.id });
- }
+ },
}, null, ...clips.map(clip => ({
text: clip.name,
action: () => {
- os.apiWithDialog('clips/add-note', { clipId: clip.id, noteId: appearNote.id });
- }
+ os.promiseDialog(
+ os.api('clips/add-note', { clipId: clip.id, noteId: appearNote.id }),
+ null,
+ async (err) => {
+ if (err.id === '734806c4-542c-463a-9311-15c512803965') {
+ const confirm = await os.confirm({
+ type: 'warning',
+ text: i18n.t('confirmToUnclipAlreadyClippedNote', { name: clip.name }),
+ });
+ if (!confirm.canceled) {
+ os.apiWithDialog('clips/remove-note', { clipId: clip.id, noteId: appearNote.id });
+ if (props.currentClipPage?.value.id === clip.id) props.isDeleted.value = true;
+ }
+ } else {
+ os.alert({
+ type: 'error',
+ text: err.message + '\n' + err.id,
+ });
+ }
+ },
+ );
+ },
}))], props.menuButton.value, {
}).then(focus);
}
+ async function unclip(): Promise<void> {
+ os.apiWithDialog('clips/remove-note', { clipId: props.currentClipPage.value.id, noteId: appearNote.id });
+ props.isDeleted.value = true;
+ }
+
async function promote(): Promise<void> {
const { canceled, result: days } = await os.inputNumber({
title: i18n.ts.numberOfDays,
@@ -166,77 +193,86 @@ export function getNoteMenu(props: {
let menu;
if ($i) {
const statePromise = os.api('notes/state', {
- noteId: appearNote.id
+ noteId: appearNote.id,
});
- menu = [{
- icon: 'fas fa-copy',
- text: i18n.ts.copyContent,
- action: copyContent
- }, {
- icon: 'fas fa-link',
- text: i18n.ts.copyLink,
- action: copyLink
- }, (appearNote.url || appearNote.uri) ? {
- icon: 'fas fa-external-link-square-alt',
- text: i18n.ts.showOnRemote,
- action: () => {
- window.open(appearNote.url || appearNote.uri, '_blank');
- }
- } : undefined,
- {
- icon: 'fas fa-share-alt',
- text: i18n.ts.share,
- action: share
- },
- instance.translatorAvailable ? {
- icon: 'fas fa-language',
- text: i18n.ts.translate,
- action: translate
- } : undefined,
- null,
- statePromise.then(state => state.isFavorited ? {
- icon: 'fas fa-star',
- text: i18n.ts.unfavorite,
- action: () => toggleFavorite(false)
- } : {
- icon: 'fas fa-star',
- text: i18n.ts.favorite,
- action: () => toggleFavorite(true)
- }),
- {
- icon: 'fas fa-paperclip',
- text: i18n.ts.clip,
- action: () => clip()
- },
- (appearNote.userId !== $i.id) ? statePromise.then(state => state.isWatching ? {
- icon: 'fas fa-eye-slash',
- text: i18n.ts.unwatch,
- action: () => toggleWatch(false)
- } : {
- icon: 'fas fa-eye',
- text: i18n.ts.watch,
- action: () => toggleWatch(true)
- }) : undefined,
- statePromise.then(state => state.isMutedThread ? {
- icon: 'fas fa-comment-slash',
- text: i18n.ts.unmuteThread,
- action: () => toggleThreadMute(false)
- } : {
- icon: 'fas fa-comment-slash',
- text: i18n.ts.muteThread,
- action: () => toggleThreadMute(true)
- }),
- appearNote.userId === $i.id ? ($i.pinnedNoteIds || []).includes(appearNote.id) ? {
- icon: 'fas fa-thumbtack',
- text: i18n.ts.unpin,
- action: () => togglePin(false)
- } : {
- icon: 'fas fa-thumbtack',
- text: i18n.ts.pin,
- action: () => togglePin(true)
- } : undefined,
- /*
+ menu = [
+ ...(
+ props.currentClipPage?.value.userId === $i.id ? [{
+ icon: 'fas fa-circle-minus',
+ text: i18n.ts.unclip,
+ danger: true,
+ action: unclip,
+ }, null] : []
+ ),
+ {
+ icon: 'fas fa-copy',
+ text: i18n.ts.copyContent,
+ action: copyContent,
+ }, {
+ icon: 'fas fa-link',
+ text: i18n.ts.copyLink,
+ action: copyLink,
+ }, (appearNote.url || appearNote.uri) ? {
+ icon: 'fas fa-external-link-square-alt',
+ text: i18n.ts.showOnRemote,
+ action: () => {
+ window.open(appearNote.url || appearNote.uri, '_blank');
+ },
+ } : undefined,
+ {
+ icon: 'fas fa-share-alt',
+ text: i18n.ts.share,
+ action: share,
+ },
+ instance.translatorAvailable ? {
+ icon: 'fas fa-language',
+ text: i18n.ts.translate,
+ action: translate,
+ } : undefined,
+ null,
+ statePromise.then(state => state.isFavorited ? {
+ icon: 'fas fa-star',
+ text: i18n.ts.unfavorite,
+ action: () => toggleFavorite(false),
+ } : {
+ icon: 'fas fa-star',
+ text: i18n.ts.favorite,
+ action: () => toggleFavorite(true),
+ }),
+ {
+ icon: 'fas fa-paperclip',
+ text: i18n.ts.clip,
+ action: () => clip(),
+ },
+ (appearNote.userId !== $i.id) ? statePromise.then(state => state.isWatching ? {
+ icon: 'fas fa-eye-slash',
+ text: i18n.ts.unwatch,
+ action: () => toggleWatch(false),
+ } : {
+ icon: 'fas fa-eye',
+ text: i18n.ts.watch,
+ action: () => toggleWatch(true),
+ }) : undefined,
+ statePromise.then(state => state.isMutedThread ? {
+ icon: 'fas fa-comment-slash',
+ text: i18n.ts.unmuteThread,
+ action: () => toggleThreadMute(false),
+ } : {
+ icon: 'fas fa-comment-slash',
+ text: i18n.ts.muteThread,
+ action: () => toggleThreadMute(true),
+ }),
+ appearNote.userId === $i.id ? ($i.pinnedNoteIds || []).includes(appearNote.id) ? {
+ icon: 'fas fa-thumbtack',
+ text: i18n.ts.unpin,
+ action: () => togglePin(false),
+ } : {
+ icon: 'fas fa-thumbtack',
+ text: i18n.ts.pin,
+ action: () => togglePin(true),
+ } : undefined,
+ /*
...($i.isModerator || $i.isAdmin ? [
null,
{
@@ -246,52 +282,52 @@ export function getNoteMenu(props: {
}]
: []
),*/
- ...(appearNote.userId !== $i.id ? [
- null,
- {
- icon: 'fas fa-exclamation-circle',
- text: i18n.ts.reportAbuse,
- action: () => {
- const u = appearNote.url || appearNote.uri || `${url}/notes/${appearNote.id}`;
- os.popup(defineAsyncComponent(() => import('@/components/abuse-report-window.vue')), {
- user: appearNote.user,
- initialComment: `Note: ${u}\n-----\n`
- }, {}, 'closed');
- }
- }]
+ ...(appearNote.userId !== $i.id ? [
+ null,
+ {
+ icon: 'fas fa-exclamation-circle',
+ text: i18n.ts.reportAbuse,
+ action: () => {
+ const u = appearNote.url || appearNote.uri || `${url}/notes/${appearNote.id}`;
+ os.popup(defineAsyncComponent(() => import('@/components/abuse-report-window.vue')), {
+ user: appearNote.user,
+ initialComment: `Note: ${u}\n-----\n`,
+ }, {}, 'closed');
+ },
+ }]
: []
- ),
- ...(appearNote.userId === $i.id || $i.isModerator || $i.isAdmin ? [
- null,
- appearNote.userId === $i.id ? {
- icon: 'fas fa-edit',
- text: i18n.ts.deleteAndEdit,
- action: delEdit
- } : undefined,
- {
- icon: 'fas fa-trash-alt',
- text: i18n.ts.delete,
- danger: true,
- action: del
- }]
+ ),
+ ...(appearNote.userId === $i.id || $i.isModerator || $i.isAdmin ? [
+ null,
+ appearNote.userId === $i.id ? {
+ icon: 'fas fa-edit',
+ text: i18n.ts.deleteAndEdit,
+ action: delEdit,
+ } : undefined,
+ {
+ icon: 'fas fa-trash-alt',
+ text: i18n.ts.delete,
+ danger: true,
+ action: del,
+ }]
: []
- )]
+ )]
.filter(x => x !== undefined);
} else {
menu = [{
icon: 'fas fa-copy',
text: i18n.ts.copyContent,
- action: copyContent
+ action: copyContent,
}, {
icon: 'fas fa-link',
text: i18n.ts.copyLink,
- action: copyLink
+ action: copyLink,
}, (appearNote.url || appearNote.uri) ? {
icon: 'fas fa-external-link-square-alt',
text: i18n.ts.showOnRemote,
action: () => {
window.open(appearNote.url || appearNote.uri, '_blank');
- }
+ },
} : undefined]
.filter(x => x !== undefined);
}
@@ -302,7 +338,7 @@ export function getNoteMenu(props: {
text: action.title,
action: () => {
action.handler(appearNote);
- }
+ },
}))]);
}