2023-07-26 22:31:52 -07:00
|
|
|
|
/*
|
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
*/
|
|
|
|
|
|
2021-02-26 20:08:34 -08:00
|
|
|
|
// TODO: なんでもかんでもos.tsに突っ込むのやめたいのでよしなに分割する
|
|
|
|
|
|
2023-09-28 23:21:45 -07:00
|
|
|
|
import { pendingApiRequestsCount, api, apiExternal, apiGet } from '@/scripts/api.js';
|
|
|
|
|
export { pendingApiRequestsCount, api, apiExternal, apiGet };
|
2022-05-01 08:55:17 -07:00
|
|
|
|
import { Component, markRaw, Ref, ref, defineAsyncComponent } from 'vue';
|
2020-10-17 04:12:00 -07:00
|
|
|
|
import { EventEmitter } from 'eventemitter3';
|
2021-02-26 20:08:34 -08:00
|
|
|
|
import insertTextAtCursor from 'insert-text-at-cursor';
|
2021-05-27 01:15:08 -07:00
|
|
|
|
import * as Misskey from 'misskey-js';
|
2023-09-19 00:37:43 -07:00
|
|
|
|
import { i18n } from '@/i18n.js';
|
2022-08-30 08:24:33 -07:00
|
|
|
|
import MkPostFormDialog from '@/components/MkPostFormDialog.vue';
|
|
|
|
|
import MkWaitingDialog from '@/components/MkWaitingDialog.vue';
|
2023-01-20 22:30:29 -08:00
|
|
|
|
import MkPageWindow from '@/components/MkPageWindow.vue';
|
2023-01-17 00:36:18 -08:00
|
|
|
|
import MkToast from '@/components/MkToast.vue';
|
|
|
|
|
import MkDialog from '@/components/MkDialog.vue';
|
2023-09-21 22:12:33 -07:00
|
|
|
|
import MkPasswordDialog from '@/components/MkPasswordDialog.vue';
|
2023-01-17 00:36:18 -08:00
|
|
|
|
import MkEmojiPickerDialog from '@/components/MkEmojiPickerDialog.vue';
|
|
|
|
|
import MkEmojiPickerWindow from '@/components/MkEmojiPickerWindow.vue';
|
|
|
|
|
import MkPopupMenu from '@/components/MkPopupMenu.vue';
|
|
|
|
|
import MkContextMenu from '@/components/MkContextMenu.vue';
|
2023-09-19 00:37:43 -07:00
|
|
|
|
import { MenuItem } from '@/types/menu.js';
|
|
|
|
|
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
|
|
|
|
|
import { showMovedDialog } from '@/scripts/show-moved-dialog.js';
|
2020-10-17 04:12:00 -07:00
|
|
|
|
|
2023-01-20 22:30:29 -08:00
|
|
|
|
export const openingWindowsCount = ref(0);
|
|
|
|
|
|
2021-05-27 01:15:08 -07:00
|
|
|
|
export const apiWithDialog = ((
|
2020-10-17 18:11:34 -07:00
|
|
|
|
endpoint: string,
|
|
|
|
|
data: Record<string, any> = {},
|
|
|
|
|
token?: string | null | undefined,
|
2021-05-27 01:15:08 -07:00
|
|
|
|
) => {
|
2020-10-17 18:11:34 -07:00
|
|
|
|
const promise = api(endpoint, data, token);
|
2023-02-11 17:21:17 -08:00
|
|
|
|
promiseDialog(promise, null, async (err) => {
|
2023-01-14 00:46:45 -08:00
|
|
|
|
let title = null;
|
|
|
|
|
let text = err.message + '\n' + (err as any).id;
|
2023-02-11 17:21:17 -08:00
|
|
|
|
if (err.code === 'INTERNAL_ERROR') {
|
|
|
|
|
title = i18n.ts.internalServerError;
|
|
|
|
|
text = i18n.ts.internalServerErrorDescription;
|
|
|
|
|
const date = new Date().toISOString();
|
|
|
|
|
const { result } = await actions({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title,
|
|
|
|
|
text,
|
|
|
|
|
actions: [{
|
|
|
|
|
value: 'ok',
|
|
|
|
|
text: i18n.ts.gotIt,
|
|
|
|
|
primary: true,
|
|
|
|
|
}, {
|
|
|
|
|
value: 'copy',
|
|
|
|
|
text: i18n.ts.copyErrorInfo,
|
|
|
|
|
}],
|
|
|
|
|
});
|
|
|
|
|
if (result === 'copy') {
|
|
|
|
|
copyToClipboard(`Endpoint: ${endpoint}\nInfo: ${JSON.stringify(err.info)}\nDate: ${date}`);
|
|
|
|
|
success();
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
} else if (err.code === 'RATE_LIMIT_EXCEEDED') {
|
2023-01-14 23:13:57 -08:00
|
|
|
|
title = i18n.ts.cannotPerformTemporary;
|
|
|
|
|
text = i18n.ts.cannotPerformTemporaryDescription;
|
2023-04-20 17:17:44 -07:00
|
|
|
|
} else if (err.code === 'INVALID_PARAM') {
|
|
|
|
|
title = i18n.ts.invalidParamError;
|
|
|
|
|
text = i18n.ts.invalidParamErrorDescription;
|
|
|
|
|
} else if (err.code === 'ROLE_PERMISSION_DENIED') {
|
|
|
|
|
title = i18n.ts.permissionDeniedError;
|
|
|
|
|
text = i18n.ts.permissionDeniedErrorDescription;
|
2023-01-14 23:13:57 -08:00
|
|
|
|
} else if (err.code.startsWith('TOO_MANY')) {
|
2023-01-14 00:46:45 -08:00
|
|
|
|
title = i18n.ts.youCannotCreateAnymore;
|
|
|
|
|
text = `${i18n.ts.error}: ${err.id}`;
|
2023-02-09 01:07:51 -08:00
|
|
|
|
} else if (err.message.startsWith('Unexpected token')) {
|
|
|
|
|
title = i18n.ts.gotInvalidResponseError;
|
|
|
|
|
text = i18n.ts.gotInvalidResponseErrorDescription;
|
2023-01-14 00:46:45 -08:00
|
|
|
|
}
|
2021-11-18 06:36:04 -08:00
|
|
|
|
alert({
|
2020-10-17 18:21:02 -07:00
|
|
|
|
type: 'error',
|
2023-01-14 00:46:45 -08:00
|
|
|
|
title,
|
|
|
|
|
text,
|
2020-10-17 18:21:02 -07:00
|
|
|
|
});
|
|
|
|
|
});
|
2020-10-17 18:11:34 -07:00
|
|
|
|
|
|
|
|
|
return promise;
|
2021-05-27 01:15:08 -07:00
|
|
|
|
}) as typeof api;
|
2020-10-17 18:11:34 -07:00
|
|
|
|
|
|
|
|
|
export function promiseDialog<T extends Promise<any>>(
|
|
|
|
|
promise: T,
|
2021-01-03 06:58:24 -08:00
|
|
|
|
onSuccess?: ((res: any) => void) | null,
|
2022-05-26 06:53:09 -07:00
|
|
|
|
onFailure?: ((err: Error) => void) | null,
|
2020-10-17 18:11:34 -07:00
|
|
|
|
text?: string,
|
|
|
|
|
): T {
|
2020-10-17 04:12:00 -07:00
|
|
|
|
const showing = ref(true);
|
2020-10-17 18:11:34 -07:00
|
|
|
|
const success = ref(false);
|
2020-10-17 04:12:00 -07:00
|
|
|
|
|
|
|
|
|
promise.then(res => {
|
|
|
|
|
if (onSuccess) {
|
|
|
|
|
showing.value = false;
|
|
|
|
|
onSuccess(res);
|
|
|
|
|
} else {
|
2020-10-17 18:11:34 -07:00
|
|
|
|
success.value = true;
|
2022-01-15 17:14:14 -08:00
|
|
|
|
window.setTimeout(() => {
|
2020-10-17 04:12:00 -07:00
|
|
|
|
showing.value = false;
|
|
|
|
|
}, 1000);
|
|
|
|
|
}
|
2022-05-26 06:53:09 -07:00
|
|
|
|
}).catch(err => {
|
2020-10-17 04:12:00 -07:00
|
|
|
|
showing.value = false;
|
|
|
|
|
if (onFailure) {
|
2022-05-26 06:53:09 -07:00
|
|
|
|
onFailure(err);
|
2020-10-17 04:12:00 -07:00
|
|
|
|
} else {
|
2021-11-18 06:36:04 -08:00
|
|
|
|
alert({
|
2020-10-17 04:12:00 -07:00
|
|
|
|
type: 'error',
|
2022-05-26 06:53:09 -07:00
|
|
|
|
text: err,
|
2020-10-17 04:12:00 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2020-10-19 03:29:04 -07:00
|
|
|
|
// NOTE: dynamic importすると挙動がおかしくなる(showingの変更が伝播しない)
|
|
|
|
|
popup(MkWaitingDialog, {
|
2020-10-17 18:11:34 -07:00
|
|
|
|
success: success,
|
|
|
|
|
showing: showing,
|
|
|
|
|
text: text,
|
2020-10-17 04:12:00 -07:00
|
|
|
|
}, {}, 'closed');
|
|
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-31 21:38:48 -07:00
|
|
|
|
let popupIdCount = 0;
|
2020-10-17 04:12:00 -07:00
|
|
|
|
export const popups = ref([]) as Ref<{
|
|
|
|
|
id: any;
|
|
|
|
|
component: any;
|
|
|
|
|
props: Record<string, any>;
|
|
|
|
|
}[]>;
|
|
|
|
|
|
2021-12-17 19:12:47 -08:00
|
|
|
|
const zIndexes = {
|
2023-01-01 20:23:12 -08:00
|
|
|
|
veryLow: 500000,
|
2021-12-17 19:12:47 -08:00
|
|
|
|
low: 1000000,
|
|
|
|
|
middle: 2000000,
|
|
|
|
|
high: 3000000,
|
|
|
|
|
};
|
2023-01-01 20:23:12 -08:00
|
|
|
|
export function claimZIndex(priority: keyof typeof zIndexes = 'low'): number {
|
2021-12-17 19:12:47 -08:00
|
|
|
|
zIndexes[priority] += 100;
|
|
|
|
|
return zIndexes[priority];
|
2021-12-10 01:20:41 -08:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-01 06:51:07 -07:00
|
|
|
|
export async function popup(component: Component, props: Record<string, any>, events = {}, disposeEvent?: string) {
|
2020-10-17 04:12:00 -07:00
|
|
|
|
markRaw(component);
|
|
|
|
|
|
2020-10-31 21:38:48 -07:00
|
|
|
|
const id = ++popupIdCount;
|
2020-10-17 04:12:00 -07:00
|
|
|
|
const dispose = () => {
|
|
|
|
|
// このsetTimeoutが無いと挙動がおかしくなる(autocompleteが閉じなくなる)。Vueのバグ?
|
2022-01-15 17:14:14 -08:00
|
|
|
|
window.setTimeout(() => {
|
2020-10-17 04:12:00 -07:00
|
|
|
|
popups.value = popups.value.filter(popup => popup.id !== id);
|
|
|
|
|
}, 0);
|
|
|
|
|
};
|
|
|
|
|
const state = {
|
|
|
|
|
component,
|
|
|
|
|
props,
|
|
|
|
|
events: disposeEvent ? {
|
|
|
|
|
...events,
|
2022-06-10 23:45:44 -07:00
|
|
|
|
[disposeEvent]: dispose,
|
2020-10-17 04:12:00 -07:00
|
|
|
|
} : events,
|
|
|
|
|
id,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
popups.value.push(state);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
dispose,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-02 17:06:19 -08:00
|
|
|
|
export function pageWindow(path: string) {
|
2023-01-17 00:36:18 -08:00
|
|
|
|
popup(MkPageWindow, {
|
2020-11-02 17:06:19 -08:00
|
|
|
|
initialPath: path,
|
2020-10-17 04:12:00 -07:00
|
|
|
|
}, {}, 'closed');
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-28 03:07:37 -08:00
|
|
|
|
export function toast(message: string) {
|
2023-01-17 00:36:18 -08:00
|
|
|
|
popup(MkToast, {
|
2022-06-10 23:45:44 -07:00
|
|
|
|
message,
|
2021-12-17 21:55:53 -08:00
|
|
|
|
}, {}, 'closed');
|
2021-11-28 03:07:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-18 01:45:58 -08:00
|
|
|
|
export function alert(props: {
|
|
|
|
|
type?: 'error' | 'info' | 'success' | 'warning' | 'waiting' | 'question';
|
2021-08-21 21:16:23 -07:00
|
|
|
|
title?: string | null;
|
|
|
|
|
text?: string | null;
|
2021-11-18 01:45:58 -08:00
|
|
|
|
}): Promise<void> {
|
2020-10-17 04:12:00 -07:00
|
|
|
|
return new Promise((resolve, reject) => {
|
2023-01-17 00:36:18 -08:00
|
|
|
|
popup(MkDialog, props, {
|
2021-11-18 01:45:58 -08:00
|
|
|
|
done: result => {
|
|
|
|
|
resolve();
|
|
|
|
|
},
|
|
|
|
|
}, 'closed');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function confirm(props: {
|
|
|
|
|
type: 'error' | 'info' | 'success' | 'warning' | 'waiting' | 'question';
|
|
|
|
|
title?: string | null;
|
|
|
|
|
text?: string | null;
|
2023-02-09 17:45:32 -08:00
|
|
|
|
okText?: string;
|
|
|
|
|
cancelText?: string;
|
2021-11-18 01:45:58 -08:00
|
|
|
|
}): Promise<{ canceled: boolean }> {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
2023-01-17 00:36:18 -08:00
|
|
|
|
popup(MkDialog, {
|
2021-11-18 01:45:58 -08:00
|
|
|
|
...props,
|
|
|
|
|
showCancelButton: true,
|
|
|
|
|
}, {
|
|
|
|
|
done: result => {
|
|
|
|
|
resolve(result ? result : { canceled: true });
|
|
|
|
|
},
|
|
|
|
|
}, 'closed');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-10 20:54:27 -08:00
|
|
|
|
// TODO: const T extends ... にしたい
|
|
|
|
|
// https://zenn.dev/general_link/articles/813e47b7a0eef7#const-type-parameters
|
|
|
|
|
export function actions<T extends {
|
|
|
|
|
value: string;
|
|
|
|
|
text: string;
|
|
|
|
|
primary?: boolean,
|
2023-04-04 22:30:03 -07:00
|
|
|
|
danger?: boolean,
|
2023-02-10 20:54:27 -08:00
|
|
|
|
}[]>(props: {
|
|
|
|
|
type: 'error' | 'info' | 'success' | 'warning' | 'waiting' | 'question';
|
|
|
|
|
title?: string | null;
|
|
|
|
|
text?: string | null;
|
|
|
|
|
actions: T;
|
|
|
|
|
}): Promise<{ canceled: true; result: undefined; } | {
|
|
|
|
|
canceled: false; result: T[number]['value'];
|
|
|
|
|
}> {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
popup(MkDialog, {
|
|
|
|
|
...props,
|
|
|
|
|
actions: props.actions.map(a => ({
|
|
|
|
|
text: a.text,
|
|
|
|
|
primary: a.primary,
|
2023-04-04 22:30:03 -07:00
|
|
|
|
danger: a.danger,
|
2023-02-10 20:54:27 -08:00
|
|
|
|
callback: () => {
|
|
|
|
|
resolve({ canceled: false, result: a.value });
|
|
|
|
|
},
|
|
|
|
|
})),
|
|
|
|
|
}, {
|
|
|
|
|
done: result => {
|
|
|
|
|
resolve(result ? result : { canceled: true });
|
|
|
|
|
},
|
|
|
|
|
}, 'closed');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-18 01:45:58 -08:00
|
|
|
|
export function inputText(props: {
|
|
|
|
|
type?: 'text' | 'email' | 'password' | 'url';
|
|
|
|
|
title?: string | null;
|
|
|
|
|
text?: string | null;
|
|
|
|
|
placeholder?: string | null;
|
2023-02-19 23:40:24 -08:00
|
|
|
|
autocomplete?: string;
|
2021-11-18 01:45:58 -08:00
|
|
|
|
default?: string | null;
|
2023-02-19 23:40:24 -08:00
|
|
|
|
minLength?: number;
|
|
|
|
|
maxLength?: number;
|
2021-11-18 01:45:58 -08:00
|
|
|
|
}): Promise<{ canceled: true; result: undefined; } | {
|
|
|
|
|
canceled: false; result: string;
|
|
|
|
|
}> {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
2023-01-17 00:36:18 -08:00
|
|
|
|
popup(MkDialog, {
|
2021-11-18 01:45:58 -08:00
|
|
|
|
title: props.title,
|
|
|
|
|
text: props.text,
|
|
|
|
|
input: {
|
|
|
|
|
type: props.type,
|
|
|
|
|
placeholder: props.placeholder,
|
2023-02-19 23:40:24 -08:00
|
|
|
|
autocomplete: props.autocomplete,
|
2021-11-18 01:45:58 -08:00
|
|
|
|
default: props.default,
|
2023-02-19 23:40:24 -08:00
|
|
|
|
minLength: props.minLength,
|
|
|
|
|
maxLength: props.maxLength,
|
2022-06-10 23:45:44 -07:00
|
|
|
|
},
|
2021-11-18 01:45:58 -08:00
|
|
|
|
}, {
|
|
|
|
|
done: result => {
|
|
|
|
|
resolve(result ? result : { canceled: true });
|
|
|
|
|
},
|
|
|
|
|
}, 'closed');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function inputNumber(props: {
|
|
|
|
|
title?: string | null;
|
|
|
|
|
text?: string | null;
|
|
|
|
|
placeholder?: string | null;
|
2023-02-19 23:40:24 -08:00
|
|
|
|
autocomplete?: string;
|
2021-11-18 01:45:58 -08:00
|
|
|
|
default?: number | null;
|
|
|
|
|
}): Promise<{ canceled: true; result: undefined; } | {
|
|
|
|
|
canceled: false; result: number;
|
|
|
|
|
}> {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
2023-01-17 00:36:18 -08:00
|
|
|
|
popup(MkDialog, {
|
2021-11-18 01:45:58 -08:00
|
|
|
|
title: props.title,
|
|
|
|
|
text: props.text,
|
|
|
|
|
input: {
|
|
|
|
|
type: 'number',
|
|
|
|
|
placeholder: props.placeholder,
|
2023-02-19 23:40:24 -08:00
|
|
|
|
autocomplete: props.autocomplete,
|
2021-11-18 01:45:58 -08:00
|
|
|
|
default: props.default,
|
2022-06-10 23:45:44 -07:00
|
|
|
|
},
|
2021-11-18 01:45:58 -08:00
|
|
|
|
}, {
|
|
|
|
|
done: result => {
|
|
|
|
|
resolve(result ? result : { canceled: true });
|
|
|
|
|
},
|
|
|
|
|
}, 'closed');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function inputDate(props: {
|
|
|
|
|
title?: string | null;
|
|
|
|
|
text?: string | null;
|
|
|
|
|
placeholder?: string | null;
|
|
|
|
|
default?: Date | null;
|
|
|
|
|
}): Promise<{ canceled: true; result: undefined; } | {
|
|
|
|
|
canceled: false; result: Date;
|
|
|
|
|
}> {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
2023-01-17 00:36:18 -08:00
|
|
|
|
popup(MkDialog, {
|
2021-11-18 01:45:58 -08:00
|
|
|
|
title: props.title,
|
|
|
|
|
text: props.text,
|
|
|
|
|
input: {
|
|
|
|
|
type: 'date',
|
|
|
|
|
placeholder: props.placeholder,
|
|
|
|
|
default: props.default,
|
2022-06-10 23:45:44 -07:00
|
|
|
|
},
|
2021-11-18 01:45:58 -08:00
|
|
|
|
}, {
|
|
|
|
|
done: result => {
|
|
|
|
|
resolve(result ? { result: new Date(result.result), canceled: false } : { canceled: true });
|
|
|
|
|
},
|
|
|
|
|
}, 'closed');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-21 22:12:33 -07:00
|
|
|
|
export function authenticateDialog(): Promise<{ canceled: true; result: undefined; } | {
|
|
|
|
|
canceled: false; result: { password: string; token: string | null; };
|
|
|
|
|
}> {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
popup(MkPasswordDialog, {}, {
|
|
|
|
|
done: result => {
|
|
|
|
|
resolve(result ? { canceled: false, result } : { canceled: true, result: undefined });
|
|
|
|
|
},
|
|
|
|
|
}, 'closed');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-09 22:36:55 -07:00
|
|
|
|
export function select<C = any>(props: {
|
2021-11-18 01:45:58 -08:00
|
|
|
|
title?: string | null;
|
|
|
|
|
text?: string | null;
|
|
|
|
|
default?: string | null;
|
2022-03-20 11:11:14 -07:00
|
|
|
|
} & ({
|
|
|
|
|
items: {
|
|
|
|
|
value: C;
|
2021-11-18 01:45:58 -08:00
|
|
|
|
text: string;
|
|
|
|
|
}[];
|
2022-03-20 11:11:14 -07:00
|
|
|
|
} | {
|
|
|
|
|
groupedItems: {
|
2021-11-18 01:45:58 -08:00
|
|
|
|
label: string;
|
|
|
|
|
items: {
|
2022-03-20 11:11:14 -07:00
|
|
|
|
value: C;
|
2021-11-18 01:45:58 -08:00
|
|
|
|
text: string;
|
|
|
|
|
}[];
|
|
|
|
|
}[];
|
2022-03-20 11:11:14 -07:00
|
|
|
|
})): Promise<{ canceled: true; result: undefined; } | {
|
|
|
|
|
canceled: false; result: C;
|
2021-11-18 01:45:58 -08:00
|
|
|
|
}> {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
2023-01-17 00:36:18 -08:00
|
|
|
|
popup(MkDialog, {
|
2021-11-18 01:45:58 -08:00
|
|
|
|
title: props.title,
|
|
|
|
|
text: props.text,
|
|
|
|
|
select: {
|
|
|
|
|
items: props.items,
|
|
|
|
|
groupedItems: props.groupedItems,
|
|
|
|
|
default: props.default,
|
2022-06-10 23:45:44 -07:00
|
|
|
|
},
|
2021-11-18 01:45:58 -08:00
|
|
|
|
}, {
|
2020-10-17 04:12:00 -07:00
|
|
|
|
done: result => {
|
|
|
|
|
resolve(result ? result : { canceled: true });
|
|
|
|
|
},
|
|
|
|
|
}, 'closed');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-01 22:05:05 -08:00
|
|
|
|
export function success(): Promise<void> {
|
2020-10-17 04:12:00 -07:00
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const showing = ref(true);
|
2022-01-15 17:14:14 -08:00
|
|
|
|
window.setTimeout(() => {
|
2020-10-17 04:12:00 -07:00
|
|
|
|
showing.value = false;
|
|
|
|
|
}, 1000);
|
2023-01-17 00:36:18 -08:00
|
|
|
|
popup(MkWaitingDialog, {
|
2020-10-17 18:11:34 -07:00
|
|
|
|
success: true,
|
2022-06-10 23:45:44 -07:00
|
|
|
|
showing: showing,
|
2020-10-17 04:12:00 -07:00
|
|
|
|
}, {
|
|
|
|
|
done: () => resolve(),
|
|
|
|
|
}, 'closed');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-01 22:05:05 -08:00
|
|
|
|
export function waiting(): Promise<void> {
|
2020-10-17 04:12:00 -07:00
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const showing = ref(true);
|
2023-01-17 00:36:18 -08:00
|
|
|
|
popup(MkWaitingDialog, {
|
2020-10-17 18:11:34 -07:00
|
|
|
|
success: false,
|
2022-06-10 23:45:44 -07:00
|
|
|
|
showing: showing,
|
2020-10-17 04:12:00 -07:00
|
|
|
|
}, {
|
|
|
|
|
done: () => resolve(),
|
|
|
|
|
}, 'closed');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function form(title, form) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
2022-08-30 08:24:33 -07:00
|
|
|
|
popup(defineAsyncComponent(() => import('@/components/MkFormDialog.vue')), { title, form }, {
|
2020-10-17 04:12:00 -07:00
|
|
|
|
done: result => {
|
|
|
|
|
resolve(result);
|
|
|
|
|
},
|
|
|
|
|
}, 'closed');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-15 12:29:44 -08:00
|
|
|
|
export async function selectUser(opts: { includeSelf?: boolean } = {}) {
|
2020-10-17 04:12:00 -07:00
|
|
|
|
return new Promise((resolve, reject) => {
|
2023-01-15 12:29:44 -08:00
|
|
|
|
popup(defineAsyncComponent(() => import('@/components/MkUserSelectDialog.vue')), {
|
|
|
|
|
includeSelf: opts.includeSelf,
|
|
|
|
|
}, {
|
2020-10-17 04:12:00 -07:00
|
|
|
|
ok: user => {
|
|
|
|
|
resolve(user);
|
|
|
|
|
},
|
|
|
|
|
}, 'closed');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-03 21:33:38 -07:00
|
|
|
|
export async function selectDriveFile(multiple: boolean): Promise<Misskey.entities.DriveFile[]> {
|
2020-10-17 04:12:00 -07:00
|
|
|
|
return new Promise((resolve, reject) => {
|
2022-08-30 08:24:33 -07:00
|
|
|
|
popup(defineAsyncComponent(() => import('@/components/MkDriveSelectDialog.vue')), {
|
2020-10-17 04:12:00 -07:00
|
|
|
|
type: 'file',
|
2022-06-10 23:45:44 -07:00
|
|
|
|
multiple,
|
2020-10-17 04:12:00 -07:00
|
|
|
|
}, {
|
|
|
|
|
done: files => {
|
|
|
|
|
if (files) {
|
2023-05-07 16:52:01 -07:00
|
|
|
|
resolve(files);
|
2020-10-17 04:12:00 -07:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}, 'closed');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function selectDriveFolder(multiple: boolean) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
2022-08-30 08:24:33 -07:00
|
|
|
|
popup(defineAsyncComponent(() => import('@/components/MkDriveSelectDialog.vue')), {
|
2020-10-17 04:12:00 -07:00
|
|
|
|
type: 'folder',
|
2022-06-10 23:45:44 -07:00
|
|
|
|
multiple,
|
2020-10-17 04:12:00 -07:00
|
|
|
|
}, {
|
|
|
|
|
done: folders => {
|
|
|
|
|
if (folders) {
|
|
|
|
|
resolve(multiple ? folders : folders[0]);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}, 'closed');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-27 19:20:42 -08:00
|
|
|
|
export async function pickEmoji(src: HTMLElement | null, opts) {
|
2020-10-17 04:12:00 -07:00
|
|
|
|
return new Promise((resolve, reject) => {
|
2023-01-17 00:36:18 -08:00
|
|
|
|
popup(MkEmojiPickerDialog, {
|
2020-11-13 21:32:01 -08:00
|
|
|
|
src,
|
2022-06-10 23:45:44 -07:00
|
|
|
|
...opts,
|
2020-10-17 04:12:00 -07:00
|
|
|
|
}, {
|
|
|
|
|
done: emoji => {
|
|
|
|
|
resolve(emoji);
|
|
|
|
|
},
|
|
|
|
|
}, 'closed');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-10 23:45:44 -07:00
|
|
|
|
export async function cropImage(image: Misskey.entities.DriveFile, options: {
|
|
|
|
|
aspectRatio: number;
|
2023-07-04 21:54:40 -07:00
|
|
|
|
uploadFolder?: string | null;
|
2022-06-10 23:45:44 -07:00
|
|
|
|
}): Promise<Misskey.entities.DriveFile> {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
2022-08-30 08:24:33 -07:00
|
|
|
|
popup(defineAsyncComponent(() => import('@/components/MkCropperDialog.vue')), {
|
2022-06-10 23:45:44 -07:00
|
|
|
|
file: image,
|
|
|
|
|
aspectRatio: options.aspectRatio,
|
2023-07-04 21:54:40 -07:00
|
|
|
|
uploadFolder: options.uploadFolder,
|
2022-06-10 23:45:44 -07:00
|
|
|
|
}, {
|
|
|
|
|
ok: x => {
|
|
|
|
|
resolve(x);
|
|
|
|
|
},
|
|
|
|
|
}, 'closed');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-26 20:08:34 -08:00
|
|
|
|
type AwaitType<T> =
|
|
|
|
|
T extends Promise<infer U> ? U :
|
2021-02-28 02:09:08 -08:00
|
|
|
|
T extends (...args: any[]) => Promise<infer V> ? V :
|
2021-02-26 20:08:34 -08:00
|
|
|
|
T;
|
|
|
|
|
let openingEmojiPicker: AwaitType<ReturnType<typeof popup>> | null = null;
|
|
|
|
|
let activeTextarea: HTMLTextAreaElement | HTMLInputElement | null = null;
|
|
|
|
|
export async function openEmojiPicker(src?: HTMLElement, opts, initialTextarea: typeof activeTextarea) {
|
|
|
|
|
if (openingEmojiPicker) return;
|
|
|
|
|
|
|
|
|
|
activeTextarea = initialTextarea;
|
|
|
|
|
|
|
|
|
|
const textareas = document.querySelectorAll('textarea, input');
|
|
|
|
|
for (const textarea of Array.from(textareas)) {
|
|
|
|
|
textarea.addEventListener('focus', () => {
|
|
|
|
|
activeTextarea = textarea;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const observer = new MutationObserver(records => {
|
|
|
|
|
for (const record of records) {
|
2021-02-26 20:16:59 -08:00
|
|
|
|
for (const node of Array.from(record.addedNodes).filter(node => node instanceof HTMLElement) as HTMLElement[]) {
|
|
|
|
|
const textareas = node.querySelectorAll('textarea, input') as NodeListOf<NonNullable<typeof activeTextarea>>;
|
|
|
|
|
for (const textarea of Array.from(textareas).filter(textarea => textarea.dataset.preventEmojiInsert == null)) {
|
|
|
|
|
if (document.activeElement === textarea) activeTextarea = textarea;
|
|
|
|
|
textarea.addEventListener('focus', () => {
|
|
|
|
|
activeTextarea = textarea;
|
|
|
|
|
});
|
2021-02-26 20:08:34 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
observer.observe(document.body, {
|
|
|
|
|
childList: true,
|
|
|
|
|
subtree: true,
|
|
|
|
|
attributes: false,
|
|
|
|
|
characterData: false,
|
|
|
|
|
});
|
|
|
|
|
|
2023-01-17 00:36:18 -08:00
|
|
|
|
openingEmojiPicker = await popup(MkEmojiPickerWindow, {
|
2021-02-26 20:08:34 -08:00
|
|
|
|
src,
|
2022-06-10 23:45:44 -07:00
|
|
|
|
...opts,
|
2021-02-26 20:08:34 -08:00
|
|
|
|
}, {
|
|
|
|
|
chosen: emoji => {
|
|
|
|
|
insertTextAtCursor(activeTextarea, emoji);
|
|
|
|
|
},
|
|
|
|
|
closed: () => {
|
|
|
|
|
openingEmojiPicker!.dispose();
|
|
|
|
|
openingEmojiPicker = null;
|
|
|
|
|
observer.disconnect();
|
2022-06-10 23:45:44 -07:00
|
|
|
|
},
|
2021-02-26 20:08:34 -08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-29 21:11:52 -08:00
|
|
|
|
export function popupMenu(items: MenuItem[] | Ref<MenuItem[]>, src?: HTMLElement, options?: {
|
2021-10-21 14:23:23 -07:00
|
|
|
|
align?: string;
|
|
|
|
|
width?: number;
|
|
|
|
|
viaKeyboard?: boolean;
|
2023-01-05 17:11:47 -08:00
|
|
|
|
onClosing?: () => void;
|
2023-03-01 22:05:05 -08:00
|
|
|
|
}): Promise<void> {
|
2020-10-17 04:12:00 -07:00
|
|
|
|
return new Promise((resolve, reject) => {
|
2020-11-02 22:22:55 -08:00
|
|
|
|
let dispose;
|
2023-01-17 00:36:18 -08:00
|
|
|
|
popup(MkPopupMenu, {
|
2020-10-17 04:12:00 -07:00
|
|
|
|
items,
|
|
|
|
|
src,
|
2021-10-21 14:23:23 -07:00
|
|
|
|
width: options?.width,
|
2020-10-17 04:12:00 -07:00
|
|
|
|
align: options?.align,
|
2022-06-10 23:45:44 -07:00
|
|
|
|
viaKeyboard: options?.viaKeyboard,
|
2020-10-17 04:12:00 -07:00
|
|
|
|
}, {
|
|
|
|
|
closed: () => {
|
|
|
|
|
resolve();
|
|
|
|
|
dispose();
|
|
|
|
|
},
|
2023-01-05 17:11:47 -08:00
|
|
|
|
closing: () => {
|
|
|
|
|
if (options?.onClosing) options.onClosing();
|
|
|
|
|
},
|
2020-11-02 23:21:28 -08:00
|
|
|
|
}).then(res => {
|
|
|
|
|
dispose = res.dispose;
|
2020-10-17 04:12:00 -07:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-01 22:05:05 -08:00
|
|
|
|
export function contextMenu(items: MenuItem[] | Ref<MenuItem[]>, ev: MouseEvent): Promise<void> {
|
2020-10-17 04:12:00 -07:00
|
|
|
|
ev.preventDefault();
|
|
|
|
|
return new Promise((resolve, reject) => {
|
2020-11-02 22:22:55 -08:00
|
|
|
|
let dispose;
|
2023-01-17 00:36:18 -08:00
|
|
|
|
popup(MkContextMenu, {
|
2020-10-17 04:12:00 -07:00
|
|
|
|
items,
|
|
|
|
|
ev,
|
|
|
|
|
}, {
|
|
|
|
|
closed: () => {
|
|
|
|
|
resolve();
|
|
|
|
|
dispose();
|
|
|
|
|
},
|
2020-11-02 23:21:28 -08:00
|
|
|
|
}).then(res => {
|
|
|
|
|
dispose = res.dispose;
|
2020-10-17 04:12:00 -07:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-01 22:05:05 -08:00
|
|
|
|
export function post(props: Record<string, any> = {}): Promise<void> {
|
enhance: account migration (#10592)
* copy block and mute then create follow and unfollow jobs
* copy block and mute and update lists when detecting an account has moved
* no need to care promise orders
* refactor updating actor and target
* automatically accept if a locked account had accepted an old account
* fix exception format
* prevent the old account from calling some endpoints
* do not unfollow when moving
* adjust following and follower counts
* check movedToUri when receiving a follow request
* skip if no need to adjust
* Revert "disable account migration"
This reverts commit 2321214c98591bcfe1385c1ab5bf0ff7b471ae1d.
* fix translation specifier
* fix checking alsoKnownAs and uri
* fix updating account
* fix refollowing locked account
* decrease followersCount if followed by the old account
* adjust following and followers counts when unfollowing
* fix copying mutings
* prohibit moved account from moving again
* fix move service
* allow app creation after moving
* fix lint
* remove unnecessary field
* fix cache update
* add e2e test
* add e2e test of accepting the new account automatically
* force follow if any error happens
* remove unnecessary joins
* use Array.map instead of for const of
* ユーザーリストの移行は追加のみを行う
* nanka iroiro
* fix misskey-js?
* :v:
* 移行を行ったアカウントからのフォローリクエストの自動許可を調整
* newUriを外に出す
* newUriを外に出す2
* clean up
* fix newUri
* prevent moving if the destination account has already moved
* set alsoKnownAs via /i/update
* fix database initialization
* add return type
* prohibit updating alsoKnownAs after moving
* skip to add to alsoKnownAs if toUrl is known
* skip adding to the list if it already has
* use Acct.parse instead
* rename error code
* :art:
* 制限を5から10に緩和
* movedTo(Uri), alsoKnownAsはユーザーidを返すように
* test api res
* fix
* 元アカウントはミュートし続ける
* :art:
* unfollow
* fix
* getUserUriをUserEntityServiceに
* ?
* job!
* :art:
* instance => server
* accountMovedShort, forbiddenBecauseYouAreMigrated
* accountMovedShort
* fix test
* import, pin禁止
* 実績を凍結する
* clean up
* :v:
* change message
* ブロック, フォロー, ミュート, リストのインポートファイルの制限を32MiBに
* Revert "ブロック, フォロー, ミュート, リストのインポートファイルの制限を32MiBに"
This reverts commit 3bd7be35d8aa455cb01ae58f8172a71a50485db1.
* validateAlsoKnownAs
* 移行後2時間以内はインポート可能なファイルサイズを拡大
* clean up
* どうせactorをupdatePersonで更新するならupdatePersonしか移行処理を発行しないことにする
* handle error?
* リモートからの移行処理の条件を是正
* log, port
* fix
* fix
* enhance(dev): non-production環境でhttpサーバー間でもユーザー、ノートの連合が可能なように
* refactor (use checkHttps)
* MISSKEY_WEBFINGER_USE_HTTP
* Environment Variable readme
* NEVER USE IN PRODUCTION
* fix punyHost
* fix indent
* fix
* experimental
---------
Co-authored-by: tamaina <tamaina@hotmail.co.jp>
Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2023-04-29 08:09:29 -07:00
|
|
|
|
showMovedDialog();
|
|
|
|
|
|
2020-10-17 04:12:00 -07:00
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
// NOTE: MkPostFormDialogをdynamic importするとiOSでテキストエリアに自動フォーカスできない
|
2020-10-18 22:46:32 -07:00
|
|
|
|
// NOTE: ただ、dynamic importしない場合、MkPostFormDialogインスタンスが使いまわされ、
|
|
|
|
|
// Vueが渡されたコンポーネントに内部的に__propsというプロパティを生やす影響で、
|
|
|
|
|
// 複数のpost formを開いたときに場合によってはエラーになる
|
|
|
|
|
// もちろん複数のpost formを開けること自体Misskeyサイドのバグなのだが
|
2020-11-02 22:22:55 -08:00
|
|
|
|
let dispose;
|
|
|
|
|
popup(MkPostFormDialog, props, {
|
2020-10-17 04:12:00 -07:00
|
|
|
|
closed: () => {
|
|
|
|
|
resolve();
|
|
|
|
|
dispose();
|
|
|
|
|
},
|
2020-11-02 23:21:28 -08:00
|
|
|
|
}).then(res => {
|
|
|
|
|
dispose = res.dispose;
|
2020-10-17 04:12:00 -07:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const deckGlobalEvents = new EventEmitter();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
export function checkExistence(fileData: ArrayBuffer): Promise<any> {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const data = new FormData();
|
|
|
|
|
data.append('md5', getMD5(fileData));
|
|
|
|
|
|
|
|
|
|
os.api('drive/files/find-by-hash', {
|
|
|
|
|
md5: getMD5(fileData)
|
|
|
|
|
}).then(resp => {
|
|
|
|
|
resolve(resp.length > 0 ? resp[0] : null);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}*/
|