Transmogrify outgoing hashtags.
authorlain <lain@soykaf.club>
Sun, 18 Feb 2018 12:51:03 +0000 (13:51 +0100)
committerlain <lain@soykaf.club>
Sun, 18 Feb 2018 12:51:03 +0000 (13:51 +0100)
lib/pleroma/web/activity_pub/transmogrifier.ex
test/web/activity_pub/transmogrifier_test.exs

index af6b5befce6bca012db51f1aff80ce65483d112f..3781b212a10aa15b06b32a3a9c7255f9f6a55b5c 100644 (file)
@@ -100,6 +100,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
   """
   def prepare_outgoing(%{"type" => "Create", "object" => %{"type" => "Note"} = object} = data) do
     object = object
+    |> add_hashtags
     |> add_mention_tags
     |> add_attributed_to
     |> prepare_attachments
@@ -118,6 +119,14 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
     {:ok, data}
   end
 
+  def add_hashtags(object) do
+    tags = (object["tag"] || [])
+    |> Enum.map fn (tag) -> %{"href" => Pleroma.Web.Endpoint.url() <> "/tags/#{tag}", "name" => "##{tag}", "type" => "Hashtag"} end
+
+    object
+    |> Map.put("tag", tags)
+  end
+
   def add_mention_tags(object) do
     mentions = object["to"]
     |> Enum.map(fn (ap_id) -> User.get_cached_by_ap_id(ap_id) end)
index a39f4c1390069c97f2c93b9f709a66c1bc180ffa..e2db615ebe95233042f0c8e19b242b368e62d5a8 100644 (file)
@@ -100,18 +100,24 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
       user = insert(:user)
       other_user = insert(:user)
 
-      {:ok, activity} = CommonAPI.post(user, %{"status" => "hey, @#{other_user.nickname}, how are ya?"})
+      {:ok, activity} = CommonAPI.post(user, %{"status" => "hey, @#{other_user.nickname}, how are ya? #2hu"})
 
       {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
       object = modified["object"]
 
-      expected_tag = %{
+      expected_mention = %{
         "href" => other_user.ap_id,
         "name" => "@#{other_user.nickname}",
         "type" => "Mention"
       }
+      expected_tag = %{
+        "href" => Pleroma.Web.Endpoint.url <> "/tags/2hu",
+        "type" => "Hashtag",
+        "name" => "#2hu"
+      }
 
       assert Enum.member?(object["tag"], expected_tag)
+      assert Enum.member?(object["tag"], expected_mention)
     end
 
     test "it adds the json-ld context" do