Change default character limit on Mastodon

󰃭 2024-10-08

Step 1

On your Mastodon server, stop the Mastodon systemd services, then become the mastodon user:

systemctl stop mastodon-web mastodon-streaming mastodon-sidekiq
su - mastodon

Step 2

For the sake of this post, we’ll assume we want to change the default character limit from 500 to 2000 characters.

Mastodon v4.3.0+:

Edit /live/app/javascript/mastodon/features/compose/containers/compose_form_container.js. Find the line containing the default character limit. There is only one place in which this number is coded in the file. Use your text editor’s search function to find the following line:

maxChars: state.getIn(['server', 'server', 'configuration', 'statuses', 'max_characters'], 500)

Replace 500 with 2000.

Earlier Mastodon versions:

Edit live/app/javascript/mastodon/features/compose/components/compose_form.js. Find the line containing the default character limit. There are two places in which this number is coded in the file.

You can find it by using your text editor’s search function and searching for the string “length(fulltext) > 500”. Change the number to 2000.

return !(isSubmitting || isUploading || isChangingUpload || length(fulltext) > 2000 || (isOnlyWhitespace && !anyMedia));

Search with your text editor for the string “CharacterCounter max={500}”. Change the number to 2000.

         <div className='character-counter__wrapper'>
            <CharacterCounter max={2000} text={this.getFulltextForCharacterCounting()} />
         </div>

Step 3

Edit live/app/validators/status_length_validator.rb. There is only one place in which this number is coded in the file.

Search with your text editor for the string “MAX_CHARS”. Change it to 2000.

class StatusLengthValidator < ActiveModel::Validator
  MAX_CHARS = 2000

Step 4

Edit live/app/serializers/rest/instance_serializer.rb.

Mastodon v4.3.0+: Search for the string “attributes :domain”. Add :max_toot_chars after :api_versions.

attributes :domain, :title, :version, :source_url, :description,
           :usage, :thumbnail, :icon, :languages, :configuration,
           :registrations, :api_versions, :max_toot_chars

Earlier Mastodon versions: Search for the string “attributes :domain”. Add :max_toot_chars after :registrations.

attributes :domain, :title, :version, :source_url, :description
           :usage, :thumbnail, :languages, :configuration,
           :registrations, :max_toot_chars

Search for the string “private”. Place the following code block above it, followed by a blank newline:

def max_toot_chars
  2000
end

Step 5

Recompile Mastodon assets:

cd live
export NODE_OPTIONS=--openssl-legacy-provider  # Fedora hosts only
RAILS_ENV=production bundle exec rails assets:precompile

Step 6

As the root user, restart the Mastodon systemd services:

systemctl start mastodon-web mastodon-streaming mastodon-sidekiq

That’s pretty much all there is to it. May your toots now be sufficiently nuanced!


Enter your instance's address