Browse Source

apply max chars patch from https://github.com/tootsuite/mastodon/pull/5697

Co-authored-by: mayaeh <mayaeh@marimo-net.org>
main
James Fenn 8 months ago
parent
commit
c69bd7789c
6 changed files with 22 additions and 6 deletions
  1. +3
    -0
      .env.production
  2. +5
    -3
      app/javascript/mastodon/features/compose/components/compose_form.js
  3. +1
    -0
      app/javascript/mastodon/initial_state.js
  4. +6
    -1
      app/serializers/initial_state_serializer.rb
  5. +6
    -1
      app/serializers/rest/instance_serializer.rb
  6. +1
    -1
      app/validators/status_length_validator.rb

+ 3
- 0
.env.production View File

@@ -61,6 +61,9 @@ LOCAL_HTTPS=true
# Optionally change default language
# DEFAULT_LOCALE=de

# Maximum allowed character count
MAX_TOOT_CHARS=10000

# E-mail configuration
# Note: Mailgun and SparkPost (https://sparkpo.st/smtp) each have good free tiers
# If you want to use an SMTP server without authentication (e.g local Postfix relay)


+ 5
- 3
app/javascript/mastodon/features/compose/components/compose_form.js View File

@@ -20,7 +20,9 @@ import ImmutablePureComponent from 'react-immutable-pure-component';
import { length } from 'stringz';
import { countableText } from '../util/counter';
import Icon from 'mastodon/components/icon';
import { max_toot_chars } from '../../../initial_state';

const maxChars = max_toot_chars || 500;
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';

const messages = defineMessages({
@@ -88,7 +90,7 @@ class ComposeForm extends ImmutablePureComponent {
const { isSubmitting, isChangingUpload, isUploading, anyMedia } = this.props;
const fulltext = [this.props.spoilerText, countableText(this.props.text)].join('');

if (isSubmitting || isUploading || isChangingUpload || length(fulltext) > 500 || (fulltext.length !== 0 && fulltext.trim().length === 0 && !anyMedia)) {
if (isSubmitting || isUploading || isChangingUpload || length(fulltext) > maxChars || (fulltext.length !== 0 && fulltext.trim().length === 0 && !anyMedia)) {
return;
}

@@ -181,7 +183,7 @@ class ComposeForm extends ImmutablePureComponent {
const { intl, onPaste, showSearch, anyMedia } = this.props;
const disabled = this.props.isSubmitting;
const text = [this.props.spoilerText, countableText(this.props.text)].join('');
const disabledButton = disabled || this.props.isUploading || this.props.isChangingUpload || length(text) > 500 || (text.length !== 0 && text.trim().length === 0 && !anyMedia);
const disabledButton = disabled || this.props.isUploading || this.props.isChangingUpload || length(text) > maxChars || (text.length !== 0 && text.trim().length === 0 && !anyMedia);
let publishText = '';

if (this.props.privacy === 'private' || this.props.privacy === 'direct') {
@@ -243,7 +245,7 @@ class ComposeForm extends ImmutablePureComponent {
<PrivacyDropdownContainer />
<SpoilerButtonContainer />
</div>
<div className='character-counter__wrapper'><CharacterCounter max={500} text={text} /></div>
<div className='character-counter__wrapper'><CharacterCounter max={maxChars} text={text} /></div>
</div>

<div className='compose-form__publish'>


+ 1
- 0
app/javascript/mastodon/initial_state.js View File

@@ -25,5 +25,6 @@ export const usePendingItems = getMeta('use_pending_items');
export const showTrends = getMeta('trends');
export const title = getMeta('title');
export const cropImages = getMeta('crop_images');
export const max_toot_chars = getMeta('max_toot_chars');

export default initialState;

+ 6
- 1
app/serializers/initial_state_serializer.rb View File

@@ -2,7 +2,8 @@

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

has_one :push_subscription, serializer: REST::WebPushSubscriptionSerializer

@@ -75,6 +76,10 @@ class InitialStateSerializer < ActiveModel::Serializer
{ accept_content_types: MediaAttachment.supported_file_extensions + MediaAttachment.supported_mime_types }
end

def max_toot_chars
StatusLengthValidator::MAX_CHARS
end

private

def instance_presenter


+ 6
- 1
app/serializers/rest/instance_serializer.rb View File

@@ -5,7 +5,8 @@ class REST::InstanceSerializer < ActiveModel::Serializer

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

has_one :contact_account, serializer: REST::AccountSerializer

@@ -39,6 +40,10 @@ class REST::InstanceSerializer < ActiveModel::Serializer
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,


+ 1
- 1
app/validators/status_length_validator.rb View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true

class StatusLengthValidator < ActiveModel::Validator
MAX_CHARS = 500
MAX_CHARS = (ENV['MAX_TOOT_CHARS'] || 500).to_i

def validate(status)
return unless status.local? && !status.reblog?


Loading…
Cancel
Save