hyperreal.coffee

Change default character limit on Mastodon instance

Step 1

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

1systemctl stop mastodon-web mastodon-streaming mastodon-sidekiq
2su - 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.

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

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

1         <div className='character-counter__wrapper'>
2            <CharacterCounter max={2000} text={this.getFulltextForCharacterCounting()} />
3         </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.

1class StatusLengthValidator < ActiveModel::Validator
2  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.

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

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

1def max_toot_chars
2  2000
3end

Step 5

Recompile Mastodon assets:

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

Step 6

As the root user, restart the Mastodon systemd services:

1systemctl start mastodon-web mastodon-streaming mastodon-sidekiq

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

#mastodon #fediverse #selfhosting

Reply to this post by email ↪