The code powering m.abunchtell.com https://m.abunchtell.com
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

68 řádky
2.4 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. end
  29. store
  30. end
  31. def compose
  32. store = {}
  33. if object.current_account
  34. store[:me] = object.current_account.id.to_s
  35. store[:default_privacy] = object.current_account.user.setting_default_privacy
  36. store[:default_sensitive] = object.current_account.user.setting_default_sensitive
  37. end
  38. store[:text] = object.text if object.text
  39. store
  40. end
  41. def accounts
  42. store = {}
  43. store[object.current_account.id.to_s] = ActiveModelSerializers::SerializableResource.new(object.current_account, serializer: REST::AccountSerializer) if object.current_account
  44. store[object.admin.id.to_s] = ActiveModelSerializers::SerializableResource.new(object.admin, serializer: REST::AccountSerializer) if object.admin
  45. store
  46. end
  47. def media_attachments
  48. { accept_content_types: MediaAttachment::IMAGE_FILE_EXTENSIONS + MediaAttachment::VIDEO_FILE_EXTENSIONS + MediaAttachment::IMAGE_MIME_TYPES + MediaAttachment::VIDEO_MIME_TYPES }
  49. end
  50. private
  51. def instance_presenter
  52. @instance_presenter ||= InstancePresenter.new
  53. end
  54. end