about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/actions
diff options
context:
space:
mode:
Diffstat (limited to 'app/javascript/flavours/glitch/actions')
-rw-r--r--app/javascript/flavours/glitch/actions/accounts.js6
-rw-r--r--app/javascript/flavours/glitch/actions/markers.js10
-rw-r--r--app/javascript/flavours/glitch/actions/push_notifications/index.js26
-rw-r--r--app/javascript/flavours/glitch/actions/rules.js27
-rw-r--r--app/javascript/flavours/glitch/actions/server.js30
5 files changed, 50 insertions, 49 deletions
diff --git a/app/javascript/flavours/glitch/actions/accounts.js b/app/javascript/flavours/glitch/actions/accounts.js
index f5871beb3..750740879 100644
--- a/app/javascript/flavours/glitch/actions/accounts.js
+++ b/app/javascript/flavours/glitch/actions/accounts.js
@@ -553,10 +553,12 @@ export function expandFollowingFail(id, error) {
 
 export function fetchRelationships(accountIds) {
   return (dispatch, getState) => {
-    const loadedRelationships = getState().get('relationships');
+    const state = getState();
+    const loadedRelationships = state.get('relationships');
     const newAccountIds = accountIds.filter(id => loadedRelationships.get(id, null) === null);
+    const signedIn = !!state.getIn(['meta', 'me']);
 
-    if (newAccountIds.length === 0) {
+    if (!signedIn || newAccountIds.length === 0) {
       return;
     }
 
diff --git a/app/javascript/flavours/glitch/actions/markers.js b/app/javascript/flavours/glitch/actions/markers.js
index a086def97..6a0549f7f 100644
--- a/app/javascript/flavours/glitch/actions/markers.js
+++ b/app/javascript/flavours/glitch/actions/markers.js
@@ -1,6 +1,7 @@
 import api from 'flavours/glitch/util/api';
 import { debounce } from 'lodash';
 import compareId from 'flavours/glitch/util/compare_id';
+import { List as ImmutableList } from 'immutable';
 
 export const MARKERS_FETCH_REQUEST = 'MARKERS_FETCH_REQUEST';
 export const MARKERS_FETCH_SUCCESS = 'MARKERS_FETCH_SUCCESS';
@@ -11,7 +12,7 @@ export const synchronouslySubmitMarkers = () => (dispatch, getState) => {
   const accessToken = getState().getIn(['meta', 'access_token'], '');
   const params      = _buildParams(getState());
 
-  if (Object.keys(params).length === 0) {
+  if (Object.keys(params).length === 0 || accessToken === '') {
     return;
   }
 
@@ -63,7 +64,7 @@ export const synchronouslySubmitMarkers = () => (dispatch, getState) => {
 const _buildParams = (state) => {
   const params = {};
 
-  const lastHomeId         = state.getIn(['timelines', 'home', 'items']).find(item => item !== null);
+  const lastHomeId         = state.getIn(['timelines', 'home', 'items'], ImmutableList()).find(item => item !== null);
   const lastNotificationId = state.getIn(['notifications', 'lastReadId']);
 
   if (lastHomeId && compareId(lastHomeId, state.getIn(['markers', 'home'])) > 0) {
@@ -82,9 +83,10 @@ const _buildParams = (state) => {
 };
 
 const debouncedSubmitMarkers = debounce((dispatch, getState) => {
-  const params = _buildParams(getState());
+  const accessToken = getState().getIn(['meta', 'access_token'], '');
+  const params      = _buildParams(getState());
 
-  if (Object.keys(params).length === 0) {
+  if (Object.keys(params).length === 0 || accessToken === '') {
     return;
   }
 
diff --git a/app/javascript/flavours/glitch/actions/push_notifications/index.js b/app/javascript/flavours/glitch/actions/push_notifications/index.js
index 2ffec500a..9dcc4bd4b 100644
--- a/app/javascript/flavours/glitch/actions/push_notifications/index.js
+++ b/app/javascript/flavours/glitch/actions/push_notifications/index.js
@@ -1,19 +1,5 @@
-import {
-  SET_BROWSER_SUPPORT,
-  SET_SUBSCRIPTION,
-  CLEAR_SUBSCRIPTION,
-  SET_ALERTS,
-  setAlerts,
-} from './setter';
-import { register, saveSettings } from './registerer';
-
-export {
-  SET_BROWSER_SUPPORT,
-  SET_SUBSCRIPTION,
-  CLEAR_SUBSCRIPTION,
-  SET_ALERTS,
-  register,
-};
+import { setAlerts } from './setter';
+import { saveSettings } from './registerer';
 
 export function changeAlerts(path, value) {
   return dispatch => {
@@ -21,3 +7,11 @@ export function changeAlerts(path, value) {
     dispatch(saveSettings());
   };
 }
+
+export {
+  CLEAR_SUBSCRIPTION,
+  SET_BROWSER_SUPPORT,
+  SET_SUBSCRIPTION,
+  SET_ALERTS,
+} from './setter';
+export { register } from './registerer';
diff --git a/app/javascript/flavours/glitch/actions/rules.js b/app/javascript/flavours/glitch/actions/rules.js
deleted file mode 100644
index b95045e81..000000000
--- a/app/javascript/flavours/glitch/actions/rules.js
+++ /dev/null
@@ -1,27 +0,0 @@
-import api from 'flavours/glitch/util/api';
-
-export const RULES_FETCH_REQUEST = 'RULES_FETCH_REQUEST';
-export const RULES_FETCH_SUCCESS = 'RULES_FETCH_SUCCESS';
-export const RULES_FETCH_FAIL    = 'RULES_FETCH_FAIL';
-
-export const fetchRules = () => (dispatch, getState) => {
-  dispatch(fetchRulesRequest());
-
-  api(getState)
-    .get('/api/v1/instance').then(({ data }) => dispatch(fetchRulesSuccess(data.rules)))
-    .catch(err => dispatch(fetchRulesFail(err)));
-};
-
-const fetchRulesRequest = () => ({
-  type: RULES_FETCH_REQUEST,
-});
-
-const fetchRulesSuccess = rules => ({
-  type: RULES_FETCH_SUCCESS,
-  rules,
-});
-
-const fetchRulesFail = error => ({
-  type: RULES_FETCH_FAIL,
-  error,
-});
diff --git a/app/javascript/flavours/glitch/actions/server.js b/app/javascript/flavours/glitch/actions/server.js
new file mode 100644
index 000000000..215dfeffa
--- /dev/null
+++ b/app/javascript/flavours/glitch/actions/server.js
@@ -0,0 +1,30 @@
+import api from 'flavours/glitch/util/api';
+import { importFetchedAccount } from './importer';
+
+export const SERVER_FETCH_REQUEST = 'Server_FETCH_REQUEST';
+export const SERVER_FETCH_SUCCESS = 'Server_FETCH_SUCCESS';
+export const SERVER_FETCH_FAIL    = 'Server_FETCH_FAIL';
+
+export const fetchServer = () => (dispatch, getState) => {
+  dispatch(fetchServerRequest());
+
+  api(getState)
+    .get('/api/v2/instance').then(({ data }) => {
+      if (data.contact.account) dispatch(importFetchedAccount(data.contact.account));
+      dispatch(fetchServerSuccess(data));
+    }).catch(err => dispatch(fetchServerFail(err)));
+};
+
+const fetchServerRequest = () => ({
+  type: SERVER_FETCH_REQUEST,
+});
+
+const fetchServerSuccess = server => ({
+  type: SERVER_FETCH_SUCCESS,
+  server,
+});
+
+const fetchServerFail = error => ({
+  type: SERVER_FETCH_FAIL,
+  error,
+});