2022-06-18 11:27:09 +02:00
|
|
|
import { defineAsyncComponent, Ref, inject } from 'vue';
|
2022-01-14 02:25:51 +01:00
|
|
|
import * as misskey from 'misskey-js';
|
2022-06-30 03:53:40 +02:00
|
|
|
import { pleaseLogin } from './please-login';
|
2022-01-14 02:25:51 +01:00
|
|
|
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 { noteActions } from '@/store';
|
2022-11-12 23:54:05 +01:00
|
|
|
import { notePage } from '@/filters/note';
|
2023-01-07 02:13:02 +01:00
|
|
|
import { miLocalStorage } from '@/local-storage';
|
2022-01-14 02:25:51 +01:00
|
|
|
|
|
|
|
export function getNoteMenu(props: {
|
|
|
|
note: misskey.entities.Note;
|
|
|
|
menuButton: Ref<HTMLElement>;
|
|
|
|
translation: Ref<any>;
|
|
|
|
translating: Ref<boolean>;
|
2022-06-18 11:27:09 +02:00
|
|
|
isDeleted: Ref<boolean>;
|
2022-06-18 11:27:47 +02:00
|
|
|
currentClipPage?: Ref<misskey.entities.Clip>;
|
2022-01-14 02:25:51 +01:00
|
|
|
}) {
|
|
|
|
const isRenote = (
|
|
|
|
props.note.renote != null &&
|
|
|
|
props.note.text == null &&
|
|
|
|
props.note.fileIds.length === 0 &&
|
|
|
|
props.note.poll == null
|
|
|
|
);
|
|
|
|
|
2022-06-10 07:36:55 +02:00
|
|
|
const appearNote = isRenote ? props.note.renote as misskey.entities.Note : props.note;
|
2022-01-14 02:25:51 +01:00
|
|
|
|
|
|
|
function del(): void {
|
|
|
|
os.confirm({
|
|
|
|
type: 'warning',
|
2022-01-28 03:39:49 +01:00
|
|
|
text: i18n.ts.noteDeleteConfirm,
|
2022-01-14 02:25:51 +01:00
|
|
|
}).then(({ canceled }) => {
|
|
|
|
if (canceled) return;
|
|
|
|
|
|
|
|
os.api('notes/delete', {
|
2022-06-30 03:53:40 +02:00
|
|
|
noteId: appearNote.id,
|
2022-01-14 02:25:51 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function delEdit(): void {
|
|
|
|
os.confirm({
|
|
|
|
type: 'warning',
|
2022-01-28 03:39:49 +01:00
|
|
|
text: i18n.ts.deleteAndEditConfirm,
|
2022-01-14 02:25:51 +01:00
|
|
|
}).then(({ canceled }) => {
|
|
|
|
if (canceled) return;
|
|
|
|
|
|
|
|
os.api('notes/delete', {
|
2022-06-30 03:53:40 +02:00
|
|
|
noteId: appearNote.id,
|
2022-01-14 02:25:51 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
os.post({ initialNote: appearNote, renote: appearNote.renote, reply: appearNote.reply, channel: appearNote.channel });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleFavorite(favorite: boolean): void {
|
|
|
|
os.apiWithDialog(favorite ? 'notes/favorites/create' : 'notes/favorites/delete', {
|
2022-06-30 03:53:40 +02:00
|
|
|
noteId: appearNote.id,
|
2022-01-14 02:25:51 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleThreadMute(mute: boolean): void {
|
|
|
|
os.apiWithDialog(mute ? 'notes/thread-muting/create' : 'notes/thread-muting/delete', {
|
2022-06-30 03:53:40 +02:00
|
|
|
noteId: appearNote.id,
|
2022-01-14 02:25:51 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function copyContent(): void {
|
|
|
|
copyToClipboard(appearNote.text);
|
|
|
|
os.success();
|
|
|
|
}
|
|
|
|
|
|
|
|
function copyLink(): void {
|
|
|
|
copyToClipboard(`${url}/notes/${appearNote.id}`);
|
|
|
|
os.success();
|
|
|
|
}
|
|
|
|
|
|
|
|
function togglePin(pin: boolean): void {
|
|
|
|
os.apiWithDialog(pin ? 'i/pin' : 'i/unpin', {
|
2022-06-30 03:53:40 +02:00
|
|
|
noteId: appearNote.id,
|
2022-05-07 07:19:15 +02:00
|
|
|
}, undefined, null, res => {
|
|
|
|
if (res.id === '72dab508-c64d-498f-8740-a8eec1ba385a') {
|
2022-01-14 02:25:51 +01:00
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
2022-06-30 03:53:40 +02:00
|
|
|
text: i18n.ts.pinLimitExceeded,
|
2022-01-14 02:25:51 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function clip(): Promise<void> {
|
|
|
|
const clips = await os.api('clips/list');
|
|
|
|
os.popupMenu([{
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-plus',
|
2022-01-28 03:39:49 +01:00
|
|
|
text: i18n.ts.createNew,
|
2022-01-14 02:25:51 +01:00
|
|
|
action: async () => {
|
2022-01-28 03:39:49 +01:00
|
|
|
const { canceled, result } = await os.form(i18n.ts.createNewClip, {
|
2022-01-14 02:25:51 +01:00
|
|
|
name: {
|
|
|
|
type: 'string',
|
2022-06-30 03:53:40 +02:00
|
|
|
label: i18n.ts.name,
|
2022-01-14 02:25:51 +01:00
|
|
|
},
|
|
|
|
description: {
|
|
|
|
type: 'string',
|
|
|
|
required: false,
|
|
|
|
multiline: true,
|
2022-06-30 03:53:40 +02:00
|
|
|
label: i18n.ts.description,
|
2022-01-14 02:25:51 +01:00
|
|
|
},
|
|
|
|
isPublic: {
|
|
|
|
type: 'boolean',
|
2022-01-28 03:39:49 +01:00
|
|
|
label: i18n.ts.public,
|
2022-06-30 03:53:40 +02:00
|
|
|
default: false,
|
|
|
|
},
|
2022-01-14 02:25:51 +01:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
|
|
|
const clip = await os.apiWithDialog('clips/create', result);
|
|
|
|
|
|
|
|
os.apiWithDialog('clips/add-note', { clipId: clip.id, noteId: appearNote.id });
|
2022-06-30 03:53:40 +02:00
|
|
|
},
|
2022-01-14 02:25:51 +01:00
|
|
|
}, null, ...clips.map(clip => ({
|
|
|
|
text: clip.name,
|
|
|
|
action: () => {
|
2022-06-18 11:27:09 +02:00
|
|
|
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 });
|
2022-06-18 11:27:47 +02:00
|
|
|
if (props.currentClipPage?.value.id === clip.id) props.isDeleted.value = true;
|
2022-06-18 11:27:09 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
|
|
|
text: err.message + '\n' + err.id,
|
|
|
|
});
|
|
|
|
}
|
2022-06-30 03:53:40 +02:00
|
|
|
},
|
2022-06-18 11:27:09 +02:00
|
|
|
);
|
2022-06-30 03:53:40 +02:00
|
|
|
},
|
2022-01-14 02:25:51 +01:00
|
|
|
}))], props.menuButton.value, {
|
|
|
|
}).then(focus);
|
|
|
|
}
|
|
|
|
|
2022-06-18 11:27:09 +02:00
|
|
|
async function unclip(): Promise<void> {
|
2022-06-18 11:27:47 +02:00
|
|
|
os.apiWithDialog('clips/remove-note', { clipId: props.currentClipPage.value.id, noteId: appearNote.id });
|
2022-06-18 11:27:09 +02:00
|
|
|
props.isDeleted.value = true;
|
|
|
|
}
|
|
|
|
|
2022-01-14 02:25:51 +01:00
|
|
|
async function promote(): Promise<void> {
|
|
|
|
const { canceled, result: days } = await os.inputNumber({
|
2022-01-28 03:39:49 +01:00
|
|
|
title: i18n.ts.numberOfDays,
|
2022-01-14 02:25:51 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
if (canceled) return;
|
|
|
|
|
|
|
|
os.apiWithDialog('admin/promo/create', {
|
|
|
|
noteId: appearNote.id,
|
|
|
|
expiresAt: Date.now() + (86400000 * days),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function share(): void {
|
|
|
|
navigator.share({
|
|
|
|
title: i18n.t('noteOf', { user: appearNote.user.name }),
|
|
|
|
text: appearNote.text,
|
|
|
|
url: `${url}/notes/${appearNote.id}`,
|
|
|
|
});
|
|
|
|
}
|
2022-11-12 23:54:05 +01:00
|
|
|
function notedetails(): void {
|
|
|
|
os.pageWindow(`/notes/${appearNote.id}`);
|
|
|
|
}
|
2022-01-14 02:25:51 +01:00
|
|
|
async function translate(): Promise<void> {
|
|
|
|
if (props.translation.value != null) return;
|
|
|
|
props.translating.value = true;
|
|
|
|
const res = await os.api('notes/translate', {
|
|
|
|
noteId: appearNote.id,
|
2023-01-07 02:13:02 +01:00
|
|
|
targetLang: miLocalStorage.getItem('lang') || navigator.language,
|
2022-01-14 02:25:51 +01:00
|
|
|
});
|
|
|
|
props.translating.value = false;
|
|
|
|
props.translation.value = res;
|
|
|
|
}
|
|
|
|
|
|
|
|
let menu;
|
|
|
|
if ($i) {
|
|
|
|
const statePromise = os.api('notes/state', {
|
2022-06-30 03:53:40 +02:00
|
|
|
noteId: appearNote.id,
|
2022-01-14 02:25:51 +01:00
|
|
|
});
|
|
|
|
|
2022-06-18 11:27:09 +02:00
|
|
|
menu = [
|
2022-06-30 03:53:40 +02:00
|
|
|
...(
|
|
|
|
props.currentClipPage?.value.userId === $i.id ? [{
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-backspace',
|
2022-06-30 03:53:40 +02:00
|
|
|
text: i18n.ts.unclip,
|
|
|
|
danger: true,
|
|
|
|
action: unclip,
|
|
|
|
}, null] : []
|
2022-11-12 23:54:05 +01:00
|
|
|
), {
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-external-link',
|
2022-11-12 23:54:05 +01:00
|
|
|
text: i18n.ts.details,
|
|
|
|
action: notedetails,
|
|
|
|
}, {
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-copy',
|
2022-06-30 03:53:40 +02:00
|
|
|
text: i18n.ts.copyContent,
|
|
|
|
action: copyContent,
|
|
|
|
}, {
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-link',
|
2022-06-30 03:53:40 +02:00
|
|
|
text: i18n.ts.copyLink,
|
|
|
|
action: copyLink,
|
|
|
|
}, (appearNote.url || appearNote.uri) ? {
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-external-link',
|
2022-06-30 03:53:40 +02:00
|
|
|
text: i18n.ts.showOnRemote,
|
|
|
|
action: () => {
|
|
|
|
window.open(appearNote.url || appearNote.uri, '_blank');
|
|
|
|
},
|
|
|
|
} : undefined,
|
|
|
|
{
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-share',
|
2022-06-30 03:53:40 +02:00
|
|
|
text: i18n.ts.share,
|
|
|
|
action: share,
|
|
|
|
},
|
|
|
|
instance.translatorAvailable ? {
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-language-hiragana',
|
2022-06-30 03:53:40 +02:00
|
|
|
text: i18n.ts.translate,
|
|
|
|
action: translate,
|
|
|
|
} : undefined,
|
|
|
|
null,
|
|
|
|
statePromise.then(state => state.isFavorited ? {
|
2022-12-20 02:40:56 +01:00
|
|
|
icon: 'ti ti-star-off',
|
2022-06-30 03:53:40 +02:00
|
|
|
text: i18n.ts.unfavorite,
|
|
|
|
action: () => toggleFavorite(false),
|
|
|
|
} : {
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-star',
|
2022-06-30 03:53:40 +02:00
|
|
|
text: i18n.ts.favorite,
|
|
|
|
action: () => toggleFavorite(true),
|
|
|
|
}),
|
|
|
|
{
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-paperclip',
|
2022-06-30 03:53:40 +02:00
|
|
|
text: i18n.ts.clip,
|
|
|
|
action: () => clip(),
|
|
|
|
},
|
|
|
|
statePromise.then(state => state.isMutedThread ? {
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-message-off',
|
2022-06-30 03:53:40 +02:00
|
|
|
text: i18n.ts.unmuteThread,
|
|
|
|
action: () => toggleThreadMute(false),
|
|
|
|
} : {
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-message-off',
|
2022-06-30 03:53:40 +02:00
|
|
|
text: i18n.ts.muteThread,
|
|
|
|
action: () => toggleThreadMute(true),
|
|
|
|
}),
|
|
|
|
appearNote.userId === $i.id ? ($i.pinnedNoteIds || []).includes(appearNote.id) ? {
|
2022-12-20 02:40:56 +01:00
|
|
|
icon: 'ti ti-pinned-off',
|
2022-06-30 03:53:40 +02:00
|
|
|
text: i18n.ts.unpin,
|
|
|
|
action: () => togglePin(false),
|
|
|
|
} : {
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-pin',
|
2022-06-30 03:53:40 +02:00
|
|
|
text: i18n.ts.pin,
|
|
|
|
action: () => togglePin(true),
|
|
|
|
} : undefined,
|
|
|
|
/*
|
2022-01-14 02:25:51 +01:00
|
|
|
...($i.isModerator || $i.isAdmin ? [
|
|
|
|
null,
|
|
|
|
{
|
|
|
|
icon: 'fas fa-bullhorn',
|
2022-01-28 03:39:49 +01:00
|
|
|
text: i18n.ts.promote,
|
2022-01-14 02:25:51 +01:00
|
|
|
action: promote
|
|
|
|
}]
|
|
|
|
: []
|
|
|
|
),*/
|
2022-06-30 03:53:40 +02:00
|
|
|
...(appearNote.userId !== $i.id ? [
|
|
|
|
null,
|
|
|
|
{
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-exclamation-circle',
|
2022-06-30 03:53:40 +02:00
|
|
|
text: i18n.ts.reportAbuse,
|
|
|
|
action: () => {
|
|
|
|
const u = appearNote.url || appearNote.uri || `${url}/notes/${appearNote.id}`;
|
2022-08-30 17:24:33 +02:00
|
|
|
os.popup(defineAsyncComponent(() => import('@/components/MkAbuseReportWindow.vue')), {
|
2022-06-30 03:53:40 +02:00
|
|
|
user: appearNote.user,
|
|
|
|
initialComment: `Note: ${u}\n-----\n`,
|
|
|
|
}, {}, 'closed');
|
|
|
|
},
|
|
|
|
}]
|
2022-01-14 02:25:51 +01:00
|
|
|
: []
|
2022-06-30 03:53:40 +02:00
|
|
|
),
|
|
|
|
...(appearNote.userId === $i.id || $i.isModerator || $i.isAdmin ? [
|
|
|
|
null,
|
|
|
|
appearNote.userId === $i.id ? {
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-edit',
|
2022-06-30 03:53:40 +02:00
|
|
|
text: i18n.ts.deleteAndEdit,
|
|
|
|
action: delEdit,
|
|
|
|
} : undefined,
|
|
|
|
{
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-trash',
|
2022-06-30 03:53:40 +02:00
|
|
|
text: i18n.ts.delete,
|
|
|
|
danger: true,
|
|
|
|
action: del,
|
|
|
|
}]
|
2022-01-14 02:25:51 +01:00
|
|
|
: []
|
2022-06-30 03:53:40 +02:00
|
|
|
)]
|
2022-09-24 03:39:17 +02:00
|
|
|
.filter(x => x !== undefined);
|
2022-01-14 02:25:51 +01:00
|
|
|
} else {
|
|
|
|
menu = [{
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-external-link',
|
2022-11-12 23:54:05 +01:00
|
|
|
text: i18n.ts.detailed,
|
|
|
|
action: openDetail,
|
|
|
|
}, {
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-copy',
|
2022-01-28 03:39:49 +01:00
|
|
|
text: i18n.ts.copyContent,
|
2022-06-30 03:53:40 +02:00
|
|
|
action: copyContent,
|
2022-01-14 02:25:51 +01:00
|
|
|
}, {
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-link',
|
2022-01-28 03:39:49 +01:00
|
|
|
text: i18n.ts.copyLink,
|
2022-06-30 03:53:40 +02:00
|
|
|
action: copyLink,
|
2022-01-14 02:25:51 +01:00
|
|
|
}, (appearNote.url || appearNote.uri) ? {
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-external-link',
|
2022-01-28 03:39:49 +01:00
|
|
|
text: i18n.ts.showOnRemote,
|
2022-01-14 02:25:51 +01:00
|
|
|
action: () => {
|
|
|
|
window.open(appearNote.url || appearNote.uri, '_blank');
|
2022-06-30 03:53:40 +02:00
|
|
|
},
|
2022-01-14 02:25:51 +01:00
|
|
|
} : undefined]
|
2022-09-24 03:39:17 +02:00
|
|
|
.filter(x => x !== undefined);
|
2022-01-14 02:25:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (noteActions.length > 0) {
|
|
|
|
menu = menu.concat([null, ...noteActions.map(action => ({
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-plug',
|
2022-01-14 02:25:51 +01:00
|
|
|
text: action.title,
|
|
|
|
action: () => {
|
|
|
|
action.handler(appearNote);
|
2022-06-30 03:53:40 +02:00
|
|
|
},
|
2022-01-14 02:25:51 +01:00
|
|
|
}))]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
}
|