Add current user to mentioned
authorMaxim Filippov <colixer@gmail.com>
Sat, 19 Jan 2019 01:25:15 +0000 (04:25 +0300)
committerMaxim Filippov <colixer@gmail.com>
Sat, 19 Jan 2019 01:25:15 +0000 (04:25 +0300)
lib/pleroma/web/twitter_api/representers/activity_representer.ex
test/user_test.exs
test/web/activity_pub/activity_pub_test.exs
test/web/mastodon_api/mastodon_api_controller_test.exs
test/web/mastodon_api/status_view_test.exs
test/web/twitter_api/views/activity_view_test.exs

index 4f8f228ab87c68eee620f66a4ca7fbd0a76aa918..0ddbef63422fe3d143ae9f2c852a14839e4871a3 100644 (file)
@@ -155,7 +155,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
     repeated = opts[:for] && opts[:for].ap_id in (object["announcements"] || [])
     pinned = activity.id in user.info.pinned_activities
 
-    mentions = opts[:mentioned] || []
+    mentions = get_mentioned_users(opts[:mentioned] || [], user)
 
     attentions =
       activity.recipients
@@ -224,6 +224,10 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
     end
   end
 
+  defp get_mentioned_users(mentioned, user) do
+    mentioned ++ [user]
+  end
+
   defp to_boolean(false) do
     false
   end
index cfccce8d118dadba29cd27299053d615957b89ad..935c9c5b120de7ede8487d40e82c96e6265f3110 100644 (file)
@@ -672,12 +672,13 @@ defmodule Pleroma.UserTest do
         "status" => "hey @#{addressed.nickname} @#{addressed_remote.nickname}"
       })
 
-    assert [addressed] == User.get_recipients_from_activity(activity)
+    assert Enum.map([actor, addressed], & &1.ap_id) --
+             Enum.map(User.get_recipients_from_activity(activity), & &1.ap_id) == []
 
     {:ok, user} = User.follow(user, actor)
     {:ok, _user_two} = User.follow(user_two, actor)
     recipients = User.get_recipients_from_activity(activity)
-    assert length(recipients) == 2
+    assert length(recipients) == 3
     assert user in recipients
     assert addressed in recipients
   end
index eafb96f3a303cfd798577e251c3e4754e3d9c878..6b1debc611e04d06a1cdbc011e6db436d4a7b47e 100644 (file)
@@ -160,7 +160,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
 
       assert activity.data["to"] == ["user1", "user2"]
       assert activity.actor == user.ap_id
-      assert activity.recipients == ["user1", "user2"]
+      assert activity.recipients == ["user1", "user2", user.ap_id]
     end
   end
 
index ce3aa5a026fd9041a65deaa813343c86eaa39c8e..fdd3f12130e6f16d336827bcd3c062a5e2965080 100644 (file)
@@ -147,7 +147,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
 
     assert %{"id" => id, "visibility" => "direct"} = json_response(conn, 200)
     assert activity = Repo.get(Activity, id)
-    assert activity.recipients == [user2.ap_id]
+    assert activity.recipients == [user2.ap_id, user1.ap_id]
     assert activity.data["to"] == [user2.ap_id]
     assert activity.data["cc"] == []
   end
index 1076b500252455068be3f2036d7ae5ffccc7743c..5779a030e16efa086eb0e38b3d117c871a16d970 100644 (file)
@@ -119,7 +119,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
 
     status = StatusView.render("status.json", %{activity: activity})
 
-    assert status.mentions == [AccountView.render("mention.json", %{user: user})]
+    actor = Repo.get_by(User, ap_id: activity.actor)
+    
+    assert status.mentions == Enum.map([user, actor], fn u -> AccountView.render("mention.json", %{user: u}) end)
   end
 
   test "attachments" do
index 8b5a16add9b12d30f0cf0be0c067620e01ee469e..4aa8c16bc90f37fb4f24c3d0285f183ca86fb526 100644 (file)
@@ -118,9 +118,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
     expected = %{
       "activity_type" => "post",
       "attachments" => [],
-      "attentions" => [
-        UserView.render("show.json", %{user: other_user})
-      ],
+      "attentions" => Enum.map([other_user, user], fn u -> UserView.render("show.json", %{user: u}) end),
       "created_at" => activity.data["object"]["published"] |> Utils.date_to_asctime(),
       "external_url" => activity.data["object"]["id"],
       "fave_num" => 0,