2023-10-22 20:16:30 +09:00
|
|
|
import { Ref, defineAsyncComponent } from 'vue';
|
2023-10-22 10:00:35 +09:00
|
|
|
import * as Misskey from 'misskey-js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
import * as os from '@/os.js';
|
2024-01-09 10:57:57 +09:00
|
|
|
import { misskeyApi } from './misskey-api.js';
|
2023-10-22 10:00:35 +09:00
|
|
|
import { MenuItem } from '@/types/menu.js';
|
2023-10-22 20:36:34 +09:00
|
|
|
import { dateTimeFormat } from './intl-const.js';
|
2023-10-22 10:00:35 +09:00
|
|
|
|
|
|
|
export async function getNoteVersionsMenu(props: {
|
|
|
|
note: Misskey.entities.Note;
|
|
|
|
menuButton: Ref<HTMLElement>;
|
|
|
|
}) {
|
|
|
|
const isRenote = (
|
|
|
|
props.note.renote != null &&
|
|
|
|
props.note.text == null &&
|
|
|
|
props.note.fileIds.length === 0 &&
|
|
|
|
props.note.poll == null
|
|
|
|
);
|
|
|
|
|
|
|
|
const appearNote = isRenote ? props.note.renote as Misskey.entities.Note : props.note;
|
|
|
|
|
|
|
|
const cleanups = [] as (() => void)[];
|
|
|
|
|
|
|
|
function openVersion(info): void {
|
2023-10-22 20:16:30 +09:00
|
|
|
os.popup(defineAsyncComponent(() => import('@/components/SkOldNoteWindow.vue')), {
|
|
|
|
note: appearNote,
|
|
|
|
oldText: info.text,
|
2023-10-22 21:07:04 +09:00
|
|
|
updatedAt: info.oldDate ? info.oldDate : info.updatedAt,
|
2023-10-22 20:16:30 +09:00
|
|
|
}, {
|
|
|
|
}, 'closed');
|
2023-10-22 10:00:35 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
const menu: MenuItem[] = [];
|
2024-01-09 10:57:57 +09:00
|
|
|
const statePromise = misskeyApi('notes/versions', {
|
2023-10-22 10:00:35 +09:00
|
|
|
noteId: appearNote.id,
|
|
|
|
});
|
|
|
|
|
|
|
|
await statePromise.then((versions) => {
|
|
|
|
for (const edit of versions) {
|
2023-10-22 21:07:04 +09:00
|
|
|
const _time = edit.oldDate == null ? NaN :
|
|
|
|
typeof edit.oldDate === 'number' ? edit.oldDate :
|
|
|
|
(edit.oldDate instanceof Date ? edit.oldDate : new Date(edit.oldDate)).getTime();
|
2024-02-05 20:39:15 +09:00
|
|
|
|
2023-10-22 10:00:35 +09:00
|
|
|
menu.push({
|
2024-02-05 20:39:15 +09:00
|
|
|
icon: 'ph-pencil-simple ph-bold ph-lg',
|
2023-10-22 21:07:04 +09:00
|
|
|
text: _time ? dateTimeFormat.format(_time) : dateTimeFormat.format(new Date(edit.updatedAt)),
|
2023-10-22 10:00:35 +09:00
|
|
|
action: () => openVersion(edit),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const cleanup = () => {
|
|
|
|
if (_DEV_) console.log('note menu cleanup', cleanups);
|
|
|
|
for (const cl of cleanups) {
|
|
|
|
cl();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
menu,
|
|
|
|
cleanup,
|
|
|
|
};
|
|
|
|
}
|