Increasing the Mastodon (4.2) post character limit
Mastodon has a default character limit of 500 characters. The ActivityPub protocol however, which Mastodon is built against, does not specify a maximum character length. This means that in order to be compatibel, Mastodon does support posts with more than 500 characters, but it keeps users from actually posting longer posts. This is simply enforced by the server software. If you happen to run your own Mastodon instance, you can just set this limit to whatever you want - it does require a few source code changes though.
But wait, I hear you say, the limit is there for a reason, right? A Twitter1-style service lives from short postings, and long postings ruin it all. Well, in my experience 500 characters is sometimes just not enough. Sure, 80% or so of my posts will fit into that amount of characters, but sometimes I have more to say. And then I need to create a thread, which is both cumbersome to write as it is to read. Mastodon clients support long character posts. Some display it all at once, but most - like Ivory, for example - hide everything longer than 500 characters behind a “Read more” link. Which is totally fine by me and I have never received any complaints over postings that are too long.
To change these source files, you need access to the server, obviously. I am also going to assume that your server is up and running, and that you are using the non-Docker installation. It is probably similar or the same for the Docker installation, but I am not using it so I cannot confirm.
These instructions are for Mastodon 4.2. I am using
nano in these example as the text editor, but you can of course use whatever you want. I am changing the default to 2500 chars. You can change it to any other value, but for most people 1000-3000 should be more than enough.
And please keep in mind, these instructions are provided “as is”. Please think before following them. There is no guarantee that they work, and they may cause errors or unexpected behaviour. It is not my fault if you break your instance applying them. That said, I have been using an increased character limit on my instance for close to a year, and never had an issue with it.
1. Switch to your Mastodon user
su - mastodon
and switch to your Mastodon installation directory. For most people, this should be /home/mastodon.
2. Edit the file compose_form.jsx
Look for the number 500 (in Nano, you can search using Ctrl-W) and change it to 2500. There should be two instances.
3. Edit the file instance_serializer.rb
nano -w live/app/serializers/rest/instance_serializer.rb
On the top of the file, there is a definition of attributes:
attributes :domain, :title, :version, :source_url, :description, :usage, :thumbnail, :languages, :configuration, :registrations
You need add your own attribute to this. You could call it
attributes :domain, :title, :version, :source_url, :description, :usage, :thumbnail, :languages, :configuration, :registrations, :max_post_chars
Afterwards, at the bottom half of the file, you will find
private. Above this, add the definition for that attribute you have specified above:
def max_post_chars 2500 end
Make sure to put it above the
private, otherwise it will not be accessible.
4. Edit the file status_length_validator.rb
nano -w live/app/validators/status_length_validator.rb b/app/validators/status_length_validator.rb
MAX_CHARS = 500 and change it to
MAX_CHARS = 2500
5. Edit the file note_length_validator_spec
nano -w live/spec/validators/note_length_validator_spec.rb
There are two instances of the number 500 in this file. Change both to 2500.
6. Rebuild assets and restart services
You are now done editing and can rebuild the live assets. Do so with the following commands:
cd live RAILS_ENV=production bundle exec rails assets:precompile
Afterwards, exit the mastodon user, and restart the Mastodon services as root:
systemctl restart mastodon-sidekiq systemctl reload mastodon-web systemctl restart mastodon-streaming
Congratulations, you should now have an increased character limit on your instance. Have fun posting!
No, I am not going to call it “X”. ↩