instance_presenter.rb 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # frozen_string_literal: true
  2. class InstancePresenter < ActiveModelSerializers::Model
  3. attributes :domain, :title, :version, :source_url,
  4. :description, :languages, :rules, :contact
  5. class ContactPresenter < ActiveModelSerializers::Model
  6. attributes :email, :account
  7. def email
  8. Setting.site_contact_email
  9. end
  10. def account
  11. Account.find_local(Setting.site_contact_username.strip.gsub(/\A@/, ''))
  12. end
  13. end
  14. def contact
  15. ContactPresenter.new
  16. end
  17. def closed_registrations_message
  18. Setting.closed_registrations_message
  19. end
  20. def description
  21. Setting.site_short_description
  22. end
  23. def extended_description
  24. Setting.site_extended_description
  25. end
  26. def privacy_policy
  27. Setting.site_terms
  28. end
  29. def domain
  30. Rails.configuration.x.local_domain
  31. end
  32. def title
  33. Setting.site_title
  34. end
  35. def languages
  36. [I18n.default_locale]
  37. end
  38. def rules
  39. Rule.ordered
  40. end
  41. def user_count
  42. Rails.cache.fetch('user_count') { User.confirmed.joins(:account).merge(Account.without_suspended).count }
  43. end
  44. def active_user_count(num_weeks = 4)
  45. Rails.cache.fetch("active_user_count/#{num_weeks}") { ActivityTracker.new('activity:logins', :unique).sum(num_weeks.weeks.ago) }
  46. end
  47. def status_count
  48. Rails.cache.fetch('local_status_count') { Account.local.joins(:account_stat).sum('account_stats.statuses_count') }.to_i
  49. end
  50. def domain_count
  51. Rails.cache.fetch('distinct_domain_count') { Instance.count }
  52. end
  53. def sample_accounts
  54. Rails.cache.fetch('sample_accounts', expires_in: 12.hours) { Account.local.discoverable.popular.limit(3) }
  55. end
  56. def version
  57. Mastodon::Version.to_s
  58. end
  59. def source_url
  60. Mastodon::Version.source_url
  61. end
  62. def thumbnail
  63. @thumbnail ||= Rails.cache.fetch('site_uploads/thumbnail') { SiteUpload.find_by(var: 'thumbnail') }
  64. end
  65. def hero
  66. @hero ||= Rails.cache.fetch('site_uploads/hero') { SiteUpload.find_by(var: 'hero') }
  67. end
  68. def mascot
  69. @mascot ||= Rails.cache.fetch('site_uploads/mascot') { SiteUpload.find_by(var: 'mascot') }
  70. end
  71. end