From 93a889df82f005e17fce6f7e6fc7d9d7554e7719 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Fri, 1 Nov 2019 05:46:20 +0900 Subject: [PATCH] Preserve the attached order in AP (#5561) * Preserve the attached order in AP * Revert "Preserve the attached order in AP" This reverts commit 8ac09cc81b1c216edccd2eba4bbdf0a194320883. * use IN --- src/remote/activitypub/renderer/note.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/remote/activitypub/renderer/note.ts b/src/remote/activitypub/renderer/note.ts index d58e1de43..31d67edba 100644 --- a/src/remote/activitypub/renderer/note.ts +++ b/src/remote/activitypub/renderer/note.ts @@ -13,9 +13,11 @@ import { Poll } from '../../../models/entities/poll'; import { ensure } from '../../../prelude/ensure'; export default async function renderNote(note: Note, dive = true, isTalk = false): Promise { - const promisedFiles: Promise = note.fileIds.length > 0 - ? DriveFiles.find({ id: In(note.fileIds) }) - : Promise.resolve([]); + const getPromisedFiles = async (ids: string[]) => { + if (!ids || ids.length === 0) return []; + const items = await DriveFiles.find({ id: In(ids) }); + return ids.map(id => items.find(item => item.id === id)).filter(item => item != null) as DriveFile[]; + }; let inReplyTo; let inReplyToNote: Note | undefined; @@ -81,7 +83,7 @@ export default async function renderNote(note: Note, dive = true, isTalk = false const hashtagTags = (note.tags || []).map(tag => renderHashtag(tag)); const mentionTags = mentionedUsers.map(u => renderMention(u)); - const files = await promisedFiles; + const files = await getPromisedFiles(note.fileIds); let text = note.text; let poll: Poll | undefined;