about summary refs log tree commit diff
path: root/app/javascript/mastodon/actions/server.js
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2022-10-05 03:47:56 +0200
committerGitHub <noreply@github.com>2022-10-05 03:47:56 +0200
commitd2528b26b6da34f34b5d7a392e263428d3c09d69 (patch)
tree142ace2915a143d61b852e479603726e8d7e2675 /app/javascript/mastodon/actions/server.js
parentcedcece0ccba626d97a910f2e3fecf93c2729ca4 (diff)
Add server banner to web app, add `GET /api/v2/instance` to REST API (#19294)
Diffstat (limited to 'app/javascript/mastodon/actions/server.js')
-rw-r--r--app/javascript/mastodon/actions/server.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/app/javascript/mastodon/actions/server.js b/app/javascript/mastodon/actions/server.js
new file mode 100644
index 000000000..af8fef780
--- /dev/null
+++ b/app/javascript/mastodon/actions/server.js
@@ -0,0 +1,30 @@
+import api from '../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,
+});