From cf295c18fe68e444b35d5369bc995da3eb14c3a1 Mon Sep 17 00:00:00 2001 From: igoradamenko Date: Tue, 13 Feb 2018 00:31:00 +0200 Subject: [PATCH] add getPinnedComments method to store --- web/app/common/store.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/web/app/common/store.js b/web/app/common/store.js index 88349d43..add98f3a 100644 --- a/web/app/common/store.js +++ b/web/app/common/store.js @@ -96,6 +96,18 @@ class Store { this.data.comments = this.data.comments.map(thread => replace(thread, newComment)); } + + getPinnedComments() { + return this.data.comments.reduce((acc, thread) => acc.concat(findPinnedComments(thread)), []); + } +} + +function findPinnedComments(thread) { + if (thread.comment.pin) return [thread.comment]; + + if (thread.replies) return thread.replies.reduce((acc, thread) => findPinnedComments(thread), []); + + return []; } export default new Store();