about summary refs log tree commit diff
path: root/app/javascript/mastodon/containers/mastodon.js
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2021-09-26 05:46:13 +0200
committerGitHub <noreply@github.com>2021-09-26 05:46:13 +0200
commit52e5c07948c4c91b73062846e1f19ea278ec0e24 (patch)
treeb46b76f919f51ad5a5ac288be2ad2565fa859496 /app/javascript/mastodon/containers/mastodon.js
parent9c9290768190d412e5b3d65502ee5d0d30596412 (diff)
Change routing paths to use usernames in web UI (#16171)
Diffstat (limited to 'app/javascript/mastodon/containers/mastodon.js')
-rw-r--r--app/javascript/mastodon/containers/mastodon.js26
1 files changed, 25 insertions, 1 deletions
diff --git a/app/javascript/mastodon/containers/mastodon.js b/app/javascript/mastodon/containers/mastodon.js
index 892ff1ca9..0c3f6afa8 100644
--- a/app/javascript/mastodon/containers/mastodon.js
+++ b/app/javascript/mastodon/containers/mastodon.js
@@ -22,14 +22,38 @@ const hydrateAction = hydrateStore(initialState);
 store.dispatch(hydrateAction);
 store.dispatch(fetchCustomEmojis());
 
+const createIdentityContext = state => ({
+  signedIn: !!state.meta.me,
+  accountId: state.meta.me,
+  accessToken: state.meta.access_token,
+});
+
 export default class Mastodon extends React.PureComponent {
 
   static propTypes = {
     locale: PropTypes.string.isRequired,
   };
 
+  static childContextTypes = {
+    identity: PropTypes.shape({
+      signedIn: PropTypes.bool.isRequired,
+      accountId: PropTypes.string,
+      accessToken: PropTypes.string,
+    }).isRequired,
+  };
+
+  identity = createIdentityContext(initialState);
+
+  getChildContext() {
+    return {
+      identity: this.identity,
+    };
+  }
+
   componentDidMount() {
-    this.disconnect = store.dispatch(connectUserStream());
+    if (this.identity.signedIn) {
+      this.disconnect = store.dispatch(connectUserStream());
+    }
   }
 
   componentWillUnmount () {