Skip to content

Commit

Permalink
Merge pull request mastodon#201 from weex/editable-toot-length
Browse files Browse the repository at this point in the history
Make post-length editable by config file
  • Loading branch information
weex committed Aug 28, 2021
2 parents ec0372a + e400747 commit 257f7a0
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
8 changes: 8 additions & 0 deletions .env.production.sample
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,11 @@ S3_BUCKET=files.example.com
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
S3_ALIAS_HOST=files.example.com

# Custom settings
# ---------------
# Various ways to customize Mastodon's behavior
# ---------------

# Maximum allowed character count
MAX_TOOT_CHARS=500
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import ImmutablePureComponent from 'react-immutable-pure-component';
import { length } from 'stringz';
import { countableText } from '../util/counter';
import Icon from 'mastodon/components/icon';
import { maxChars } from '../../../initial_state';

const allowedAroundShortCode = '><\u0085\u0020\u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029\u0009\u000a\u000b\u000c\u000d';

Expand Down Expand Up @@ -86,7 +87,7 @@ class ComposeForm extends ImmutablePureComponent {
const fulltext = this.getFulltextForCharacterCounting();
const isOnlyWhitespace = fulltext.length !== 0 && fulltext.trim().length === 0;

return !(isSubmitting || isUploading || isChangingUpload || length(fulltext) > 500 || (isOnlyWhitespace && !anyMedia));
return !(isSubmitting || isUploading || isChangingUpload || length(fulltext) > maxChars || (isOnlyWhitespace && !anyMedia));
}

handleSubmit = () => {
Expand Down Expand Up @@ -257,7 +258,7 @@ class ComposeForm extends ImmutablePureComponent {
<PrivacyDropdownContainer />
<SpoilerButtonContainer />
</div>
<div className='character-counter__wrapper'><CharacterCounter max={500} text={this.getFulltextForCharacterCounting()} /></div>
<div className='character-counter__wrapper'><CharacterCounter max={maxChars} text={this.getFulltextForCharacterCounting()} /></div>
</div>

<div className='compose-form__publish'>
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/initial_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const boostModal = getMeta('boost_modal');
export const deleteModal = getMeta('delete_modal');
export const me = getMeta('me');
export const searchEnabled = getMeta('search_enabled');
export const maxChars = (initialState && initialState.max_toot_chars) || 500;
export const invitesEnabled = getMeta('invites_enabled');
export const limitedFederationMode = getMeta('limited_federation_mode');
export const repository = getMeta('repository');
Expand Down
7 changes: 6 additions & 1 deletion app/serializers/initial_state_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

class InitialStateSerializer < ActiveModel::Serializer
attributes :meta, :compose, :accounts,
:media_attachments, :settings
:media_attachments, :settings,
:max_toot_chars

has_one :push_subscription, serializer: REST::WebPushSubscriptionSerializer

def max_toot_chars
StatusLengthValidator::MAX_CHARS
end

def meta
store = {
streaming_api_base_url: Rails.configuration.x.streaming_api_base_url,
Expand Down
6 changes: 5 additions & 1 deletion app/serializers/rest/instance_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class REST::InstanceSerializer < ActiveModel::Serializer
include RoutingHelper

attributes :uri, :title, :short_description, :description, :email,
:version, :urls, :stats, :thumbnail,
:version, :urls, :stats, :thumbnail, :max_toot_chars,
:languages, :registrations, :approval_required, :invites_enabled,
:configuration

Expand Down Expand Up @@ -42,6 +42,10 @@ def thumbnail
instance_presenter.thumbnail ? full_asset_url(instance_presenter.thumbnail.file.url) : full_pack_url('media/images/preview.jpg')
end

def max_toot_chars
StatusLengthValidator::MAX_CHARS
end

def stats
{
user_count: instance_presenter.user_count,
Expand Down
2 changes: 1 addition & 1 deletion app/validators/status_length_validator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class StatusLengthValidator < ActiveModel::Validator
MAX_CHARS = 500
MAX_CHARS = (ENV['MAX_TOOT_CHARS'] || 500).to_i
URL_PLACEHOLDER_CHARS = 23
URL_PLACEHOLDER = "\1#{'x' * URL_PLACEHOLDER_CHARS}"

Expand Down

0 comments on commit 257f7a0

Please sign in to comment.