about summary refs log tree commit diff
path: root/app/presenters/instance_presenter.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2022-10-05 03:47:56 +0200
committerGitHub <noreply@github.com>2022-10-05 03:47:56 +0200
commitd2528b26b6da34f34b5d7a392e263428d3c09d69 (patch)
tree142ace2915a143d61b852e479603726e8d7e2675 /app/presenters/instance_presenter.rb
parentcedcece0ccba626d97a910f2e3fecf93c2729ca4 (diff)
Add server banner to web app, add `GET /api/v2/instance` to REST API (#19294)
Diffstat (limited to 'app/presenters/instance_presenter.rb')
-rw-r--r--app/presenters/instance_presenter.rb64
1 files changed, 48 insertions, 16 deletions
diff --git a/app/presenters/instance_presenter.rb b/app/presenters/instance_presenter.rb
index 3e85faa92..c461ac55f 100644
--- a/app/presenters/instance_presenter.rb
+++ b/app/presenters/instance_presenter.rb
@@ -1,19 +1,51 @@
 # frozen_string_literal: true
 
-class InstancePresenter
-  delegate(
-    :site_contact_email,
-    :site_title,
-    :site_short_description,
-    :site_description,
-    :site_extended_description,
-    :site_terms,
-    :closed_registrations_message,
-    to: Setting
-  )
-
-  def contact_account
-    Account.find_local(Setting.site_contact_username.strip.gsub(/\A@/, ''))
+class InstancePresenter < ActiveModelSerializers::Model
+  attributes :domain, :title, :version, :source_url,
+             :description, :languages, :rules, :contact
+
+  class ContactPresenter < ActiveModelSerializers::Model
+    attributes :email, :account
+
+    def email
+      Setting.site_contact_email
+    end
+
+    def account
+      Account.find_local(Setting.site_contact_username.strip.gsub(/\A@/, ''))
+    end
+  end
+
+  def contact
+    ContactPresenter.new
+  end
+
+  def closed_registrations_message
+    Setting.closed_registrations_message
+  end
+
+  def description
+    Setting.site_short_description
+  end
+
+  def extended_description
+    Setting.site_extended_description
+  end
+
+  def privacy_policy
+    Setting.site_terms
+  end
+
+  def domain
+    Rails.configuration.x.local_domain
+  end
+
+  def title
+    Setting.site_title
+  end
+
+  def languages
+    [I18n.default_locale]
   end
 
   def rules
@@ -40,8 +72,8 @@ class InstancePresenter
     Rails.cache.fetch('sample_accounts', expires_in: 12.hours) { Account.local.discoverable.popular.limit(3) }
   end
 
-  def version_number
-    Mastodon::Version
+  def version
+    Mastodon::Version.to_s
   end
 
   def source_url