The code powering m.abunchtell.com https://m.abunchtell.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

69 line
2.5 KiB

  1. # frozen_string_literal: true
  2. class InitialStateSerializer < ActiveModel::Serializer
  3. attributes :meta, :compose, :accounts,
  4. :media_attachments, :settings
  5. has_one :push_subscription, serializer: REST::WebPushSubscriptionSerializer
  6. def meta
  7. store = {
  8. streaming_api_base_url: Rails.configuration.x.streaming_api_base_url,
  9. access_token: object.token,
  10. locale: I18n.locale,
  11. domain: Rails.configuration.x.local_domain,
  12. admin: object.admin&.id&.to_s,
  13. search_enabled: Chewy.enabled?,
  14. version: Mastodon::Version.to_s,
  15. invites_enabled: Setting.min_invite_role == 'user',
  16. mascot: instance_presenter.mascot&.file&.url,
  17. profile_directory: Setting.profile_directory,
  18. }
  19. if object.current_account
  20. store[:me] = object.current_account.id.to_s
  21. store[:unfollow_modal] = object.current_account.user.setting_unfollow_modal
  22. store[:boost_modal] = object.current_account.user.setting_boost_modal
  23. store[:delete_modal] = object.current_account.user.setting_delete_modal
  24. store[:auto_play_gif] = object.current_account.user.setting_auto_play_gif
  25. store[:display_media] = object.current_account.user.setting_display_media
  26. store[:expand_spoilers] = object.current_account.user.setting_expand_spoilers
  27. store[:reduce_motion] = object.current_account.user.setting_reduce_motion
  28. store[:is_staff] = object.current_account.user.staff?
  29. end
  30. store
  31. end
  32. def compose
  33. store = {}
  34. if object.current_account
  35. store[:me] = object.current_account.id.to_s
  36. store[:default_privacy] = object.current_account.user.setting_default_privacy
  37. store[:default_sensitive] = object.current_account.user.setting_default_sensitive
  38. end
  39. store[:text] = object.text if object.text
  40. store
  41. end
  42. def accounts
  43. store = {}
  44. store[object.current_account.id.to_s] = ActiveModelSerializers::SerializableResource.new(object.current_account, serializer: REST::AccountSerializer) if object.current_account
  45. store[object.admin.id.to_s] = ActiveModelSerializers::SerializableResource.new(object.admin, serializer: REST::AccountSerializer) if object.admin
  46. store
  47. end
  48. def media_attachments
  49. { accept_content_types: MediaAttachment::IMAGE_FILE_EXTENSIONS + MediaAttachment::VIDEO_FILE_EXTENSIONS + MediaAttachment::IMAGE_MIME_TYPES + MediaAttachment::VIDEO_MIME_TYPES }
  50. end
  51. private
  52. def instance_presenter
  53. @instance_presenter ||= InstancePresenter.new
  54. end
  55. end