Don't break on empty mentions.
authorRoger Braun <roger@rogerbraun.net>
Thu, 24 Aug 2017 10:54:01 +0000 (12:54 +0200)
committerRoger Braun <roger@rogerbraun.net>
Thu, 24 Aug 2017 10:54:01 +0000 (12:54 +0200)
lib/pleroma/web/ostatus/handlers/note_handler.ex
lib/pleroma/web/twitter_api/twitter_api.ex
test/web/ostatus/ostatus_test.exs

index e67f67b37c03bd754a4172bf430fbe7c2c75a0e3..f9aa463a0432300700eb1ee5462487241a998aee 100644 (file)
@@ -55,8 +55,9 @@ defmodule Pleroma.Web.OStatus.NoteHandler do
   end
 
   def get_mentions(entry) do
-    get_people_mentions(entry)
-    ++ get_collection_mentions(entry)
+    (get_people_mentions(entry)
+      ++ get_collection_mentions(entry))
+    |> Enum.filter(&(&1))
   end
 
   def make_to_list(actor, mentions) do
index dc66e27adba77965769539eed976b15a7daa8cdf..de39834ca83b5abc796834a9dd9a443f70767695 100644 (file)
@@ -270,7 +270,11 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
     user = User.get_cached_by_ap_id(actor)
     # mentioned_users = Repo.all(from user in User, where: user.ap_id in ^activity.data["to"])
     mentioned_users = Enum.map(activity.data["to"] || [], fn (ap_id) ->
-      User.get_cached_by_ap_id(ap_id)
+      if ap_id do
+        User.get_cached_by_ap_id(ap_id)
+      else
+        nil
+      end
     end)
     |> Enum.filter(&(&1))
 
index 44d687d8e9a1a1d196548edae715447c9d9ddd04..8dd3c3b54c65d77a8cf50a772ad92c1636191246 100644 (file)
@@ -346,4 +346,11 @@ defmodule Pleroma.Web.OStatusTest do
 
     assert {:ok, %User{}} = OStatus.insert_or_update_user(data)
   end
+
+  test "it doesn't add nil in the do field" do
+    incoming = File.read!("test/fixtures/nil_mention_entry.xml")
+    {:ok, [activity]} = OStatus.handle_incoming(incoming)
+
+    assert activity.data["to"] == ["http://localhost:4001/users/atarifrosch@social.stopwatchingus-heidelberg.de/followers", "https://www.w3.org/ns/activitystreams#Public"]
+  end
 end