add max_toot_chars from glitch-soc
This commit is contained in:
parent
da7cd1ab1a
commit
6bd0dadcfd
@ -169,6 +169,9 @@ STREAMING_CLUSTER_NUM=1
|
|||||||
# UID=1000
|
# UID=1000
|
||||||
# GID=1000
|
# GID=1000
|
||||||
|
|
||||||
|
# Maximum allowed character count
|
||||||
|
# MAX_TOOT_CHARS=500
|
||||||
|
|
||||||
# LDAP authentication (optional)
|
# LDAP authentication (optional)
|
||||||
# LDAP_ENABLED=true
|
# LDAP_ENABLED=true
|
||||||
# LDAP_HOST=localhost
|
# LDAP_HOST=localhost
|
||||||
|
@ -21,6 +21,7 @@ import ImmutablePureComponent from 'react-immutable-pure-component';
|
|||||||
import { length } from 'stringz';
|
import { length } from 'stringz';
|
||||||
import { countableText } from '../util/counter';
|
import { countableText } from '../util/counter';
|
||||||
import Icon from 'mastodon/components/icon';
|
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';
|
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';
|
||||||
|
|
||||||
@ -90,7 +91,7 @@ class ComposeForm extends ImmutablePureComponent {
|
|||||||
const { isSubmitting, isChangingUpload, isUploading, anyMedia } = this.props;
|
const { isSubmitting, isChangingUpload, isUploading, anyMedia } = this.props;
|
||||||
const fulltext = [this.props.spoilerText, countableText(this.props.text)].join('');
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,7 +184,7 @@ class ComposeForm extends ImmutablePureComponent {
|
|||||||
const { intl, onPaste, showSearch, anyMedia } = this.props;
|
const { intl, onPaste, showSearch, anyMedia } = this.props;
|
||||||
const disabled = this.props.isSubmitting;
|
const disabled = this.props.isSubmitting;
|
||||||
const text = [this.props.spoilerText, countableText(this.props.text)].join('');
|
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 = '';
|
let publishText = '';
|
||||||
|
|
||||||
if (this.props.privacy === 'private' || this.props.privacy === 'direct') {
|
if (this.props.privacy === 'private' || this.props.privacy === 'direct') {
|
||||||
@ -246,7 +247,7 @@ class ComposeForm extends ImmutablePureComponent {
|
|||||||
<SpoilerButtonContainer />
|
<SpoilerButtonContainer />
|
||||||
<FederationDropdownContainer />
|
<FederationDropdownContainer />
|
||||||
</div>
|
</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>
|
||||||
|
|
||||||
<div className='compose-form__publish'>
|
<div className='compose-form__publish'>
|
||||||
|
@ -12,6 +12,7 @@ export const boostModal = getMeta('boost_modal');
|
|||||||
export const deleteModal = getMeta('delete_modal');
|
export const deleteModal = getMeta('delete_modal');
|
||||||
export const me = getMeta('me');
|
export const me = getMeta('me');
|
||||||
export const searchEnabled = getMeta('search_enabled');
|
export const searchEnabled = getMeta('search_enabled');
|
||||||
|
export const maxChars = (initialState && initialState.max_toot_chars) || 500;
|
||||||
export const invitesEnabled = getMeta('invites_enabled');
|
export const invitesEnabled = getMeta('invites_enabled');
|
||||||
export const repository = getMeta('repository');
|
export const repository = getMeta('repository');
|
||||||
export const source_url = getMeta('source_url');
|
export const source_url = getMeta('source_url');
|
||||||
|
@ -2,10 +2,15 @@
|
|||||||
|
|
||||||
class InitialStateSerializer < ActiveModel::Serializer
|
class InitialStateSerializer < ActiveModel::Serializer
|
||||||
attributes :meta, :compose, :accounts,
|
attributes :meta, :compose, :accounts,
|
||||||
:media_attachments, :settings
|
:media_attachments, :settings,
|
||||||
|
:max_toot_chars
|
||||||
|
|
||||||
has_one :push_subscription, serializer: REST::WebPushSubscriptionSerializer
|
has_one :push_subscription, serializer: REST::WebPushSubscriptionSerializer
|
||||||
|
|
||||||
|
def max_toot_chars
|
||||||
|
StatusLengthValidator::MAX_CHARS
|
||||||
|
end
|
||||||
|
|
||||||
def meta
|
def meta
|
||||||
store = {
|
store = {
|
||||||
streaming_api_base_url: Rails.configuration.x.streaming_api_base_url,
|
streaming_api_base_url: Rails.configuration.x.streaming_api_base_url,
|
||||||
|
@ -4,7 +4,7 @@ class REST::InstanceSerializer < ActiveModel::Serializer
|
|||||||
include RoutingHelper
|
include RoutingHelper
|
||||||
|
|
||||||
attributes :uri, :title, :short_description, :description, :email,
|
attributes :uri, :title, :short_description, :description, :email,
|
||||||
:version, :urls, :stats, :thumbnail,
|
:version, :urls, :stats, :thumbnail, :max_toot_chars,
|
||||||
:languages, :registrations, :approval_required
|
:languages, :registrations, :approval_required
|
||||||
|
|
||||||
has_one :contact_account, serializer: REST::AccountSerializer
|
has_one :contact_account, serializer: REST::AccountSerializer
|
||||||
@ -39,6 +39,10 @@ class REST::InstanceSerializer < ActiveModel::Serializer
|
|||||||
instance_presenter.thumbnail ? full_asset_url(instance_presenter.thumbnail.file.url) : full_pack_url('media/images/preview.jpg')
|
instance_presenter.thumbnail ? full_asset_url(instance_presenter.thumbnail.file.url) : full_pack_url('media/images/preview.jpg')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def max_toot_chars
|
||||||
|
StatusLengthValidator::MAX_CHARS
|
||||||
|
end
|
||||||
|
|
||||||
def stats
|
def stats
|
||||||
{
|
{
|
||||||
user_count: instance_presenter.user_count,
|
user_count: instance_presenter.user_count,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class StatusLengthValidator < ActiveModel::Validator
|
class StatusLengthValidator < ActiveModel::Validator
|
||||||
MAX_CHARS = 500
|
MAX_CHARS = (ENV['MAX_TOOT_CHARS'] || 500).to_i
|
||||||
|
|
||||||
def validate(status)
|
def validate(status)
|
||||||
return unless status.local? && !status.reblog?
|
return unless status.local? && !status.reblog?
|
||||||
|
Loading…
Reference in New Issue
Block a user