From a3d88eba4e3bd25b66d859b97b8e8442a51a03be Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 4 Jun 2019 12:12:15 +0200 Subject: [PATCH] MOBILE-3039 forum: Fix attachments not downloaded on prefetch --- .../mod/forum/providers/prefetch-handler.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/addon/mod/forum/providers/prefetch-handler.ts b/src/addon/mod/forum/providers/prefetch-handler.ts index 04e3289f8..6241dce19 100644 --- a/src/addon/mod/forum/providers/prefetch-handler.ts +++ b/src/addon/mod/forum/providers/prefetch-handler.ts @@ -122,7 +122,24 @@ export class AddonModForumPrefetchHandler extends CoreCourseActivityPrefetchHand }); }); - return Promise.all(promises); + return Promise.all(promises).then((results) => { + // Each order has returned its own list of posts. Merge all the lists, preventing duplicates. + const posts = [], + postIds = {}; // To make the array unique. + + results.forEach((orderResults) => { + orderResults.forEach((orderResult) => { + orderResult.posts.forEach((post) => { + if (!postIds[post.id]) { + postIds[post.id] = true; + posts.push(post); + } + }); + }); + }); + + return posts; + }); } /**