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 { NoteEdit } from "@/models/entities/note-edit.js";
|
||||||
import { awaitAll } from "@/prelude/await-all.js";
|
import { awaitAll } from "@/prelude/await-all.js";
|
||||||
import type { Packed } from "@/misc/schema.js";
|
import type { Packed } from "@/misc/schema.js";
|
||||||
|
import {
|
||||||
|
DriveFiles,
|
||||||
|
} from "../index.js";
|
||||||
|
|
||||||
export const NoteEditRepository = db.getRepository(NoteEdit).extend({
|
export const NoteEditRepository = db.getRepository(NoteEdit).extend({
|
||||||
async pack(
|
async pack(
|
||||||
|
@ -14,6 +17,7 @@ export const NoteEditRepository = db.getRepository(NoteEdit).extend({
|
||||||
text: noteEdit.text,
|
text: noteEdit.text,
|
||||||
cw: noteEdit.cw,
|
cw: noteEdit.cw,
|
||||||
fileIds: noteEdit.fileIds,
|
fileIds: noteEdit.fileIds,
|
||||||
|
files: DriveFiles.packMany(noteEdit.fileIds),
|
||||||
})
|
})
|
||||||
|
|
||||||
return packed;
|
return packed;
|
||||||
|
|
|
@ -39,11 +39,22 @@ export const packedNoteEdit = {
|
||||||
fileIds: {
|
fileIds: {
|
||||||
type: "array",
|
type: "array",
|
||||||
optional: true,
|
optional: true,
|
||||||
nullable: true,
|
nullable: false,
|
||||||
items: {
|
items: {
|
||||||
type: "string",
|
type: "string",
|
||||||
format: "id",
|
format: "id",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
files: {
|
||||||
|
type: "array",
|
||||||
|
optional: true,
|
||||||
|
nullable: false,
|
||||||
|
items: {
|
||||||
|
type: "object",
|
||||||
|
optional: false,
|
||||||
|
nullable: false,
|
||||||
|
ref: "DriveFile",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
} as const;
|
} as const;
|
||||||
|
|
|
@ -87,18 +87,28 @@ onMounted(() => {
|
||||||
});
|
});
|
||||||
|
|
||||||
function convertNoteEditsToNotes(noteEdits: NoteEdit[]) {
|
function convertNoteEditsToNotes(noteEdits: NoteEdit[]) {
|
||||||
return [note.value].concat(
|
const now: NoteEdit = {
|
||||||
noteEdits.map(e => convertNoteEditToNote(e))
|
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 [now].concat(noteEdits).map((noteEdit: NoteEdit, index, arr): Note => {
|
||||||
return Object.assign({}, note.value, {
|
return Object.assign({}, note.value, {
|
||||||
id: crypto.randomUUID(), // Don't use noteId
|
id: crypto.randomUUID(), // Don't use noteId
|
||||||
createdAt: noteEdit.updatedAt,
|
// 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,
|
text: noteEdit.text,
|
||||||
cw: noteEdit.cw,
|
cw: noteEdit.cw,
|
||||||
_shouldInsertAd_: false,
|
_shouldInsertAd_: false,
|
||||||
|
files: noteEdit.files,
|
||||||
|
fileIds: noteEdit.fileIds,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -182,7 +182,8 @@ export type NoteEdit = {
|
||||||
text: string | null;
|
text: string | null;
|
||||||
cw: string | null;
|
cw: string | null;
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
fileIds: DriveFile["id"];
|
fileIds: DriveFile["id"][];
|
||||||
|
files: DriveFile[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type NoteReaction = {
|
export type NoteReaction = {
|
||||||
|
|
Loading…
Reference in a new issue