From 154c74ec13eb25c02f4bef7cebec870f139ea2f0 Mon Sep 17 00:00:00 2001 From: igoradamenko Date: Thu, 3 May 2018 00:39:27 +0300 Subject: [PATCH] fix search for pinned comments --- web/app/common/store.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/web/app/common/store.js b/web/app/common/store.js index f54e2889..0f033f24 100644 --- a/web/app/common/store.js +++ b/web/app/common/store.js @@ -115,11 +115,17 @@ class Store { } function findPinnedComments(thread) { - if (thread.comment.pin) return [thread.comment]; + let result = []; - if (thread.replies) return thread.replies.reduce((acc, thread) => findPinnedComments(thread), []); + if (thread.comment.pin) { + result = result.concat(thread.comment); + } - return []; + if (thread.replies) { + result = result.concat(thread.replies.reduce((acc, thread) => acc.concat(findPinnedComments(thread)), [])); + } + + return result; } export default new Store();