Save external link for notes.
authorRoger Braun <roger@rogerbraun.net>
Sun, 25 Jun 2017 09:57:34 +0000 (11:57 +0200)
committerRoger Braun <roger@rogerbraun.net>
Sun, 25 Jun 2017 09:57:34 +0000 (11:57 +0200)
lib/pleroma/web/ostatus/handlers/note_handler.ex
test/web/ostatus/ostatus_test.exs

index 0abc0ac5c5cb5751fa6191c25c76cb12b48afd27..82e60676f18c28851d464478216ee60e5bd12441 100644 (file)
@@ -49,6 +49,11 @@ defmodule Pleroma.Web.OStatus.NoteHandler do
     ] ++ mentions
   end
 
+  def add_external_url(note, entry) do
+    url = XML.string_from_xpath("//link[@rel='alternate' and @type='text/html']/@href", entry)
+    Map.put(note, "external_url", url)
+  end
+
   def handle_note(entry, doc \\ nil) do
     with id <- XML.string_from_xpath("//id", entry),
          activity when is_nil(activity) <- Activity.get_create_activity_by_object_ap_id(id),
@@ -67,6 +72,7 @@ defmodule Pleroma.Web.OStatus.NoteHandler do
          note <- TwitterAPI.Utils.make_note_data(actor.ap_id, to, context, content_html, attachments, inReplyToActivity, []),
          note <- note |> Map.put("id", id) |> Map.put("tag", tags),
          note <- note |> Map.put("published", date),
+         note <- add_external_url(note, entry),
          # TODO: Handle this case in make_note_data
          note <- (if inReplyTo && !inReplyToActivity, do: note |> Map.put("inReplyTo", inReplyTo), else: note)
       do
index 11b618fdbfcd1f03b729ddfc4d776cdd09c17f28..2d11b4664a1b78abea5e7f417a5634a63d97be3d 100644 (file)
@@ -45,6 +45,7 @@ defmodule Pleroma.Web.OStatusTest do
     assert activity.data["object"]["type"] == "Note"
     assert activity.data["object"]["actor"] == "https://social.heldscal.la/user/23211"
     assert activity.data["object"]["attachment"] |> length == 2
+    assert activity.data["object"]["external_url"] == "https://social.heldscal.la/notice/2020923"
   end
 
   test "handle incoming notes with tags" do