initial_state_serializer.rb 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # frozen_string_literal: true
  2. class InitialStateSerializer < ActiveModel::Serializer
  3. attributes :meta, :compose, :accounts,
  4. :media_attachments, :settings, :push_subscription
  5. has_many :custom_emojis, serializer: REST::CustomEmojiSerializer
  6. def custom_emojis
  7. CustomEmoji.local.where(disabled: false)
  8. end
  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. }
  17. if object.current_account
  18. store[:me] = object.current_account.id.to_s
  19. store[:unfollow_modal] = object.current_account.user.setting_unfollow_modal
  20. store[:boost_modal] = object.current_account.user.setting_boost_modal
  21. store[:delete_modal] = object.current_account.user.setting_delete_modal
  22. store[:auto_play_gif] = object.current_account.user.setting_auto_play_gif
  23. store[:display_sensitive_media] = object.current_account.user.setting_display_sensitive_media
  24. store[:reduce_motion] = object.current_account.user.setting_reduce_motion
  25. end
  26. store
  27. end
  28. def compose
  29. store = {}
  30. if object.current_account
  31. store[:me] = object.current_account.id.to_s
  32. store[:default_privacy] = object.current_account.user.setting_default_privacy
  33. store[:default_sensitive] = object.current_account.user.setting_default_sensitive
  34. end
  35. store[:text] = object.text if object.text
  36. store
  37. end
  38. def accounts
  39. store = {}
  40. store[object.current_account.id.to_s] = ActiveModelSerializers::SerializableResource.new(object.current_account, serializer: REST::AccountSerializer) if object.current_account
  41. store[object.admin.id.to_s] = ActiveModelSerializers::SerializableResource.new(object.admin, serializer: REST::AccountSerializer) if object.admin
  42. store
  43. end
  44. def media_attachments
  45. { accept_content_types: MediaAttachment::IMAGE_FILE_EXTENSIONS + MediaAttachment::VIDEO_FILE_EXTENSIONS + MediaAttachment::IMAGE_MIME_TYPES + MediaAttachment::VIDEO_MIME_TYPES }
  46. end
  47. end