]> cat aescling's git repositories - mastodon.git/commitdiff
Add own composed status to home without waiting for websocket event
authorEugen Rochko <eugen@zeonfederated.com>
Thu, 3 Nov 2016 10:06:55 +0000 (11:06 +0100)
committerEugen Rochko <eugen@zeonfederated.com>
Thu, 3 Nov 2016 10:06:55 +0000 (11:06 +0100)
This makes the UI appear less laggy. After all, the status *is* created
right there and then, it's the distribution to home timelines that can take
a while

app/assets/javascripts/components/actions/compose.jsx
app/assets/javascripts/components/reducers/timelines.jsx

index b576c744469d589d7ca54e5c4c07908886476824..228469df18ba450901d268c73bb578fd75fa88c6 100644 (file)
@@ -1,5 +1,7 @@
 import api from '../api'
 
+import { updateTimeline } from './timelines';
+
 export const COMPOSE_CHANGE          = 'COMPOSE_CHANGE';
 export const COMPOSE_SUBMIT_REQUEST  = 'COMPOSE_SUBMIT_REQUEST';
 export const COMPOSE_SUBMIT_SUCCESS  = 'COMPOSE_SUBMIT_SUCCESS';
@@ -66,9 +68,13 @@ export function submitComposeRequest() {
 };
 
 export function submitComposeSuccess(status) {
-  return {
-    type: COMPOSE_SUBMIT_SUCCESS,
-    status: status
+  return (dispatch, getState) => {
+    dispatch({
+      type: COMPOSE_SUBMIT_SUCCESS,
+      status: status
+    });
+
+    dispatch(updateTimeline('home', status));
   };
 };
 
index db13cad313009b6e362c3c313786dc9d314c46bc..c12d1b70ddc4e6dc5dfdd6155064461db26a32d4 100644 (file)
@@ -95,6 +95,10 @@ const updateTimeline = (state, timeline, status, references) => {
   state = normalizeStatus(state, status);
 
   state = state.update(timeline, list => {
+    if (list.includes(status.get('id'))) {
+      return list;
+    }
+
     const reblogOfId = status.getIn(['reblog', 'id'], null);
 
     if (reblogOfId !== null) {