about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2018-11-30 12:24:12 +0100
committerThibG <thib@sitedethib.com>2018-11-30 22:37:38 +0100
commit837ea32c88f75cac4a83f4449161e0d2d81a6cd2 (patch)
tree00e1334e7cbbff9e247ebb7f94cfda203486a089 /app
parenta28f5695f3d639fcbae1e73c85acd79ac088ca54 (diff)
[Glitch] Replace recursion in status mapStateToProps
Port dfbadd68374ab5ddcaa75907261bd91da688fc6b to glitch-soc
Diffstat (limited to 'app')
-rw-r--r--app/javascript/flavours/glitch/features/status/index.js21
1 files changed, 9 insertions, 12 deletions
diff --git a/app/javascript/flavours/glitch/features/status/index.js b/app/javascript/flavours/glitch/features/status/index.js
index 2ce6a9281..c1ff5513a 100644
--- a/app/javascript/flavours/glitch/features/status/index.js
+++ b/app/javascript/flavours/glitch/features/status/index.js
@@ -65,31 +65,28 @@ const makeMapStateToProps = () => {
 
     if (status) {
       ancestorsIds = ancestorsIds.withMutations(mutable => {
-        function addAncestor(id) {
-          if (id) {
-            const inReplyTo = state.getIn(['contexts', 'inReplyTos', id]);
+        let id = status.get('in_reply_to_id');
 
-            mutable.unshift(id);
-            addAncestor(inReplyTo);
-          }
+        while (id) {
+          mutable.unshift(id);
+          id = state.getIn(['contexts', 'inReplyTos', id]);
         }
-
-        addAncestor(status.get('in_reply_to_id'));
       });
 
       descendantsIds = descendantsIds.withMutations(mutable => {
-        function addDescendantOf(id) {
+        const ids = [status.get('id')];
+
+        while (ids.length > 0) {
+          let id        = ids.shift();
           const replies = state.getIn(['contexts', 'replies', id]);
 
           if (replies) {
             replies.forEach(reply => {
               mutable.push(reply);
-              addDescendantOf(reply);
+              ids.unshift(reply);
             });
           }
         }
-
-        addDescendantOf(status.get('id'));
       });
     }