chore: format

This commit is contained in:
Lhcfl 2024-04-01 03:24:30 +08:00
parent 9a0136514b
commit a562d9bb39
9 changed files with 37 additions and 45 deletions

View File

@ -2,14 +2,10 @@ 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 { import { DriveFiles } from "../index.js";
DriveFiles,
} from "../index.js";
export const NoteEditRepository = db.getRepository(NoteEdit).extend({ export const NoteEditRepository = db.getRepository(NoteEdit).extend({
async pack( async pack(noteEdit: NoteEdit) {
noteEdit: NoteEdit,
) {
const packed: Packed<"NoteEdit"> = await awaitAll({ const packed: Packed<"NoteEdit"> = await awaitAll({
id: noteEdit.id, id: noteEdit.id,
noteId: noteEdit.noteId, noteId: noteEdit.noteId,
@ -18,24 +14,20 @@ export const NoteEditRepository = db.getRepository(NoteEdit).extend({
cw: noteEdit.cw, cw: noteEdit.cw,
fileIds: noteEdit.fileIds, fileIds: noteEdit.fileIds,
files: DriveFiles.packMany(noteEdit.fileIds), files: DriveFiles.packMany(noteEdit.fileIds),
}) });
return packed; return packed;
}, },
async packMany( async packMany(noteEdits: NoteEdit[]) {
noteEdits: NoteEdit[],
) {
if (noteEdits.length === 0) return []; if (noteEdits.length === 0) return [];
const promises = await Promise.allSettled( const promises = await Promise.allSettled(
noteEdits.map((n) => noteEdits.map((n) => this.pack(n)),
this.pack(n)
),
); );
// filter out rejected promises, only keep fulfilled values // filter out rejected promises, only keep fulfilled values
return promises.flatMap((result) => return promises.flatMap((result) =>
result.status === "fulfilled" ? [result.value] : [], result.status === "fulfilled" ? [result.value] : [],
); );
} },
}); });

View File

@ -639,7 +639,7 @@ export default define(meta, paramDef, async (ps, user) => {
(async () => { (async () => {
const noteActivity = await renderNote(note, false); const noteActivity = await renderNote(note, false);
noteActivity.updated = (new Date()).toISOString(); noteActivity.updated = new Date().toISOString();
const updateActivity = renderUpdate(noteActivity, user); const updateActivity = renderUpdate(noteActivity, user);
updateActivity.to = noteActivity.to; updateActivity.to = noteActivity.to;
updateActivity.cc = noteActivity.cc; updateActivity.cc = noteActivity.cc;

View File

@ -59,7 +59,7 @@ export default define(meta, paramDef, async (ps, user) => {
take: ps.limit, take: ps.limit,
skip: ps.offset, skip: ps.offset,
order: { order: {
id: "DESC" id: "DESC",
}, },
}); });

View File

@ -158,7 +158,7 @@
> >
</div> </div>
<footer <footer
v-show="!hideFooter" v-show="!hideFooter"
ref="footerEl" ref="footerEl"
class="footer" class="footer"
tabindex="-1" tabindex="-1"

View File

@ -3,13 +3,14 @@ import type { entities } from "firefish-js";
export function notePage( export function notePage(
note: entities.Note, note: entities.Note,
options?: { options?: {
historyPage?: boolean historyPage?: boolean;
}) { },
) {
if (options?.historyPage) { if (options?.historyPage) {
return `/notes/${note.id}/history`; return `/notes/${note.id}/history`;
} }
if (note.historyId) { if (note.historyId) {
return `/notes/${note.id}/history#${note.historyId}` return `/notes/${note.id}/history#${note.historyId}`;
} }
return `/notes/${note.id}`; return `/notes/${note.id}`;
}; }

View File

@ -1,11 +1,9 @@
<template> <template>
<MkStickyContainer> <MkStickyContainer>
<template #header <template #header
><MkPageHeader ><MkPageHeader :display-back-button="true"
:display-back-button="true"
/></template> /></template>
<MkSpacer :content-max="800"> <MkSpacer :content-max="800">
<MkLoading v-if="!loaded" /> <MkLoading v-if="!loaded" />
<MkPagination <MkPagination
v-else v-else
@ -15,7 +13,7 @@
> >
<div ref="tlEl" class="giivymft noGap"> <div ref="tlEl" class="giivymft noGap">
<XList <XList
v-slot="{item} : {item: Note}" v-slot="{ item }: { item: Note }"
:items="convertNoteEditsToNotes(items)" :items="convertNoteEditsToNotes(items)"
class="notes" class="notes"
:no-gap="true" :no-gap="true"
@ -30,15 +28,14 @@
</XList> </XList>
</div> </div>
</MkPagination> </MkPagination>
</MkSpacer> </MkSpacer>
</MkStickyContainer> </MkStickyContainer>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { computed, onMounted, ref } from "vue"; import { computed, onMounted, ref } from "vue";
import MkPagination from "@/components/MkPagination.vue" import MkPagination from "@/components/MkPagination.vue";
import type { Paging } from "@/components/MkPagination.vue" import type { Paging } from "@/components/MkPagination.vue";
import { api } from "@/os"; import { api } from "@/os";
import XList from "@/components/MkDateSeparatedList.vue"; import XList from "@/components/MkDateSeparatedList.vue";
import XNote from "@/components/MkNote.vue"; import XNote from "@/components/MkNote.vue";
@ -58,7 +55,7 @@ const pagination: Paging = {
limit: 10, limit: 10,
offsetMode: true, offsetMode: true,
params: computed(() => ({ params: computed(() => ({
noteId: props.noteId noteId: props.noteId,
})), })),
}; };
@ -81,7 +78,7 @@ onMounted(() => {
res.renoteId = null; res.renoteId = null;
res.reply = undefined; res.reply = undefined;
res.replyId = null; res.replyId = null;
note.value = res; note.value = res;
loaded.value = true; loaded.value = true;
}); });
@ -98,19 +95,21 @@ function convertNoteEditsToNotes(noteEdits: NoteEdit[]) {
fileIds: note.value.fileIds, fileIds: note.value.fileIds,
}; };
return [now].concat(noteEdits).map((noteEdit: NoteEdit, index, arr): Note => { return [now]
return Object.assign({}, note.value, { .concat(noteEdits)
historyId: noteEdit.id, .map((noteEdit: NoteEdit, index, arr): Note => {
// Conversion from updatedAt to createdAt return Object.assign({}, note.value, {
// The createdAt of a edition's content is actually the updatedAt of the previous one. historyId: noteEdit.id,
createdAt: arr[(index + 1) % arr.length].updatedAt, // Conversion from updatedAt to createdAt
text: noteEdit.text, // The createdAt of a edition's content is actually the updatedAt of the previous one.
cw: noteEdit.cw, createdAt: arr[(index + 1) % arr.length].updatedAt,
_shouldInsertAd_: false, text: noteEdit.text,
files: noteEdit.files, cw: noteEdit.cw,
fileIds: noteEdit.fileIds, _shouldInsertAd_: false,
files: noteEdit.files,
fileIds: noteEdit.fileIds,
});
}); });
});
} }
</script> </script>

View File

@ -373,7 +373,7 @@ export function getNoteMenu(props: {
: undefined, : undefined,
isEdited isEdited
? { ? {
icon: `${icon('ph-clock-countdown')}`, icon: `${icon("ph-clock-countdown")}`,
text: i18n.ts.noteEditHistory, text: i18n.ts.noteEditHistory,
action: () => showEditHistory(), action: () => showEditHistory(),
} }

View File

@ -664,7 +664,7 @@ export type Endpoints = {
limit?: number; limit?: number;
offset?: number; offset?: number;
}; };
res: NoteEdit[] res: NoteEdit[];
}; };
"notes/recommended-timeline": { "notes/recommended-timeline": {
req: { req: {

View File

@ -186,7 +186,7 @@ export type NoteEdit = {
updatedAt: string; updatedAt: string;
fileIds: DriveFile["id"][]; fileIds: DriveFile["id"][];
files: DriveFile[]; files: DriveFile[];
} };
export type NoteReaction = { export type NoteReaction = {
id: ID; id: ID;