]> cat aescling's git repositories - mastodon.git/blob - app/serializers/initial_state_serializer.rb
Add quick links to the admin interface in the WebUI (#8545)
[mastodon.git] / app / serializers / initial_state_serializer.rb
1 # frozen_string_literal: true
2
3 class InitialStateSerializer < ActiveModel::Serializer
4 attributes :meta, :compose, :accounts,
5 :media_attachments, :settings
6
7 has_one :push_subscription, serializer: REST::WebPushSubscriptionSerializer
8
9 def meta
10 store = {
11 streaming_api_base_url: Rails.configuration.x.streaming_api_base_url,
12 access_token: object.token,
13 locale: I18n.locale,
14 domain: Rails.configuration.x.local_domain,
15 admin: object.admin&.id&.to_s,
16 search_enabled: Chewy.enabled?,
17 version: Mastodon::Version.to_s,
18 invites_enabled: Setting.min_invite_role == 'user',
19 mascot: instance_presenter.mascot&.file&.url,
20 profile_directory: Setting.profile_directory,
21 }
22
23 if object.current_account
24 store[:me] = object.current_account.id.to_s
25 store[:unfollow_modal] = object.current_account.user.setting_unfollow_modal
26 store[:boost_modal] = object.current_account.user.setting_boost_modal
27 store[:delete_modal] = object.current_account.user.setting_delete_modal
28 store[:auto_play_gif] = object.current_account.user.setting_auto_play_gif
29 store[:display_media] = object.current_account.user.setting_display_media
30 store[:expand_spoilers] = object.current_account.user.setting_expand_spoilers
31 store[:reduce_motion] = object.current_account.user.setting_reduce_motion
32 store[:is_staff] = object.current_account.user.staff?
33 end
34
35 store
36 end
37
38 def compose
39 store = {}
40
41 if object.current_account
42 store[:me] = object.current_account.id.to_s
43 store[:default_privacy] = object.current_account.user.setting_default_privacy
44 store[:default_sensitive] = object.current_account.user.setting_default_sensitive
45 end
46
47 store[:text] = object.text if object.text
48
49 store
50 end
51
52 def accounts
53 store = {}
54 store[object.current_account.id.to_s] = ActiveModelSerializers::SerializableResource.new(object.current_account, serializer: REST::AccountSerializer) if object.current_account
55 store[object.admin.id.to_s] = ActiveModelSerializers::SerializableResource.new(object.admin, serializer: REST::AccountSerializer) if object.admin
56 store
57 end
58
59 def media_attachments
60 { accept_content_types: MediaAttachment::IMAGE_FILE_EXTENSIONS + MediaAttachment::VIDEO_FILE_EXTENSIONS + MediaAttachment::IMAGE_MIME_TYPES + MediaAttachment::VIDEO_MIME_TYPES }
61 end
62
63 private
64
65 def instance_presenter
66 @instance_presenter ||= InstancePresenter.new
67 end
68 end
This page took 0.107252 seconds and 6 git commands to generate.