Skip to main content

Increase the character limit for Mastodon posts

500 characters isn't enough for you?

Content comes from here, but this post is geared towards the official docker containers. I didn't want to roll my own images, because if anything ever gets changed in the official container, well, I don't care that much. I am just going to modify the existing containers I create, and when I upgrade, I'll just do it again.

We will edit three different files, two which set the character limit on your instance, and one which tells other clients or apps what your custom character limit is (for those that support it).

Copy the concerned files out of the container so we can edit them

docker cp mastodon_web_1:/opt/mastodon/app/javascript/mastodon/features/compose/components/compose_form.js . && \
docker cp mastodon_web_1:/opt/mastodon/app/validators/status_length_validator.rb . && \
docker cp mastodon_web_1:/opt/mastodon/app/serializers/rest/instance_serializer.rb .

Edit the files in your favourite text editor

You need to change the number 500 to whatever you would like the new limit to be. In the compose_form.js file, there are two instances, but in the other files, there is only one. In the final file, find the row starting with :languages, :registrations (should be the ~8th row), and change it so it includes :max_toot_chars after :registrations, such as :languages, :registrations, :max_toot_chars, where the full row now looks something like :languages, :registrations, :max_toot_chars, :approval_required, :invites_enabled. Then, at the end of the same file, above where it says private, add the following code:

def max_toot_chars 
   <your value here> 

and change to the same value you wrote previously.

Copy the files back into the containers

docker cp ./compose_form.js mastodon_web_1:/opt/mastodon/app/javascript/mastodon/features/compose/components/ && \
docker cp ./compose_form.js mastodon_sidekiq_1:/opt/mastodon/app/javascript/mastodon/features/compose/components/ && \
docker cp ./compose_form.js mastodon_streaming_1:/opt/mastodon/app/javascript/mastodon/features/compose/components/ && \
docker cp ./status_length_validator.rb mastodon_web_1:/opt/mastodon/app/validators/ && \
docker cp ./status_length_validator.rb mastodon_sidekiq_1:/opt/mastodon/app/validators/ && \
docker cp ./status_length_validator.rb mastodon_streaming_1:/opt/mastodon/app/validators/ && \
docker cp ./instance_serializer.rb mastodon_web_1:/opt/mastodon/app/serializers/rest/ && \
docker cp ./instance_serializer.rb mastodon_sidekiq_1:/opt/mastodon/app/serializers/rest/ && \
docker cp ./instance_serializer.rb mastodon_streaming_1:/opt/mastodon/app/serializers/rest/

Recompile assets and restart containers

docker exec mastodon_web_1 /bin/bash -c "RAILS_ENV=production bundle exec rails assets:precompile" && \
docker exec mastodon_sidekiq_1 /bin/bash -c "RAILS_ENV=production bundle exec rails assets:precompile" && \
docker exec mastodon_streaming_1 /bin/bash -c "RAILS_ENV=production bundle exec rails assets:precompile" && \
docker restart mastodon_web_1 mastodon_sidekiq_1 mastodon_streaming_1

And you’re done! You should now be able to see the new character limit on your Mastodon instance. It's too bad this value couldn't have one central location, like, for example, a configuration option or something.

#mastodon #character #limit #docker