instance_presenter.rb 2.1 KB

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