about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/actions
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2019-03-06 12:20:17 +0100
committerGitHub <noreply@github.com>2019-03-06 12:20:17 +0100
commitfefacb7b7a21fc4aa40cb18ac797ecb5c44627f6 (patch)
tree7c4dbacf4603fd834da1bf8645b894634da06d4f /app/javascript/flavours/glitch/actions
parente80fabfd84c1e2d157ca1cd536f68f3c75f011c1 (diff)
parent94a0149ff3e455792050e790d397d1d4d2c2d851 (diff)
Merge pull request #939 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/javascript/flavours/glitch/actions')
-rw-r--r--app/javascript/flavours/glitch/actions/importer/index.js10
-rw-r--r--app/javascript/flavours/glitch/actions/importer/normalizer.js11
-rw-r--r--app/javascript/flavours/glitch/actions/polls.js11
3 files changed, 28 insertions, 4 deletions
diff --git a/app/javascript/flavours/glitch/actions/importer/index.js b/app/javascript/flavours/glitch/actions/importer/index.js
index abadee817..f4372fb31 100644
--- a/app/javascript/flavours/glitch/actions/importer/index.js
+++ b/app/javascript/flavours/glitch/actions/importer/index.js
@@ -1,4 +1,4 @@
-import { normalizeAccount, normalizeStatus } from './normalizer';
+import { normalizeAccount, normalizeStatus, normalizePoll } from './normalizer';
 
 export const ACCOUNT_IMPORT  = 'ACCOUNT_IMPORT';
 export const ACCOUNTS_IMPORT = 'ACCOUNTS_IMPORT';
@@ -71,7 +71,7 @@ export function importFetchedStatuses(statuses) {
       }
 
       if (status.poll && status.poll.id) {
-        pushUnique(polls, status.poll);
+        pushUnique(polls, normalizePoll(status.poll));
       }
     }
 
@@ -82,3 +82,9 @@ export function importFetchedStatuses(statuses) {
     dispatch(importStatuses(normalStatuses));
   };
 }
+
+export function importFetchedPoll(poll) {
+  return dispatch => {
+    dispatch(importPolls([normalizePoll(poll)]));
+  };
+}
diff --git a/app/javascript/flavours/glitch/actions/importer/normalizer.js b/app/javascript/flavours/glitch/actions/importer/normalizer.js
index f57fb70b4..ccd84364e 100644
--- a/app/javascript/flavours/glitch/actions/importer/normalizer.js
+++ b/app/javascript/flavours/glitch/actions/importer/normalizer.js
@@ -65,3 +65,14 @@ export function normalizeStatus(status, normalOldStatus) {
 
   return normalStatus;
 }
+
+export function normalizePoll(poll) {
+  const normalPoll = { ...poll };
+
+  normalPoll.options = poll.options.map(option => ({
+    ...option,
+    title_emojified: emojify(escapeTextContentForBrowser(option.title)),
+  }));
+
+  return normalPoll;
+}
diff --git a/app/javascript/flavours/glitch/actions/polls.js b/app/javascript/flavours/glitch/actions/polls.js
index bee4c48a6..8e8b82df5 100644
--- a/app/javascript/flavours/glitch/actions/polls.js
+++ b/app/javascript/flavours/glitch/actions/polls.js
@@ -1,4 +1,5 @@
 import api from '../api';
+import { importFetchedPoll } from './importer';
 
 export const POLL_VOTE_REQUEST = 'POLL_VOTE_REQUEST';
 export const POLL_VOTE_SUCCESS = 'POLL_VOTE_SUCCESS';
@@ -12,7 +13,10 @@ export const vote = (pollId, choices) => (dispatch, getState) => {
   dispatch(voteRequest());
 
   api(getState).post(`/api/v1/polls/${pollId}/votes`, { choices })
-    .then(({ data }) => dispatch(voteSuccess(data)))
+    .then(({ data }) => {
+      dispatch(importFetchedPoll(data));
+      dispatch(voteSuccess(data));
+    })
     .catch(err => dispatch(voteFail(err)));
 };
 
@@ -20,7 +24,10 @@ export const fetchPoll = pollId => (dispatch, getState) => {
   dispatch(fetchPollRequest());
 
   api(getState).get(`/api/v1/polls/${pollId}`)
-    .then(({ data }) => dispatch(fetchPollSuccess(data)))
+    .then(({ data }) => {
+      dispatch(importFetchedPoll(data));
+      dispatch(fetchPollSuccess(data));
+    })
     .catch(err => dispatch(fetchPollFail(err)));
 };