The code powering m.abunchtell.com https://m.abunchtell.com
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 

82 Zeilen
3.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. title: instance_presenter.site_title,
  13. admin: object.admin&.id&.to_s,
  14. search_enabled: Chewy.enabled?,
  15. repository: Mastodon::Version.repository,
  16. source_url: Mastodon::Version.source_url,
  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. trends: Setting.trends,
  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[:advanced_layout] = object.current_account.user.setting_advanced_layout
  33. store[:use_blurhash] = object.current_account.user.setting_use_blurhash
  34. store[:use_pending_items] = object.current_account.user.setting_use_pending_items
  35. store[:is_staff] = object.current_account.user.staff?
  36. store[:trends] = Setting.trends && object.current_account.user.setting_trends
  37. else
  38. store[:auto_play_gif] = Setting.auto_play_gif
  39. store[:display_media] = Setting.display_media
  40. store[:reduce_motion] = Setting.reduce_motion
  41. store[:use_blurhash] = Setting.use_blurhash
  42. end
  43. store
  44. end
  45. def compose
  46. store = {}
  47. if object.current_account
  48. store[:me] = object.current_account.id.to_s
  49. store[:default_privacy] = object.current_account.user.setting_default_privacy
  50. store[:default_sensitive] = object.current_account.user.setting_default_sensitive
  51. end
  52. store[:text] = object.text if object.text
  53. store
  54. end
  55. def accounts
  56. store = {}
  57. store[object.current_account.id.to_s] = ActiveModelSerializers::SerializableResource.new(object.current_account, serializer: REST::AccountSerializer) if object.current_account
  58. store[object.admin.id.to_s] = ActiveModelSerializers::SerializableResource.new(object.admin, serializer: REST::AccountSerializer) if object.admin
  59. store
  60. end
  61. def media_attachments
  62. { accept_content_types: MediaAttachment.supported_file_extensions + MediaAttachment.supported_mime_types }
  63. end
  64. private
  65. def instance_presenter
  66. @instance_presenter ||= InstancePresenter.new
  67. end
  68. end