about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-11-18 22:04:03 -0600
committermultiple creatures <dev@multiple-creature.party>2019-11-18 22:04:03 -0600
commit5c9fbacaafa0734d1c56762b671d39ba0391bc0b (patch)
treed4427fee31b360d29e702102f14a4a1cfd3a6986 /app/javascript/flavours/glitch
parent8f4f29f7101fd599f166b54a7c06faf782894748 (diff)
Add support for updating posts in-place to the frontend and API. This makes it possible to implement features such as *real* post editing.
Diffstat (limited to 'app/javascript/flavours/glitch')
-rw-r--r--app/javascript/flavours/glitch/actions/importer/index.js3
-rw-r--r--app/javascript/flavours/glitch/actions/importer/normalizer.js7
2 files changed, 7 insertions, 3 deletions
diff --git a/app/javascript/flavours/glitch/actions/importer/index.js b/app/javascript/flavours/glitch/actions/importer/index.js
index f4372fb31..a7a5c60d7 100644
--- a/app/javascript/flavours/glitch/actions/importer/index.js
+++ b/app/javascript/flavours/glitch/actions/importer/index.js
@@ -9,6 +9,9 @@ export const POLLS_IMPORT    = 'POLLS_IMPORT';
 function pushUnique(array, object) {
   if (array.every(element => element.id !== object.id)) {
     array.push(object);
+  } else {
+    const idx = array.findIndex(element => element.id === object.id);
+    array.splice(idx, 1, object);
   }
 }
 
diff --git a/app/javascript/flavours/glitch/actions/importer/normalizer.js b/app/javascript/flavours/glitch/actions/importer/normalizer.js
index 12f8e3395..38d4d389c 100644
--- a/app/javascript/flavours/glitch/actions/importer/normalizer.js
+++ b/app/javascript/flavours/glitch/actions/importer/normalizer.js
@@ -47,9 +47,10 @@ export function normalizeStatus(status, normalOldStatus) {
     normalStatus.poll = status.poll.id;
   }
 
-  // Only calculate these values when status first encountered
-  // Otherwise keep the ones already in the reducer
-  if (normalOldStatus) {
+  const oldUpdatedAt = normalOldStatus ? normalOldStatus.updated_at || normalOldStatus.created_at : null;
+  const newUpdatedAt = normalStatus ? normalStatus.updated_at || normalStatus.created_at : null;
+
+  if (normalOldStatus && oldUpdatedAt === newUpdatedAt) {
     normalStatus.search_index = normalOldStatus.get('search_index');
     normalStatus.contentHtml = normalOldStatus.get('contentHtml');
     normalStatus.spoilerHtml = normalOldStatus.get('spoilerHtml');