about summary refs log tree commit diff
path: root/app/serializers/activitypub/vote_serializer.rb
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2019-03-05 22:20:58 +0100
committerGitHub <noreply@github.com>2019-03-05 22:20:58 +0100
commit772b4ba24c60e0394d25d0fad4eefb338a9befea (patch)
tree804bb8ba01b1ff55471cc558d72456d2b9d0aea9 /app/serializers/activitypub/vote_serializer.rb
parent2a4ce7458a16c64029842fde210089453be2ede1 (diff)
parent866496ac16b47ee17138db600519a630be833e4e (diff)
Merge pull request #935 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/serializers/activitypub/vote_serializer.rb')
-rw-r--r--app/serializers/activitypub/vote_serializer.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/app/serializers/activitypub/vote_serializer.rb b/app/serializers/activitypub/vote_serializer.rb
new file mode 100644
index 000000000..248190404
--- /dev/null
+++ b/app/serializers/activitypub/vote_serializer.rb
@@ -0,0 +1,52 @@
+# frozen_string_literal: true
+
+class ActivityPub::VoteSerializer < ActiveModel::Serializer
+  class NoteSerializer < ActiveModel::Serializer
+    attributes :id, :type, :name, :attributed_to,
+               :in_reply_to, :to
+
+    def id
+      ActivityPub::TagManager.instance.uri_for(object) || [ActivityPub::TagManager.instance.uri_for(object.account), '#votes/', object.id].join
+    end
+
+    def type
+      'Note'
+    end
+
+    def name
+      object.poll.options[object.choice.to_i]
+    end
+
+    def attributed_to
+      ActivityPub::TagManager.instance.uri_for(object.account)
+    end
+
+    def in_reply_to
+      ActivityPub::TagManager.instance.uri_for(object.poll.status)
+    end
+
+    def to
+      ActivityPub::TagManager.instance.uri_for(object.poll.account)
+    end
+  end
+
+  attributes :id, :type, :actor, :to
+
+  has_one :object, serializer: ActivityPub::VoteSerializer::NoteSerializer
+
+  def id
+    [ActivityPub::TagManager.instance.uri_for(object.account), '#votes/', object.id, '/activity'].join
+  end
+
+  def type
+    'Create'
+  end
+
+  def actor
+    ActivityPub::TagManager.instance.uri_for(object.account)
+  end
+
+  def to
+    ActivityPub::TagManager.instance.uri_for(object.poll.account)
+  end
+end