diff options
author | Reverite <github@reverite.sh> | 2019-03-10 19:19:52 -0700 |
---|---|---|
committer | Reverite <github@reverite.sh> | 2019-03-10 19:19:52 -0700 |
commit | 229e2726cad36066afb210d7087a40cd9f955483 (patch) | |
tree | a14d55e9469f1f339fc40b777827aa4886bb7889 /app/serializers/rest | |
parent | 715c552fe4c1b2d59bf1f281d77b6e2546bdb531 (diff) | |
parent | 3cef04610cd809c7bd01adc00d34fb3d25261a16 (diff) |
Merge branch 'glitch'
Diffstat (limited to 'app/serializers/rest')
-rw-r--r-- | app/serializers/rest/instance_serializer.rb | 11 | ||||
-rw-r--r-- | app/serializers/rest/poll_serializer.rb | 30 | ||||
-rw-r--r-- | app/serializers/rest/status_serializer.rb | 1 |
3 files changed, 41 insertions, 1 deletions
diff --git a/app/serializers/rest/instance_serializer.rb b/app/serializers/rest/instance_serializer.rb index 41ed1995d..30e8dcbc1 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_toot_chars, + :version, :urls, :stats, :thumbnail, :max_toot_chars, :poll_limits, :languages, :registrations has_one :contact_account, serializer: REST::AccountSerializer @@ -39,6 +39,15 @@ class REST::InstanceSerializer < ActiveModel::Serializer StatusLengthValidator::MAX_CHARS end + def poll_limits + { + max_options: PollValidator::MAX_OPTIONS, + max_option_chars: PollValidator::MAX_OPTION_CHARS, + min_expiration: PollValidator::MIN_EXPIRATION, + max_expiration: PollValidator::MAX_EXPIRATION, + } + end + def stats { user_count: instance_presenter.user_count, diff --git a/app/serializers/rest/poll_serializer.rb b/app/serializers/rest/poll_serializer.rb new file mode 100644 index 000000000..4dae1c09f --- /dev/null +++ b/app/serializers/rest/poll_serializer.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class REST::PollSerializer < ActiveModel::Serializer + attributes :id, :expires_at, :expired, + :multiple, :votes_count + + has_many :loaded_options, key: :options + + attribute :voted, if: :current_user? + + def id + object.id.to_s + end + + def expired + object.expired? + end + + def voted + object.voted?(current_user.account) + end + + def current_user? + !current_user.nil? + end + + class OptionSerializer < ActiveModel::Serializer + attributes :title, :votes_count + end +end diff --git a/app/serializers/rest/status_serializer.rb b/app/serializers/rest/status_serializer.rb index b72eebb10..7185121d6 100644 --- a/app/serializers/rest/status_serializer.rb +++ b/app/serializers/rest/status_serializer.rb @@ -23,6 +23,7 @@ class REST::StatusSerializer < ActiveModel::Serializer has_many :emojis, serializer: REST::CustomEmojiSerializer has_one :preview_card, key: :card, serializer: REST::PreviewCardSerializer + has_one :poll, serializer: REST::PollSerializer def id object.id.to_s |