about summary refs log tree commit diff
path: root/app/presenters
diff options
context:
space:
mode:
Diffstat (limited to 'app/presenters')
-rw-r--r--app/presenters/initial_state_presenter.rb4
-rw-r--r--app/presenters/tag_relationships_presenter.rb15
2 files changed, 19 insertions, 0 deletions
diff --git a/app/presenters/initial_state_presenter.rb b/app/presenters/initial_state_presenter.rb
index 06482935c..129ea2a46 100644
--- a/app/presenters/initial_state_presenter.rb
+++ b/app/presenters/initial_state_presenter.rb
@@ -3,4 +3,8 @@
 class InitialStatePresenter < ActiveModelSerializers::Model
   attributes :settings, :push_subscription, :token,
              :current_account, :admin, :text, :visibility
+
+  def role
+    current_account&.user_role
+  end
 end
diff --git a/app/presenters/tag_relationships_presenter.rb b/app/presenters/tag_relationships_presenter.rb
new file mode 100644
index 000000000..c3bdbaf07
--- /dev/null
+++ b/app/presenters/tag_relationships_presenter.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class TagRelationshipsPresenter
+  attr_reader :following_map
+
+  def initialize(tags, current_account_id = nil, **options)
+    @following_map = begin
+      if current_account_id.nil?
+        {}
+      else
+        TagFollow.select(:tag_id).where(tag_id: tags.map(&:id), account_id: current_account_id).each_with_object({}) { |f, h| h[f.tag_id] = true }.merge(options[:following_map] || {})
+      end
+    end
+  end
+end