Save cws in the activitypub data.
authorRoger Braun <roger@rogerbraun.net>
Tue, 31 Oct 2017 16:30:46 +0000 (17:30 +0100)
committerRoger Braun <roger@rogerbraun.net>
Tue, 31 Oct 2017 16:30:46 +0000 (17:30 +0100)
lib/pleroma/web/common_api/utils.ex
lib/pleroma/web/ostatus/handlers/note_handler.ex
lib/pleroma/web/ostatus/ostatus.ex
test/web/ostatus/ostatus_test.exs

index 06fcc9e8b637dc9f71f8a4aa289e4c3ec4502c1e..83a656011a83c0b9497f85203a5aaa5f144aea08 100644 (file)
@@ -94,11 +94,12 @@ defmodule Pleroma.Web.CommonAPI.Utils do
     end)
   end
 
-  def make_note_data(actor, to, context, content_html, attachments, inReplyTo, tags) do
+  def make_note_data(actor, to, context, content_html, attachments, inReplyTo, tags, cw \\ nil) do
       object = %{
         "type" => "Note",
         "to" => to,
         "content" => content_html,
+        "summary" => cw,
         "context" => context,
         "attachment" => attachments,
         "actor" => actor,
index b151c118a787330c27bffd462da0e00e43d67e56..8747dbb676efabcf69b201ce1eb8e535a5197fa3 100644 (file)
@@ -94,6 +94,7 @@ defmodule Pleroma.Web.OStatus.NoteHandler do
          [author] <- :xmerl_xpath.string('//author[1]', doc),
          {:ok, actor} <- OStatus.find_make_or_update_user(author),
          content_html <- OStatus.get_content(entry),
+         cw <- OStatus.get_cw(entry),
          inReplyTo <- XML.string_from_xpath("//thr:in-reply-to[1]/@ref", entry),
          inReplyToActivity <- fetch_replied_to_activity(entry, inReplyTo),
          inReplyTo <- (inReplyToActivity && inReplyToActivity.data["object"]["id"]) || inReplyTo,
@@ -103,7 +104,7 @@ defmodule Pleroma.Web.OStatus.NoteHandler do
          mentions <- get_mentions(entry),
          to <- make_to_list(actor, mentions),
          date <- XML.string_from_xpath("//published", entry),
-         note <- CommonAPI.Utils.make_note_data(actor.ap_id, to, context, content_html, attachments, inReplyToActivity, []),
+         note <- CommonAPI.Utils.make_note_data(actor.ap_id, to, context, content_html, attachments, inReplyToActivity, [], cw),
          note <- note |> Map.put("id", id) |> Map.put("tag", tags),
          note <- note |> Map.put("published", date),
          note <- note |> Map.put("emoji", get_emoji(entry)),
index bc975f82dc941e365a2ce3c968d676b97a4959b0..1e8b71357400c450340a18644c7becf9c5896211 100644 (file)
@@ -150,16 +150,20 @@ defmodule Pleroma.Web.OStatus do
   end
 
   @doc """
-    Gets the content from a an entry. Will add the cw text to the body for cw'd
-    Mastodon notes.
+    Gets the content from a an entry.
   """
   def get_content(entry) do
-    base_content = string_from_xpath("//content", entry)
+    string_from_xpath("//content", entry)
+  end
 
+  @doc """
+    Get the cw that mastodon uses.
+  """
+  def get_cw(entry) do
     with scope when not is_nil(scope) <- string_from_xpath("//mastodon:scope", entry),
          cw when not is_nil(cw) <- string_from_xpath("/*/summary", entry) do
-      "<span class='mastodon-cw'>#{cw}</span><br>#{base_content}"
-    else _e -> base_content
+      cw
+    else _e -> nil
     end
   end
 
index 95038b73ca328887205a88af10030fc480379d13..de01612b3a803b9ae2caff7976520ec24c1a212d 100644 (file)
@@ -85,7 +85,7 @@ defmodule Pleroma.Web.OStatusTest do
     assert activity.data["type"] == "Create"
     assert activity.data["object"]["type"] == "Note"
     assert activity.data["object"]["actor"] == "https://mastodon.social/users/lambadalambda"
-    assert String.contains?(activity.data["object"]["content"], "technologic")
+    assert activity.data["object"]["summary"] == "technologic"
     assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
   end
 
@@ -93,7 +93,7 @@ defmodule Pleroma.Web.OStatusTest do
     incoming = File.read!("test/fixtures/cw_retweet.xml")
     {:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
 
-    assert String.contains?(retweeted_activity.data["object"]["content"], "Hey.")
+    assert retweeted_activity.data["object"]["summary"] == "Hey."
   end
 
   test "handle incoming notes - GS, subscription, reply" do