Narrow type of isPureRenote

As side effect of that, a non-null assertion can be removed.

Co-authored-by: Johann150 <johann.galle@protonmail.com>
This commit is contained in:
Michcio 2022-09-25 15:33:29 +02:00 committed by Johann150
parent 47b2f619a6
commit c282ed7683
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1
2 changed files with 2 additions and 6 deletions

View file

@ -1,5 +1,5 @@
import { Note } from '@/models/entities/note.js';
export function isPureRenote(note: Note): boolean {
export function isPureRenote(note: Note): note is Note & { renoteId: string, text: null, fileIds: null | never[], hasPoll: false } {
return note.renoteId != null && note.text == null && (note.fileIds == null || note.fileIds.length === 0) && !note.hasPoll;
}

View file

@ -43,11 +43,7 @@ export default async function(user: { id: User['id']; uri: User['uri']; host: Us
// if deleted note is renote
if (isPureRenote(note)) {
renote = await Notes.findOneBy({
// isPureRenote checks if note.renoteId is null already, so renoteId should be non-null.
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
id: note.renoteId!,
});
renote = await Notes.findOneBy({ id: note.renoteId });
}
const content = renderActivity(renote