about summary refs log tree commit diff
path: root/app/javascript/mastodon/actions/timelines.js
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-10-04 01:01:44 +0200
committerGitHub <noreply@github.com>2017-10-04 01:01:44 +0200
commitec13cfa4f940e9f9441ceff1f7389bb0e1bd61fb (patch)
treee0addcd57333d15e06e741fbb548400a73e37271 /app/javascript/mastodon/actions/timelines.js
parentcdd5ef691bcdb25f8c8367698de7e09301ee3528 (diff)
When a streaming API status arrives, sort it into conversations (#5206)
Diffstat (limited to 'app/javascript/mastodon/actions/timelines.js')
-rw-r--r--app/javascript/mastodon/actions/timelines.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/app/javascript/mastodon/actions/timelines.js b/app/javascript/mastodon/actions/timelines.js
index 5c0cd93c7..cdaafd89c 100644
--- a/app/javascript/mastodon/actions/timelines.js
+++ b/app/javascript/mastodon/actions/timelines.js
@@ -17,6 +17,8 @@ export const TIMELINE_SCROLL_TOP = 'TIMELINE_SCROLL_TOP';
 export const TIMELINE_CONNECT    = 'TIMELINE_CONNECT';
 export const TIMELINE_DISCONNECT = 'TIMELINE_DISCONNECT';
 
+export const TIMELINE_CONTEXT_UPDATE = 'CONTEXT_UPDATE';
+
 export function refreshTimelineSuccess(timeline, statuses, skipLoading, next) {
   return {
     type: TIMELINE_REFRESH_SUCCESS,
@@ -30,6 +32,16 @@ export function refreshTimelineSuccess(timeline, statuses, skipLoading, next) {
 export function updateTimeline(timeline, status) {
   return (dispatch, getState) => {
     const references = status.reblog ? getState().get('statuses').filter((item, itemId) => (itemId === status.reblog.id || item.get('reblog') === status.reblog.id)).map((_, itemId) => itemId) : [];
+    const parents = [];
+
+    if (status.in_reply_to_id) {
+      let parent = getState().getIn(['statuses', status.in_reply_to_id]);
+
+      while (parent.get('in_reply_to_id')) {
+        parents.push(parent.get('id'));
+        parent = getState().getIn(['statuses', parent.get('in_reply_to_id')]);
+      }
+    }
 
     dispatch({
       type: TIMELINE_UPDATE,
@@ -37,6 +49,14 @@ export function updateTimeline(timeline, status) {
       status,
       references,
     });
+
+    if (parents.length > 0) {
+      dispatch({
+        type: TIMELINE_CONTEXT_UPDATE,
+        status,
+        references: parents,
+      });
+    }
   };
 };