instance_presenter.rb 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 description
  20. Setting.site_short_description
  21. end
  22. def extended_description
  23. Setting.site_extended_description
  24. end
  25. def status_page_url
  26. Setting.status_page_url
  27. end
  28. def domain
  29. Rails.configuration.x.local_domain
  30. end
  31. def title
  32. Setting.site_title
  33. end
  34. def languages
  35. [I18n.default_locale]
  36. end
  37. def rules
  38. Rule.ordered
  39. end
  40. def user_count
  41. Rails.cache.fetch('user_count') { User.confirmed.joins(:account).merge(Account.without_suspended).count }
  42. end
  43. def active_user_count(num_weeks = 4)
  44. Rails.cache.fetch("active_user_count/#{num_weeks}") { ActivityTracker.new('activity:logins', :unique).sum(num_weeks.weeks.ago) }
  45. end
  46. def status_count
  47. Rails.cache.fetch('local_status_count') { Account.local.joins(:account_stat).sum('account_stats.statuses_count') }.to_i
  48. end
  49. def domain_count
  50. Rails.cache.fetch('distinct_domain_count') { Instance.count }
  51. end
  52. def version
  53. Mastodon::Version.to_s
  54. end
  55. def source_url
  56. Mastodon::Version.source_url
  57. end
  58. def thumbnail
  59. @thumbnail ||= Rails.cache.fetch('site_uploads/thumbnail') { SiteUpload.find_by(var: 'thumbnail') }
  60. end
  61. def mascot
  62. @mascot ||= Rails.cache.fetch('site_uploads/mascot') { SiteUpload.find_by(var: 'mascot') }
  63. end
  64. end