From 535fa9f506a4fad3afa1f55ed091692b3069a34a Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Sun, 4 Jun 2023 14:41:18 -0700 Subject: [PATCH] fix: :bug: prevent null date insertion https://calckey.aokaga.work/notes/9f6ksv2oov --- packages/backend/src/services/note/create.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/backend/src/services/note/create.ts b/packages/backend/src/services/note/create.ts index bd54db7e24..31fddfc4e0 100644 --- a/packages/backend/src/services/note/create.ts +++ b/packages/backend/src/services/note/create.ts @@ -596,20 +596,20 @@ export default async ( lastNotedAt: new Date(), }); - const count = await Notes.countBy({ + await Notes.countBy({ userId: user.id, channelId: data.channel.id, }).then((count) => { // この処理が行われるのはノート作成後なので、ノートが一つしかなかったら最初の投稿だと判断できる // TODO: とはいえノートを削除して何回も投稿すればその分だけインクリメントされる雑さもあるのでどうにかしたい - if (count === 1) { - Channels.increment({ id: data.channel!.id }, "usersCount", 1); + if (count === 1 && data.channel != null) { + Channels.increment({ id: data.channel.id }, "usersCount", 1); } }); } // Register to search database - await index(note); + await index(note, false); }); async function renderNoteOrRenoteActivity(data: Option, note: Note) { @@ -649,9 +649,12 @@ async function insertNote( emojis: string[], mentionedUsers: MinimumUser[], ) { + if (data.createdAt === null || data.createdAt === undefined ) { + data.createdAt = new Date(); + } const insert = new Note({ - id: genId(data.createdAt!), - createdAt: data.createdAt!, + id: genId(data.createdAt), + createdAt: data.createdAt, fileIds: data.files ? data.files.map((file) => file.id) : [], replyId: data.reply ? data.reply.id : null, renoteId: data.renote ? data.renote.id : null, @@ -668,7 +671,7 @@ async function insertNote( tags: tags.map((tag) => normalizeForSearch(tag)), emojis, userId: user.id, - localOnly: data.localOnly!, + localOnly: data.localOnly || false, visibility: data.visibility as any, visibleUserIds: data.visibility === "specified"