feat: show files of noteEdit
This commit is contained in:
parent
6d4cb5b4aa
commit
cbe88c56ef
4 changed files with 39 additions and 13 deletions
|
@ -2,6 +2,9 @@ import { db } from "@/db/postgre.js";
|
|||
import { NoteEdit } from "@/models/entities/note-edit.js";
|
||||
import { awaitAll } from "@/prelude/await-all.js";
|
||||
import type { Packed } from "@/misc/schema.js";
|
||||
import {
|
||||
DriveFiles,
|
||||
} from "../index.js";
|
||||
|
||||
export const NoteEditRepository = db.getRepository(NoteEdit).extend({
|
||||
async pack(
|
||||
|
@ -14,6 +17,7 @@ export const NoteEditRepository = db.getRepository(NoteEdit).extend({
|
|||
text: noteEdit.text,
|
||||
cw: noteEdit.cw,
|
||||
fileIds: noteEdit.fileIds,
|
||||
files: DriveFiles.packMany(noteEdit.fileIds),
|
||||
})
|
||||
|
||||
return packed;
|
||||
|
|
|
@ -39,11 +39,22 @@ export const packedNoteEdit = {
|
|||
fileIds: {
|
||||
type: "array",
|
||||
optional: true,
|
||||
nullable: true,
|
||||
nullable: false,
|
||||
items: {
|
||||
type: "string",
|
||||
format: "id",
|
||||
},
|
||||
},
|
||||
files: {
|
||||
type: "array",
|
||||
optional: true,
|
||||
nullable: false,
|
||||
items: {
|
||||
type: "object",
|
||||
optional: false,
|
||||
nullable: false,
|
||||
ref: "DriveFile",
|
||||
},
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
|
|
|
@ -87,18 +87,28 @@ onMounted(() => {
|
|||
});
|
||||
|
||||
function convertNoteEditsToNotes(noteEdits: NoteEdit[]) {
|
||||
return [note.value].concat(
|
||||
noteEdits.map(e => convertNoteEditToNote(e))
|
||||
);
|
||||
}
|
||||
const now: NoteEdit = {
|
||||
id: note.value.id,
|
||||
noteId: note.value.id,
|
||||
updatedAt: note.value.createdAt,
|
||||
text: note.value.text,
|
||||
cw: note.value.cw,
|
||||
files: note.value.files,
|
||||
fileIds: note.value.fileIds,
|
||||
};
|
||||
|
||||
function convertNoteEditToNote(noteEdit: NoteEdit): Note {
|
||||
return Object.assign({}, note.value, {
|
||||
id: crypto.randomUUID(), // Don't use noteId
|
||||
createdAt: noteEdit.updatedAt,
|
||||
text: noteEdit.text,
|
||||
cw: noteEdit.cw,
|
||||
_shouldInsertAd_: false,
|
||||
return [now].concat(noteEdits).map((noteEdit: NoteEdit, index, arr): Note => {
|
||||
return Object.assign({}, note.value, {
|
||||
id: crypto.randomUUID(), // Don't use noteId
|
||||
// Conversion from updatedAt to createdAt
|
||||
// The createdAt of a edition's content is actually the updatedAt of the previous one.
|
||||
createdAt: arr[(index + 1) % arr.length].updatedAt,
|
||||
text: noteEdit.text,
|
||||
cw: noteEdit.cw,
|
||||
_shouldInsertAd_: false,
|
||||
files: noteEdit.files,
|
||||
fileIds: noteEdit.fileIds,
|
||||
});
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -182,7 +182,8 @@ export type NoteEdit = {
|
|||
text: string | null;
|
||||
cw: string | null;
|
||||
updatedAt: string;
|
||||
fileIds: DriveFile["id"];
|
||||
fileIds: DriveFile["id"][];
|
||||
files: DriveFile[];
|
||||
}
|
||||
|
||||
export type NoteReaction = {
|
||||
|
|
Loading…
Reference in a new issue