2022-05-01 08:51:07 -05:00
|
|
|
import { defineAsyncComponent, Ref } from 'vue';
|
2022-01-13 19:25:51 -06:00
|
|
|
import * as misskey from 'misskey-js';
|
|
|
|
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';
|
|
|
|
import { pleaseLogin } from './please-login';
|
|
|
|
|
|
|
|
export function getNoteMenu(props: {
|
|
|
|
note: misskey.entities.Note;
|
|
|
|
menuButton: Ref<HTMLElement>;
|
|
|
|
translation: Ref<any>;
|
|
|
|
translating: Ref<boolean>;
|
|
|
|
}) {
|
|
|
|
const isRenote = (
|
|
|
|
props.note.renote != null &&
|
|
|
|
props.note.text == null &&
|
|
|
|
props.note.fileIds.length === 0 &&
|
|
|
|
props.note.poll == null
|
|
|
|
);
|
|
|
|
|
|
|
|
let appearNote = isRenote ? props.note.renote as misskey.entities.Note : props.note;
|
|
|
|
|
|
|
|
function del(): void {
|
|
|
|
os.confirm({
|
|
|
|
type: 'warning',
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts.noteDeleteConfirm,
|
2022-01-13 19:25:51 -06:00
|
|
|
}).then(({ canceled }) => {
|
|
|
|
if (canceled) return;
|
|
|
|
|
|
|
|
os.api('notes/delete', {
|
|
|
|
noteId: appearNote.id
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function delEdit(): void {
|
|
|
|
os.confirm({
|
|
|
|
type: 'warning',
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts.deleteAndEditConfirm,
|
2022-01-13 19:25:51 -06:00
|
|
|
}).then(({ canceled }) => {
|
|
|
|
if (canceled) return;
|
|
|
|
|
|
|
|
os.api('notes/delete', {
|
|
|
|
noteId: appearNote.id
|
|
|
|
});
|
|
|
|
|
|
|
|
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', {
|
|
|
|
noteId: appearNote.id
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleWatch(watch: boolean): void {
|
|
|
|
os.apiWithDialog(watch ? 'notes/watching/create' : 'notes/watching/delete', {
|
|
|
|
noteId: appearNote.id
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleThreadMute(mute: boolean): void {
|
|
|
|
os.apiWithDialog(mute ? 'notes/thread-muting/create' : 'notes/thread-muting/delete', {
|
|
|
|
noteId: appearNote.id
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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', {
|
|
|
|
noteId: appearNote.id
|
|
|
|
}, undefined, null, e => {
|
|
|
|
if (e.id === '72dab508-c64d-498f-8740-a8eec1ba385a') {
|
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts.pinLimitExceeded
|
2022-01-13 19:25:51 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function clip(): Promise<void> {
|
|
|
|
const clips = await os.api('clips/list');
|
|
|
|
os.popupMenu([{
|
|
|
|
icon: 'fas fa-plus',
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts.createNew,
|
2022-01-13 19:25:51 -06:00
|
|
|
action: async () => {
|
2022-01-27 20:39:49 -06:00
|
|
|
const { canceled, result } = await os.form(i18n.ts.createNewClip, {
|
2022-01-13 19:25:51 -06:00
|
|
|
name: {
|
|
|
|
type: 'string',
|
2022-01-27 20:39:49 -06:00
|
|
|
label: i18n.ts.name
|
2022-01-13 19:25:51 -06:00
|
|
|
},
|
|
|
|
description: {
|
|
|
|
type: 'string',
|
|
|
|
required: false,
|
|
|
|
multiline: true,
|
2022-01-27 20:39:49 -06:00
|
|
|
label: i18n.ts.description
|
2022-01-13 19:25:51 -06:00
|
|
|
},
|
|
|
|
isPublic: {
|
|
|
|
type: 'boolean',
|
2022-01-27 20:39:49 -06:00
|
|
|
label: i18n.ts.public,
|
2022-01-13 19:25:51 -06:00
|
|
|
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 });
|
|
|
|
}
|
|
|
|
}))], props.menuButton.value, {
|
|
|
|
}).then(focus);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function promote(): Promise<void> {
|
|
|
|
const { canceled, result: days } = await os.inputNumber({
|
2022-01-27 20:39:49 -06:00
|
|
|
title: i18n.ts.numberOfDays,
|
2022-01-13 19:25:51 -06: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}`,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
targetLang: localStorage.getItem('lang') || navigator.language,
|
|
|
|
});
|
|
|
|
props.translating.value = false;
|
|
|
|
props.translation.value = res;
|
|
|
|
}
|
|
|
|
|
|
|
|
let menu;
|
|
|
|
if ($i) {
|
|
|
|
const statePromise = os.api('notes/state', {
|
|
|
|
noteId: appearNote.id
|
|
|
|
});
|
|
|
|
|
|
|
|
menu = [{
|
|
|
|
icon: 'fas fa-copy',
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts.copyContent,
|
2022-01-13 19:25:51 -06:00
|
|
|
action: copyContent
|
|
|
|
}, {
|
|
|
|
icon: 'fas fa-link',
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts.copyLink,
|
2022-01-13 19:25:51 -06:00
|
|
|
action: copyLink
|
|
|
|
}, (appearNote.url || appearNote.uri) ? {
|
|
|
|
icon: 'fas fa-external-link-square-alt',
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts.showOnRemote,
|
2022-01-13 19:25:51 -06:00
|
|
|
action: () => {
|
|
|
|
window.open(appearNote.url || appearNote.uri, '_blank');
|
|
|
|
}
|
|
|
|
} : undefined,
|
|
|
|
{
|
|
|
|
icon: 'fas fa-share-alt',
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts.share,
|
2022-01-13 19:25:51 -06:00
|
|
|
action: share
|
|
|
|
},
|
|
|
|
instance.translatorAvailable ? {
|
|
|
|
icon: 'fas fa-language',
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts.translate,
|
2022-01-13 19:25:51 -06:00
|
|
|
action: translate
|
|
|
|
} : undefined,
|
|
|
|
null,
|
|
|
|
statePromise.then(state => state.isFavorited ? {
|
|
|
|
icon: 'fas fa-star',
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts.unfavorite,
|
2022-01-13 19:25:51 -06:00
|
|
|
action: () => toggleFavorite(false)
|
|
|
|
} : {
|
|
|
|
icon: 'fas fa-star',
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts.favorite,
|
2022-01-13 19:25:51 -06:00
|
|
|
action: () => toggleFavorite(true)
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
icon: 'fas fa-paperclip',
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts.clip,
|
2022-01-13 19:25:51 -06:00
|
|
|
action: () => clip()
|
|
|
|
},
|
|
|
|
(appearNote.userId != $i.id) ? statePromise.then(state => state.isWatching ? {
|
|
|
|
icon: 'fas fa-eye-slash',
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts.unwatch,
|
2022-01-13 19:25:51 -06:00
|
|
|
action: () => toggleWatch(false)
|
|
|
|
} : {
|
|
|
|
icon: 'fas fa-eye',
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts.watch,
|
2022-01-13 19:25:51 -06:00
|
|
|
action: () => toggleWatch(true)
|
|
|
|
}) : undefined,
|
|
|
|
statePromise.then(state => state.isMutedThread ? {
|
|
|
|
icon: 'fas fa-comment-slash',
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts.unmuteThread,
|
2022-01-13 19:25:51 -06:00
|
|
|
action: () => toggleThreadMute(false)
|
|
|
|
} : {
|
|
|
|
icon: 'fas fa-comment-slash',
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts.muteThread,
|
2022-01-13 19:25:51 -06:00
|
|
|
action: () => toggleThreadMute(true)
|
|
|
|
}),
|
|
|
|
appearNote.userId == $i.id ? ($i.pinnedNoteIds || []).includes(appearNote.id) ? {
|
|
|
|
icon: 'fas fa-thumbtack',
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts.unpin,
|
2022-01-13 19:25:51 -06:00
|
|
|
action: () => togglePin(false)
|
|
|
|
} : {
|
|
|
|
icon: 'fas fa-thumbtack',
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts.pin,
|
2022-01-13 19:25:51 -06:00
|
|
|
action: () => togglePin(true)
|
|
|
|
} : undefined,
|
|
|
|
/*
|
|
|
|
...($i.isModerator || $i.isAdmin ? [
|
|
|
|
null,
|
|
|
|
{
|
|
|
|
icon: 'fas fa-bullhorn',
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts.promote,
|
2022-01-13 19:25:51 -06:00
|
|
|
action: promote
|
|
|
|
}]
|
|
|
|
: []
|
|
|
|
),*/
|
|
|
|
...(appearNote.userId != $i.id ? [
|
|
|
|
null,
|
|
|
|
{
|
|
|
|
icon: 'fas fa-exclamation-circle',
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts.reportAbuse,
|
2022-01-13 19:25:51 -06:00
|
|
|
action: () => {
|
2022-01-20 12:06:38 -06:00
|
|
|
const u = appearNote.url || appearNote.uri || `${url}/notes/${appearNote.id}`;
|
2022-05-01 08:51:07 -05:00
|
|
|
os.popup(defineAsyncComponent(() => import('@/components/abuse-report-window.vue')), {
|
2022-01-13 19:25:51 -06:00
|
|
|
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',
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts.deleteAndEdit,
|
2022-01-13 19:25:51 -06:00
|
|
|
action: delEdit
|
|
|
|
} : undefined,
|
|
|
|
{
|
|
|
|
icon: 'fas fa-trash-alt',
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts.delete,
|
2022-01-13 19:25:51 -06:00
|
|
|
danger: true,
|
|
|
|
action: del
|
|
|
|
}]
|
|
|
|
: []
|
|
|
|
)]
|
|
|
|
.filter(x => x !== undefined);
|
|
|
|
} else {
|
|
|
|
menu = [{
|
|
|
|
icon: 'fas fa-copy',
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts.copyContent,
|
2022-01-13 19:25:51 -06:00
|
|
|
action: copyContent
|
|
|
|
}, {
|
|
|
|
icon: 'fas fa-link',
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts.copyLink,
|
2022-01-13 19:25:51 -06:00
|
|
|
action: copyLink
|
|
|
|
}, (appearNote.url || appearNote.uri) ? {
|
|
|
|
icon: 'fas fa-external-link-square-alt',
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts.showOnRemote,
|
2022-01-13 19:25:51 -06:00
|
|
|
action: () => {
|
|
|
|
window.open(appearNote.url || appearNote.uri, '_blank');
|
|
|
|
}
|
|
|
|
} : undefined]
|
|
|
|
.filter(x => x !== undefined);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (noteActions.length > 0) {
|
|
|
|
menu = menu.concat([null, ...noteActions.map(action => ({
|
|
|
|
icon: 'fas fa-plug',
|
|
|
|
text: action.title,
|
|
|
|
action: () => {
|
|
|
|
action.handler(appearNote);
|
|
|
|
}
|
|
|
|
}))]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
}
|