Permalink
Browse files

add max_toot_chars from glitch-soc

  • Loading branch information...
nolanlawson committed Feb 6, 2019
1 parent 28866d3 commit daeab22b2a666b1a145ba1a8154856a7d3998940
@@ -153,6 +153,9 @@ STREAMING_CLUSTER_NUM=1
# UID=1000
# GID=1000

# Maximum allowed character count
# MAX_TOOT_CHARS=500

# LDAP authentication (optional)
# LDAP_ENABLED=true
# LDAP_HOST=localhost
@@ -17,6 +17,7 @@ import { isMobile } from '../../../is_mobile';
import ImmutablePureComponent from 'react-immutable-pure-component';
import { length } from 'stringz';
import { countableText } from '../util/counter';
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';

@@ -85,7 +86,7 @@ class ComposeForm extends ImmutablePureComponent {
const { is_submitting, is_changing_upload, is_uploading, anyMedia } = this.props;
const fulltext = [this.props.spoiler_text, countableText(this.props.text)].join('');

if (is_submitting || is_uploading || is_changing_upload || length(fulltext) > 500 || (fulltext.length !== 0 && fulltext.trim().length === 0 && !anyMedia)) {
if (is_submitting || is_uploading || is_changing_upload || length(fulltext) > maxChars || (fulltext.length !== 0 && fulltext.trim().length === 0 && !anyMedia)) {
return;
}

@@ -161,7 +162,7 @@ class ComposeForm extends ImmutablePureComponent {
const { intl, onPaste, showSearch, anyMedia } = this.props;
const disabled = this.props.is_submitting;
const text = [this.props.spoiler_text, countableText(this.props.text)].join('');
const disabledButton = disabled || this.props.is_uploading || this.props.is_changing_upload || length(text) > 500 || (text.length !== 0 && text.trim().length === 0 && !anyMedia);
const disabledButton = disabled || this.props.is_uploading || this.props.is_changing_upload || length(text) > maxChars || (text.length !== 0 && text.trim().length === 0 && !anyMedia);
let publishText = '';

if (this.props.privacy === 'private' || this.props.privacy === 'direct') {
@@ -213,7 +214,7 @@ class ComposeForm extends ImmutablePureComponent {
<SensitiveButtonContainer />
<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'>
@@ -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 version = getMeta('version');
export const mascot = getMeta('mascot');
@@ -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,
@@ -4,7 +4,7 @@ class REST::InstanceSerializer < ActiveModel::Serializer
include RoutingHelper

attributes :uri, :title, :description, :email,
:version, :urls, :stats, :thumbnail,
:version, :urls, :stats, :thumbnail, :max_toot_chars,
:languages

has_one :contact_account, serializer: REST::AccountSerializer
@@ -35,6 +35,10 @@ def thumbnail
instance_presenter.thumbnail ? full_asset_url(instance_presenter.thumbnail.file.url) : full_pack_url('preview.jpg')
end

def max_toot_chars
StatusLengthValidator::MAX_CHARS
end

def stats
{
user_count: instance_presenter.user_count,
@@ -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?

0 comments on commit daeab22

Please sign in to comment.