Sometimes, 500 characters isn’t enough. Recently over at auspol.cafe we decided to up the limit to 1500 characters. There was a bit of trial and error, so hopefully this article should help anyone out there having their own troubles with this process.

First, you’ll want to go to the Git repo for Mastodon and fork it into your own account. Once that’s done, clone the repo to your local workspace. I like to rename the folder to the instance that I’m making the changes for, just in case I’m working on multiple instances at the same time.

git clone https://github.com/indentedspace/mastodon.git auspol.cafe
cd auspol.cafe

Next, add tootsuite’s mastodon repo as your upstream remote. This will let you keep abreast of future releases.

git remote add upstream https://github.com/tootsuite/mastodon.git

Once that’s done, it’s time to checkout the most recent release you want to work with. You can skip this step if you really want to use the cutting edge master content, but I’d recommend just sticking with the latest release.

git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)

Now, from this release tag we’ll create our own branch to keep track of the changes for this instance. I like to name the branch after the instance we’re modifying, but you can name it whatever you’d like!

git checkout -b auspolcafe

Now we can go ahead and start hacking!

vi app/validators/status_length_validator.rb

Change line 4 from MAX_CHARS = 500 to MAX_CHARS = 1500 and save. This changes the Mastodon back-end to allow toots with a max of 1500 characters. Next, we probably want to let the world know, too. Currently there’s no official way to include your character length in the API, but unofficially, you’ll need to set the max_toot_chars attribute in your instance’s API response.

vi app/serializers/rest/instance_serializer.rb

Change line 8 from :languages, :registrations, :approval_required to :languages, :registrations, :approval_required, :max_toot_chars (don’t forget the comma).

Change line 65, after the approval_required block, and add a definition for max_toot_chars

def max_toot_chars
    1500
end

Save and exit instance_serializer.rb. Now that we’ve handled the back-end, it’s time to make some front-end changes too. This will let users on the instance’s web client post longer toots.

vi app/javascript/mastodon/features/compose/components/compose_form.js

Change line 91‘s contents, from length(fulltext) > 500 to length(fulltext) > 1500.

Make the same change for line 181. length(text) > 500 to length(text) > 1500.

Finally, change line 243, from<div className='character-counter__wrapper'><CharacterCounter max={500} text={text} /></div> to <div className='character-counter__wrapper'><CharacterCounter max={1500} text={text} /></div> and save.

Once that’s done, commit and push your changes.

If you’re using vanilla Mastodon in production and need to switch to your new fork, simply edit the origin remote to point to your new fork, pull down your new branch, and check it out. Once that’s done, simply precompile the assets (if not using docker) and restart your Mastodon processes.

Leave a Reply

Your email address will not be published. Required fields are marked *