Skip to content

Instantly share code, notes, and snippets.

@flaki
Created March 5, 2023 22:24
Show Gist options
  • Save flaki/1947721752732906d325a06f9c2c8138 to your computer and use it in GitHub Desktop.
Save flaki/1947721752732906d325a06f9c2c8138 to your computer and use it in GitHub Desktop.
Patch Mastodon to allow more than 500 characters for toots
#!/bin/sh
STATUS_MAX_CHARS=1000
# Enable > 500 characters in the toot composer of the web interface
COMPOSEROOT=/opt/mastodon/app/javascript/mastodon/features/compose/components
if [ -e $COMPOSEROOT/compose_form.js ]; then
# Sets the custom limit
cat <<EOF > $COMPOSEROOT/compose_max.js
export default $STATUS_MAX_CHARS;
EOF
# Show import
cat $COMPOSEROOT/compose_max.js
# Adds the import to compose_form
# replaces 'length(fulltext) > 500' & 'CharacterCounter max={500}' with COMPOSE_MAX
sed -i.default \
-e '1i\' \
-e "import COMPOSE_MAX from './compose_max';" \
-e 's/\(length(fulltext) > \)500/\1COMPOSE_MAX/' \
-e 's/\(CharacterCounter max={\)500\(}\)/\1COMPOSE_MAX\2/' \
$COMPOSEROOT/compose_form.js
# Show result
diff --color=always $COMPOSEROOT/compose_form.js.default $COMPOSEROOT/compose_form.js
fi
# Enable > 500 characters in the serverside validator
# (will also update the instance configuration reported via the API)
VALIDATORROOT=/opt/mastodon/app/validators
if [ -e $VALIDATORROOT/status_length_validator.rb ]; then
# Updates MAX_CHARS in the validator
sed -i.default \
-e "s/\\(MAX_CHARS = \\)500/\1$STATUS_MAX_CHARS/" \
$VALIDATORROOT/status_length_validator.rb
# Show result
diff --color=always $VALIDATORROOT/status_length_validator.rb.default $VALIDATORROOT/status_length_validator.rb
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment