customizations

code enhancements on mountains.social

These code changes have been tested without issues on Mastodon versions 4.2+

According to my information, there should come a normal parameter to set the maximum number of characters in Mastodon version 4.3. No need for this customization in that case, which would make upgrades even easier.

Increase maximum number of characters for a post

The maximum number of characters for a post on a Mastodon instance is 500. This can be quite limiting, so the number of characters have been increased to 1000.

Please note that a URL in a post only counts for 23 characters, regardless of the length of the URL. This means as well, that no URL shorteners are needed (which often have the downside of being privacy invasive).

1. Implement the enhancement

As user mastodon:

cd ~/live

cp -p app/javascript/mastodon/features/compose/components/compose_form.jsx app/javascript/mastodon/features/compose/components/compose_form.jsx.orig
cp -p app/validators/status_length_validator.rb app/validators/status_length_validator.rb.orig
cp -p app/serializers/rest/instance_serializer.rb app/serializers/rest/instance_serializer.rb.orig

sed -i 's/500/1000/g' app/javascript/mastodon/features/compose/components/compose_form.jsx
sed -i 's/500/1000/g' app/validators/status_length_validator.rb
sed -i 's/:registrations/:registrations, :max_toot_chars /g' app/serializers/rest/instance_serializer.rb
sed -i 's/private/def max_toot_chars\n 1000\n end\n\n private/g' app/serializers/rest/instance_serializer.rb

RAILS_ENV=production bundle exec rails assets:precompile && echo "pass" || echo "fail"

As user root:

service mastodon-web reload

As the code now has been changed, it is wise to revert the code changes (see below) before performing Mastodon upgrades. The upgrade will therefore run without issues. After the upgrade, the enhancement needs to be implemented again.

2. Revert the enhancement

As user mastodon:

cd ~/live

cp -p app/javascript/mastodon/features/compose/components/compose_form.jsx.orig app/javascript/mastodon/features/compose/components/compose_form.jsx
cp -p app/validators/status_length_validator.rb.orig app/validators/status_length_validator.rb
cp -p app/serializers/rest/instance_serializer.rb.orig app/serializers/rest/instance_serializer.rb

RAILS_ENV=production bundle exec rails assets:precompile && echo "pass" || echo "fail"

As user root:

service mastodon-web reload