From 45fb596539472dc7c999eb3a4e30f87fa815664c Mon Sep 17 00:00:00 2001
From: sneakers-the-rat <sneakers-the-rat@protonmail.com>
Date: Sat, 31 Aug 2024 22:33:56 -0700
Subject: [PATCH] move account_css to account header component, fix css change
 on navigation

---
 .../flavours/glitch/api_types/accounts.ts     |  1 +
 .../features/account/components/header.jsx    |  9 ++++-
 .../flavours/glitch/models/account.ts         | 39 ++++++++++++++++++-
 .../styles/neuromatchstodon/myspace.scss      |  1 +
 app/serializers/rest/account_serializer.rb    |  3 +-
 app/views/accounts/show.html.haml             |  4 --
 6 files changed, 49 insertions(+), 8 deletions(-)

diff --git a/app/javascript/flavours/glitch/api_types/accounts.ts b/app/javascript/flavours/glitch/api_types/accounts.ts
index 5bf3e64288c76e..d6dada067b6678 100644
--- a/app/javascript/flavours/glitch/api_types/accounts.ts
+++ b/app/javascript/flavours/glitch/api_types/accounts.ts
@@ -44,4 +44,5 @@ export interface ApiAccountJSON {
   limited?: boolean;
   memorial?: boolean;
   hide_collections: boolean;
+  account_css?: string;
 }
diff --git a/app/javascript/flavours/glitch/features/account/components/header.jsx b/app/javascript/flavours/glitch/features/account/components/header.jsx
index 62c8c84c66eafa..d504ff260cf174 100644
--- a/app/javascript/flavours/glitch/features/account/components/header.jsx
+++ b/app/javascript/flavours/glitch/features/account/components/header.jsx
@@ -3,8 +3,8 @@ import PropTypes from 'prop-types';
 import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
 
 import classNames from 'classnames';
-import { Helmet } from 'react-helmet';
-import { withRouter } from 'react-router-dom';
+import {Helmet} from 'react-helmet';
+import {withRouter} from 'react-router-dom';
 
 import ImmutablePropTypes from 'react-immutable-proptypes';
 import ImmutablePureComponent from 'react-immutable-pure-component';
@@ -405,6 +405,11 @@ class Header extends ImmutablePureComponent {
           <title>{titleFromAccount(account)}</title>
           <meta name='robots' content={(isLocal && isIndexable) ? 'all' : 'noindex'} />
           <link rel='canonical' href={account.get('url')} />
+          {account.account_css && (
+            <style id={"account-css"} nonce={document.querySelector('meta[name=style-nonce]').content}>
+              {account.account_css}
+            </style>
+          )}
         </Helmet>
       </div>
     );
diff --git a/app/javascript/flavours/glitch/models/account.ts b/app/javascript/flavours/glitch/models/account.ts
index 0b698ead3d1930..6ad2e779e53012 100644
--- a/app/javascript/flavours/glitch/models/account.ts
+++ b/app/javascript/flavours/glitch/models/account.ts
@@ -60,7 +60,43 @@ export interface AccountShape
 
 export type Account = RecordOf<AccountShape>;
 
-export const accountDefaultValues: AccountShape = {
+export const accountDefaultValues: {
+  note: string;
+  hidden: boolean;
+  bot: boolean;
+  roles: Immutable.List<AccountRole>;
+  moved: null;
+  indexable: boolean;
+  created_at: string;
+  header_static: string;
+  account_css: string;
+  hide_collections: boolean;
+  id: string;
+  memorial: boolean;
+  locked: boolean;
+  display_name_html: string;
+  group: boolean;
+  emojis: Immutable.List<CustomEmoji>;
+  noindex: boolean;
+  limited: boolean;
+  avatar: string;
+  display_name: string;
+  note_plain: string;
+  uri: string;
+  url: string;
+  suspended: boolean;
+  following_count: number;
+  discoverable: boolean;
+  last_status_at: string;
+  statuses_count: number;
+  followers_count: number;
+  note_emojified: string;
+  header: string;
+  avatar_static: string;
+  fields: Immutable.List<AccountField>;
+  acct: string;
+  username: string;
+} = {
   acct: '',
   avatar: '',
   avatar_static: '',
@@ -95,6 +131,7 @@ export const accountDefaultValues: AccountShape = {
   limited: false,
   moved: null,
   hide_collections: false,
+  account_css: '',
 };
 
 const AccountFactory = ImmutableRecord<AccountShape>(accountDefaultValues);
diff --git a/app/javascript/flavours/glitch/styles/neuromatchstodon/myspace.scss b/app/javascript/flavours/glitch/styles/neuromatchstodon/myspace.scss
index 62b2b1c4dc42b9..7bcb775aa1a9b9 100644
--- a/app/javascript/flavours/glitch/styles/neuromatchstodon/myspace.scss
+++ b/app/javascript/flavours/glitch/styles/neuromatchstodon/myspace.scss
@@ -1,3 +1,4 @@
 #account_account_css {
   font-family: $font-monospace;
+  height: 15em;
 }
diff --git a/app/serializers/rest/account_serializer.rb b/app/serializers/rest/account_serializer.rb
index a10d6988817370..dbaa15944b5e28 100644
--- a/app/serializers/rest/account_serializer.rb
+++ b/app/serializers/rest/account_serializer.rb
@@ -8,7 +8,8 @@ class REST::AccountSerializer < ActiveModel::Serializer
 
   attributes :id, :username, :acct, :display_name, :locked, :bot, :discoverable, :indexable, :group, :created_at,
              :note, :url, :uri, :avatar, :avatar_static, :header, :header_static,
-             :followers_count, :following_count, :statuses_count, :last_status_at, :hide_collections
+             :followers_count, :following_count, :statuses_count, :last_status_at, :hide_collections,
+             :account_css
 
   has_one :moved_to_account, key: :moved, serializer: REST::AccountSerializer, if: :moved_and_not_nested?
 
diff --git a/app/views/accounts/show.html.haml b/app/views/accounts/show.html.haml
index d7ca2037e776ef..dde9c508474901 100644
--- a/app/views/accounts/show.html.haml
+++ b/app/views/accounts/show.html.haml
@@ -11,10 +11,6 @@
   - @account.fields.select(&:verifiable?).each do |field|
     %link{ rel: 'me', type: 'text/html', href: field.value }/
 
-  - if @account.account_css?
-    %style{ nonce: request.content_security_policy_nonce }
-      = @account.account_css
-
   = opengraph 'og:type', 'profile'
   = render 'og', account: @account, url: short_account_url(@account, only_path: false)