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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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