Skip to content

Commit

Permalink
Add option to change status char counter
Browse files Browse the repository at this point in the history
  • Loading branch information
dhelonious committed Aug 1, 2024
1 parent 47e77a7 commit d5e36b4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ An initial setup command is required to initialize the database and configuratio

sudo mastodon-server.setup

> Note: Be patient if you have changed the `status.char-limit`, as it takes some time to recompile the assets.
> Note: Be patient if you have changed the `status.char-limit` or `status.char-counter`, as it takes some time to recompile the assets.
## Create admin user

Expand Down Expand Up @@ -119,11 +119,12 @@ The following settings are available:
|----------------------|-------------------------------|------------------------|--------------------------------------------------------------------------------------|
| `domain` | valid FQDN | | FQDN of the Mastodon instance |
| `email` | valid e-mail | | E-mail address of the owner of the Mastodon instance |
| `status.char-limit` | integer | 500 | Character limit of statuses (toots); changes require recompilation of assets, which takes some time |
| `ports.http` | 0 to 65353 | 80 | HTTP port |
| `ports.https` | 0 to 65353 | 443 | HTTPS port |
| `acme.server` | letsencrypt, zerossl | letsencrypt | CA used for acquiring an SSL certificate |
| `update.backups` | true, false | true | Create a backup in `/var/snap/mastodon-server/common/update/backups` before updating |
| `status.char-limit` | integer | 500 | Character limit of statuses (toots); changes require recompilation of assets, which takes some time |
| `status.char-limit` | integer | 500 | Character counter shown for statuses (toots); changes require recompilation of assets, which takes some time |
| `media.dir` | absolute path | `$SNAP_COMMON/media` | Location of the media directory (*public/system*) |
| `backup.dir` | absolute path | `$SNAP_COMMON/backups` | Location of the backup directory |
| `backup.days` | integer | 0 | Create and keep backups for `backup.days` (enabled if > 0) |
Expand Down
5 changes: 2 additions & 3 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ This release contains:
* mastodon-bird-ui 1.8.5
* tangerine-ui 1.9.5

Changelog for 4.2.10snap3:
Changelog for 4.2.10snap4:

* Adds an option to change the character limit of toots (`status.characters`).
* Updates the browserlist DB for npm and yarn on build (see https://github.com/browserslist/update-db#readme)
* Adds an option to change the character counter of toots (`status.chat-counter`).
2 changes: 1 addition & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description: |
implements ActivityPub!)
base: core20
version: 4.2.10snap3
version: 4.2.10snap4
grade: stable
confinement: strict

Expand Down
13 changes: 11 additions & 2 deletions src/mastodon/mastodon.env
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export CLEANUP_PREVIEWS="$(snapctl get cleanup.previews)"
export CLEANUP_STATUSES="$(snapctl get cleanup.statuses)"
export CLEANUP_ORPHANS="$(snapctl get cleanup.orphans)"
export STATUS_MAX_CHARS="$(snapctl get status.char-limit)"
export STATUS_MAX_CHARS_COUNTER="$(snapctl get status.char-counter)"

compose_form="$SNAP_DATA/mastodon/app/javascript/mastodon/features/compose/components/compose_form.jsx"
status_length_validator="$SNAP_DATA/mastodon/app/validators/status_length_validator.rb"
Expand Down Expand Up @@ -167,10 +168,18 @@ get_status_max_chars_file() {
}

update_status_max_chars() {
if [ -n "$STATUS_MAX_CHARS" ] && [ "$STATUS_MAX_CHARS" -eq "$STATUS_MAX_CHARS" ] && [ "$STATUS_MAX_CHARS" -gt "0" ]; then
if [ "$STATUS_MAX_CHARS" -gt "0" ]; then
sed -ri "s/length\(fulltext\) > [0-9]+/length(fulltext) > $STATUS_MAX_CHARS/" "$compose_form"
sed -ri "s/CharacterCounter max=\{[0-9]+\}/CharacterCounter max={$STATUS_MAX_CHARS}/" "$compose_form"
sed -ri "s/MAX_CHARS = [0-9]+/MAX_CHARS = $STATUS_MAX_CHARS/" "$status_length_validator"
fi
}

get_status_max_chars_counter_file() {
sed -rn "s/.*CharacterCounter max=\{([0-9]+)\}/\1/p" "$compose_form"
}

update_status_max_chars_counter() {
if [ "$STATUS_MAX_CHARS_COUNTER" -gt "0" ]; then
sed -ri "s/CharacterCounter max=\{[0-9]+\}/CharacterCounter max={$STATUS_MAX_CHARS_COUNTER}/" "$compose_form"
fi
}
3 changes: 2 additions & 1 deletion src/snap/snap.env
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ export DEFAULT_BACKUP_DIR="$SNAP_COMMON/backups"
export SETTINGS=$(cat <<-END
domain,
email,
status.char-limit,500
ports.http,80
ports.https,443
acme.server,letsencrypt
update.backups,true
status.char-limit,500
status.char-counter,500
media.dir,"$DEFAULT_MEDIA_DIR"
backup.dir,"$DEFAULT_BACKUP_DIR"
backup.days,0
Expand Down

0 comments on commit d5e36b4

Please sign in to comment.