From 6cd192b9fb3dcb40a87cfb8b1bd0c5416b686a41 Mon Sep 17 00:00:00 2001 From: Lain Iwakura Date: Tue, 14 Nov 2017 16:22:34 +0100 Subject: Make character limit configurable. --- .env.production.sample | 3 +++ app/validators/status_length_validator.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.env.production.sample b/.env.production.sample index 91fcce6ac..414404476 100644 --- a/.env.production.sample +++ b/.env.production.sample @@ -134,3 +134,6 @@ STREAMING_CLUSTER_NUM=1 # If you use Docker, you may want to assign UID/GID manually. # UID=1000 # GID=1000 + +# Maximum allowed character count +# MAX_CHARS=500 diff --git a/app/validators/status_length_validator.rb b/app/validators/status_length_validator.rb index 77be3f1f5..2be899740 100644 --- a/app/validators/status_length_validator.rb +++ b/app/validators/status_length_validator.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class StatusLengthValidator < ActiveModel::Validator - MAX_CHARS = 500 + MAX_CHARS = (ENV["MAX_CHARS"] || 500).to_i def validate(status) return unless status.local? && !status.reblog? -- cgit From a4dcabc11beac5e1226157baf4242ce66a831d55 Mon Sep 17 00:00:00 2001 From: Lain Iwakura Date: Tue, 14 Nov 2017 16:23:12 +0100 Subject: Return character limit in API and initial state. --- app/serializers/initial_state_serializer.rb | 7 ++++++- app/serializers/rest/instance_serializer.rb | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/serializers/initial_state_serializer.rb b/app/serializers/initial_state_serializer.rb index 4fa1981ed..4550b344e 100644 --- a/app/serializers/initial_state_serializer.rb +++ b/app/serializers/initial_state_serializer.rb @@ -2,10 +2,15 @@ class InitialStateSerializer < ActiveModel::Serializer attributes :meta, :compose, :accounts, - :media_attachments, :settings, :push_subscription + :media_attachments, :settings, :push_subscription, + :max_chars has_many :custom_emojis, serializer: REST::CustomEmojiSerializer + def max_chars + StatusLengthValidator::MAX_CHARS + end + def custom_emojis CustomEmoji.local.where(disabled: false) end diff --git a/app/serializers/rest/instance_serializer.rb b/app/serializers/rest/instance_serializer.rb index 2898011fd..52c161cb4 100644 --- a/app/serializers/rest/instance_serializer.rb +++ b/app/serializers/rest/instance_serializer.rb @@ -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_chars def uri Rails.configuration.x.local_domain @@ -30,6 +30,10 @@ class REST::InstanceSerializer < ActiveModel::Serializer full_asset_url(instance_presenter.thumbnail.file.url) if instance_presenter.thumbnail end + def max_chars + StatusLengthValidator::MAX_CHARS + end + def stats { user_count: instance_presenter.user_count, -- cgit From d11b1a1aa7a44e345f2458a712e6bbed85db267f Mon Sep 17 00:00:00 2001 From: Lain Iwakura Date: Tue, 14 Nov 2017 16:24:10 +0100 Subject: Handle character limit in initial state in frontend. --- app/javascript/mastodon/features/compose/components/compose_form.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/javascript/mastodon/features/compose/components/compose_form.js b/app/javascript/mastodon/features/compose/components/compose_form.js index 7890755f3..1b64f7fc7 100644 --- a/app/javascript/mastodon/features/compose/components/compose_form.js +++ b/app/javascript/mastodon/features/compose/components/compose_form.js @@ -18,6 +18,8 @@ import { isMobile } from '../../../is_mobile'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { length } from 'stringz'; import { countableText } from '../util/counter'; +import initialState from '../../../initial_state'; +const maxChars = initialState.max_chars; const messages = defineMessages({ placeholder: { id: 'compose_form.placeholder', defaultMessage: 'What is on your mind?' }, @@ -201,8 +203,8 @@ export default class ComposeForm extends ImmutablePureComponent {
-
-
+
+
-- cgit From dae8916544d0a9cee5d998b10bc5cf36f144b727 Mon Sep 17 00:00:00 2001 From: Lain Iwakura Date: Tue, 14 Nov 2017 16:54:04 +0100 Subject: Code style fixes. --- app/javascript/mastodon/features/compose/components/compose_form.js | 1 + app/validators/status_length_validator.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/javascript/mastodon/features/compose/components/compose_form.js b/app/javascript/mastodon/features/compose/components/compose_form.js index 1b64f7fc7..b7a7447c4 100644 --- a/app/javascript/mastodon/features/compose/components/compose_form.js +++ b/app/javascript/mastodon/features/compose/components/compose_form.js @@ -19,6 +19,7 @@ import ImmutablePureComponent from 'react-immutable-pure-component'; import { length } from 'stringz'; import { countableText } from '../util/counter'; import initialState from '../../../initial_state'; + const maxChars = initialState.max_chars; const messages = defineMessages({ diff --git a/app/validators/status_length_validator.rb b/app/validators/status_length_validator.rb index 2be899740..888de5a40 100644 --- a/app/validators/status_length_validator.rb +++ b/app/validators/status_length_validator.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class StatusLengthValidator < ActiveModel::Validator - MAX_CHARS = (ENV["MAX_CHARS"] || 500).to_i + MAX_CHARS = (ENV['MAX_CHARS'] || 500).to_i def validate(status) return unless status.local? && !status.reblog? -- cgit From ca5440b93df514659eacde4ce562e459643dedc3 Mon Sep 17 00:00:00 2001 From: Lain Iwakura Date: Tue, 14 Nov 2017 17:56:38 +0100 Subject: Rename MAX_CHARS to MAX_TOOT_CHARS to be more specific. --- .env.production.sample | 2 +- app/javascript/mastodon/features/compose/components/compose_form.js | 2 +- app/serializers/initial_state_serializer.rb | 4 ++-- app/serializers/rest/instance_serializer.rb | 4 ++-- app/validators/status_length_validator.rb | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.env.production.sample b/.env.production.sample index 414404476..27de27de4 100644 --- a/.env.production.sample +++ b/.env.production.sample @@ -136,4 +136,4 @@ STREAMING_CLUSTER_NUM=1 # GID=1000 # Maximum allowed character count -# MAX_CHARS=500 +# MAX_TOOT_CHARS=500 diff --git a/app/javascript/mastodon/features/compose/components/compose_form.js b/app/javascript/mastodon/features/compose/components/compose_form.js index b7a7447c4..1d0126dbe 100644 --- a/app/javascript/mastodon/features/compose/components/compose_form.js +++ b/app/javascript/mastodon/features/compose/components/compose_form.js @@ -20,7 +20,7 @@ import { length } from 'stringz'; import { countableText } from '../util/counter'; import initialState from '../../../initial_state'; -const maxChars = initialState.max_chars; +const maxChars = initialState.max_toot_chars; const messages = defineMessages({ placeholder: { id: 'compose_form.placeholder', defaultMessage: 'What is on your mind?' }, diff --git a/app/serializers/initial_state_serializer.rb b/app/serializers/initial_state_serializer.rb index 4550b344e..b4bdb326b 100644 --- a/app/serializers/initial_state_serializer.rb +++ b/app/serializers/initial_state_serializer.rb @@ -3,11 +3,11 @@ class InitialStateSerializer < ActiveModel::Serializer attributes :meta, :compose, :accounts, :media_attachments, :settings, :push_subscription, - :max_chars + :max_toot_chars has_many :custom_emojis, serializer: REST::CustomEmojiSerializer - def max_chars + def max_toot_chars StatusLengthValidator::MAX_CHARS end diff --git a/app/serializers/rest/instance_serializer.rb b/app/serializers/rest/instance_serializer.rb index 52c161cb4..abbacc374 100644 --- a/app/serializers/rest/instance_serializer.rb +++ b/app/serializers/rest/instance_serializer.rb @@ -4,7 +4,7 @@ class REST::InstanceSerializer < ActiveModel::Serializer include RoutingHelper attributes :uri, :title, :description, :email, - :version, :urls, :stats, :thumbnail, :max_chars + :version, :urls, :stats, :thumbnail, :max_toot_chars def uri Rails.configuration.x.local_domain @@ -30,7 +30,7 @@ class REST::InstanceSerializer < ActiveModel::Serializer full_asset_url(instance_presenter.thumbnail.file.url) if instance_presenter.thumbnail end - def max_chars + def max_toot_chars StatusLengthValidator::MAX_CHARS end diff --git a/app/validators/status_length_validator.rb b/app/validators/status_length_validator.rb index 888de5a40..79d17742a 100644 --- a/app/validators/status_length_validator.rb +++ b/app/validators/status_length_validator.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class StatusLengthValidator < ActiveModel::Validator - MAX_CHARS = (ENV['MAX_CHARS'] || 500).to_i + MAX_CHARS = (ENV['MAX_TOOT_CHARS'] || 500).to_i def validate(status) return unless status.local? && !status.reblog? -- cgit