The code powering m.abunchtell.com https://m.abunchtell.com
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

59 lines
2.2 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. }
  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