From 8979b709750493763368bca9b2fac79902086f48 Mon Sep 17 00:00:00 2001
From: Eugen Rochko <eugen@zeonfederated.com>
Date: Fri, 28 Apr 2023 10:05:34 +0200
Subject: [PATCH] Add default post text to onboarding flow in web UI (#24705)

---
 app/javascript/mastodon/actions/compose.js           |  3 ++-
 .../mastodon/features/onboarding/index.jsx           | 12 ++++++++----
 app/javascript/mastodon/locales/defaultMessages.json |  4 ++++
 app/javascript/mastodon/locales/en.json              |  1 +
 app/javascript/mastodon/reducers/compose.js          |  2 +-
 5 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/app/javascript/mastodon/actions/compose.js b/app/javascript/mastodon/actions/compose.js
index b7c9e6357..f4cd2d04d 100644
--- a/app/javascript/mastodon/actions/compose.js
+++ b/app/javascript/mastodon/actions/compose.js
@@ -126,9 +126,10 @@ export function resetCompose() {
   };
 }
 
-export const focusCompose = routerHistory => dispatch => {
+export const focusCompose = (routerHistory, defaultText) => dispatch => {
   dispatch({
     type: COMPOSE_FOCUS,
+    defaultText,
   });
 
   ensureComposeIsVisible(routerHistory);
diff --git a/app/javascript/mastodon/features/onboarding/index.jsx b/app/javascript/mastodon/features/onboarding/index.jsx
index 5980ba0d0..388734055 100644
--- a/app/javascript/mastodon/features/onboarding/index.jsx
+++ b/app/javascript/mastodon/features/onboarding/index.jsx
@@ -16,9 +16,13 @@ import Follows from './follows';
 import Share from './share';
 import Step from './components/step';
 import ArrowSmallRight from './components/arrow_small_right';
-import { FormattedMessage } from 'react-intl';
+import { FormattedMessage, injectIntl, defineMessages } from 'react-intl';
 import { debounce } from 'lodash';
 
+const messages = defineMessages({
+  template: { id: 'onboarding.compose.template', defaultMessage: 'Hello #Mastodon!' },
+});
+
 const mapStateToProps = () => {
   const getAccount = makeGetAccount();
 
@@ -61,10 +65,10 @@ class Onboarding extends ImmutablePureComponent {
   };
 
   handleComposeClick = () => {
-    const { dispatch } = this.props;
+    const { dispatch, intl } = this.props;
     const { router } = this.context;
 
-    dispatch(focusCompose(router.history));
+    dispatch(focusCompose(router.history, intl.formatMessage(messages.template)));
   };
 
   handleShareClick = () => {
@@ -138,4 +142,4 @@ class Onboarding extends ImmutablePureComponent {
 
 }
 
-export default connect(mapStateToProps)(Onboarding);
+export default connect(mapStateToProps)(injectIntl(Onboarding));
diff --git a/app/javascript/mastodon/locales/defaultMessages.json b/app/javascript/mastodon/locales/defaultMessages.json
index b910f2a85..a735d2ff3 100644
--- a/app/javascript/mastodon/locales/defaultMessages.json
+++ b/app/javascript/mastodon/locales/defaultMessages.json
@@ -3211,6 +3211,10 @@
   },
   {
     "descriptors": [
+      {
+        "defaultMessage": "Hello #Mastodon!",
+        "id": "onboarding.compose.template"
+      },
       {
         "defaultMessage": "You've made it!",
         "id": "onboarding.start.title"
diff --git a/app/javascript/mastodon/locales/en.json b/app/javascript/mastodon/locales/en.json
index 0220f67eb..85040bf5b 100644
--- a/app/javascript/mastodon/locales/en.json
+++ b/app/javascript/mastodon/locales/en.json
@@ -445,6 +445,7 @@
   "onboarding.actions.close": "Don't show this screen again",
   "onboarding.actions.go_to_explore": "See what's trending",
   "onboarding.actions.go_to_home": "Go to your home feed",
+  "onboarding.compose.template": "Hello #Mastodon!",
   "onboarding.follows.empty": "Unfortunately, no results can be shown right now. You can try using search or browsing the explore page to find people to follow, or try again later.",
   "onboarding.follows.lead": "You curate your own home feed. The more people you follow, the more active and interesting it will be. These profiles may be a good starting point—you can always unfollow them later!",
   "onboarding.follows.title": "Popular on Mastodon",
diff --git a/app/javascript/mastodon/reducers/compose.js b/app/javascript/mastodon/reducers/compose.js
index 11549cb39..65f439e03 100644
--- a/app/javascript/mastodon/reducers/compose.js
+++ b/app/javascript/mastodon/reducers/compose.js
@@ -528,7 +528,7 @@ export default function compose(state = initialState, action) {
   case COMPOSE_LANGUAGE_CHANGE:
     return state.set('language', action.language);
   case COMPOSE_FOCUS:
-    return state.set('focusDate', new Date());
+    return state.set('focusDate', new Date()).update('text', text => text.length > 0 ? text : action.defaultText);
   default:
     return state;
   }