hyperreal.coffee

Change default character limit on Mastodon

published on 2022-12-19 by hyperreal

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.

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 “MAXCHARS”. Change it to 2000.

class StatusLengthValidator < ActiveModel::Validator
  MAX_CHARS = 2000

Step 4

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

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!