Remove inReplyToStatusId
authorrinpatch <rinpatch@sdf.org>
Mon, 15 Apr 2019 08:50:36 +0000 (11:50 +0300)
committerrinpatch <rinpatch@sdf.org>
Mon, 15 Apr 2019 08:50:36 +0000 (11:50 +0300)
CHANGELOG.md
lib/pleroma/activity.ex
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/activity_pub/transmogrifier.ex
lib/pleroma/web/common_api/utils.ex
lib/pleroma/web/twitter_api/views/activity_view.ex
test/activity_test.exs
test/web/activity_pub/transmogrifier_test.exs
test/web/mastodon_api/mastodon_api_controller_test.exs
test/web/twitter_api/twitter_api_test.exs

index cf751a496fbc9e12af3b5f355de53f73b4e1ac79..ebf21851ba807b0d8414ba56bfd3b933ad1fb8cb 100644 (file)
@@ -30,6 +30,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 - Link/mention/hashtag detection is now handled by [auto_linker](https://git.pleroma.social/pleroma/auto_linker)
 - NodeInfo: Return `safe_dm_mentions` feature flag
 - Federation: Expand the audience of delete activities to all recipients of the deleted object
+- Federation: Removed `inReplyToStatusId` from objects
 - Configuration: Dedupe enabled by default
 - Pleroma API: Support for emoji tags in `/api/pleroma/emoji` resulting in a breaking API change
 - Mastodon API: Support for `exclude_types`, `limit` and `min_id` in `/api/v1/notifications`
index ab8861b277b7683660e6ca031dd8f69db664522c..e6507e5ca011b342b8a656c6ce20e1476332eaaa 100644 (file)
@@ -246,20 +246,22 @@ defmodule Pleroma.Activity do
     |> Repo.all()
   end
 
-  def increase_replies_count(id) do
-    Activity
-    |> where(id: ^id)
-    |> update([a],
-      set: [
-        data:
-          fragment(
-            """
-            jsonb_set(?, '{object, repliesCount}',
-              (coalesce((?->'object'->>'repliesCount')::int, 0) + 1)::varchar::jsonb, true)
-            """,
-            a.data,
-            a.data
-          )
+  def increase_replies_count(nil), do: nil
+
+  def increase_replies_count(object_ap_id) do
+    from(a in create_by_object_ap_id(object_ap_id),
+      update: [
+        set: [
+          data:
+            fragment(
+              """
+              jsonb_set(?, '{object, repliesCount}',
+                (coalesce((?->'object'->>'repliesCount')::int, 0) + 1)::varchar::jsonb, true)
+              """,
+              a.data,
+              a.data
+            )
+        ]
       ]
     )
     |> Repo.update_all([])
@@ -269,20 +271,22 @@ defmodule Pleroma.Activity do
     end
   end
 
-  def decrease_replies_count(id) do
-    Activity
-    |> where(id: ^id)
-    |> update([a],
-      set: [
-        data:
-          fragment(
-            """
-            jsonb_set(?, '{object, repliesCount}',
-              (greatest(0, (?->'object'->>'repliesCount')::int - 1))::varchar::jsonb, true)
-            """,
-            a.data,
-            a.data
-          )
+  def decrease_replies_count(nil), do: nil
+
+  def decrease_replies_count(object_ap_id) do
+    from(a in create_by_object_ap_id(object_ap_id),
+      update: [
+        set: [
+          data:
+            fragment(
+              """
+              jsonb_set(?, '{object, repliesCount}',
+                (greatest(0, (?->'object'->>'repliesCount')::int - 1))::varchar::jsonb, true)
+              """,
+              a.data,
+              a.data
+            )
+        ]
       ]
     )
     |> Repo.update_all([])
index 89fee2d9fade7b65983c80bba3b0e36ddb97ba90..54dd4097c755ab99b798a8f11b41915d95d43228 100644 (file)
@@ -91,12 +91,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
   end
 
   def increase_replies_count_if_reply(%{
-        "object" =>
-          %{"inReplyTo" => reply_ap_id, "inReplyToStatusId" => reply_status_id} = object,
+        "object" => %{"inReplyTo" => reply_ap_id} = object,
         "type" => "Create"
       }) do
     if is_public?(object) do
-      Activity.increase_replies_count(reply_status_id)
+      Activity.increase_replies_count(reply_ap_id)
       Object.increase_replies_count(reply_ap_id)
     end
   end
@@ -104,10 +103,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
   def increase_replies_count_if_reply(_create_data), do: :noop
 
   def decrease_replies_count_if_reply(%Object{
-        data: %{"inReplyTo" => reply_ap_id, "inReplyToStatusId" => reply_status_id} = object
+        data: %{"inReplyTo" => reply_ap_id} = object
       }) do
     if is_public?(object) do
-      Activity.decrease_replies_count(reply_status_id)
+      Activity.decrease_replies_count(reply_ap_id)
       Object.decrease_replies_count(reply_ap_id)
     end
   end
index 49ea732041e7dbadd76514f6693f76e05866b9a6..39cd319212c415b265282dd12ae766907139c5f6 100644 (file)
@@ -225,12 +225,11 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
 
     case fetch_obj_helper(in_reply_to_id) do
       {:ok, replied_object} ->
-        with %Activity{} = activity <-
+        with %Activity{} = _activity <-
                Activity.get_create_by_object_ap_id(replied_object.data["id"]) do
           object
           |> Map.put("inReplyTo", replied_object.data["id"])
           |> Map.put("inReplyToAtomUri", object["inReplyToAtomUri"] || in_reply_to_id)
-          |> Map.put("inReplyToStatusId", activity.id)
           |> Map.put("conversation", replied_object.data["context"] || object["conversation"])
           |> Map.put("context", replied_object.data["context"] || object["conversation"])
         else
index 58a561a40fd8a2a8932432b830a9c2c274c5c27b..185292878b6e94f72ee9b5fbeb4730f63185c8b5 100644 (file)
@@ -228,7 +228,6 @@ defmodule Pleroma.Web.CommonAPI.Utils do
     if inReplyTo do
       object
       |> Map.put("inReplyTo", inReplyTo.data["object"]["id"])
-      |> Map.put("inReplyToStatusId", inReplyTo.id)
     else
       object
     end
index 433322eb8fbfce70632803921504a234d789b3b8..ecb2b437ba4cff9249284a7ca2da2d6ce6474975 100644 (file)
@@ -291,7 +291,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
       "is_local" => activity.local,
       "is_post_verb" => true,
       "created_at" => created_at,
-      "in_reply_to_status_id" => object["inReplyToStatusId"],
+      "in_reply_to_status_id" => reply_parent && reply_parent.id,
       "in_reply_to_screen_name" => reply_user && reply_user.nickname,
       "in_reply_to_profileurl" => User.profile_url(reply_user),
       "in_reply_to_ostatus_uri" => reply_user && reply_user.ap_id,
index ad889f544830a5ed8463312461c5ee35bdd3b7af..d8063bf11652611d03b17af1deb8b44298f89b2d 100644 (file)
@@ -28,4 +28,18 @@ defmodule Pleroma.ActivityTest do
 
     assert activity == found_activity
   end
+
+  test "reply count" do
+    %{id: id, data: %{"object" => %{"id" => object_ap_id}}} = activity = insert(:note_activity)
+
+    repliesCount = activity.data["object"]["repliesCount"] || 0
+    expected_increase = repliesCount + 1
+    Activity.increase_replies_count(object_ap_id)
+    %{data: %{"object" => %{"repliesCount" => actual_increase}}} = Activity.get_by_id(id)
+    assert expected_increase == actual_increase
+    expected_decrease = expected_increase - 1
+    Activity.decrease_replies_count(object_ap_id)
+    %{data: %{"object" => %{"repliesCount" => actual_decrease}}} = Activity.get_by_id(id)
+    assert expected_decrease == actual_decrease
+  end
 end
index 47cffe257827d7853fb5b33570cfa249d21c5c4e..c857a7ec1e44372f7a818b4454b7cfd413598be7 100644 (file)
@@ -58,8 +58,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
 
       assert returned_activity.data["object"]["inReplyToAtomUri"] ==
                "https://shitposter.club/notice/2827873"
-
-      assert returned_activity.data["object"]["inReplyToStatusId"] == activity.id
     end
 
     test "it works for incoming notices" do
index 292cd46b8198312895d56af2ba7f63514a39b791..df3315022d7d1d65b2523db2679811390317f2c9 100644 (file)
@@ -342,7 +342,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
     activity = Activity.get_by_id(id)
 
     assert activity.data["context"] == replied_to.data["context"]
-    assert activity.data["object"]["inReplyToStatusId"] == replied_to.id
+    assert Activity.get_in_reply_to_activity(activity).id == replied_to.id
   end
 
   test "posting a status with an invalid in_reply_to_id", %{conn: conn} do
@@ -2724,7 +2724,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
     activity = Activity.get_by_id(id)
 
     assert activity.data["object"]["inReplyTo"] == replied_to.data["object"]["id"]
-    assert activity.data["object"]["inReplyToStatusId"] == replied_to.id
+    assert Activity.get_in_reply_to_activity(activity).id == replied_to.id
 
     # Reblog from the third user
     conn2 =
index 6d43bd13a0ac1aca7217cfdf9b34f66574796d1a..8781061d4c1fad7bb0a1b021fbde32a763a50fd1 100644 (file)
@@ -105,7 +105,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
              get_in(activity.data, ["object", "context"])
 
     assert get_in(reply.data, ["object", "inReplyTo"]) == get_in(activity.data, ["object", "id"])
-    assert get_in(reply.data, ["object", "inReplyToStatusId"]) == activity.id
+    assert Activity.get_in_reply_to_activity(reply).id == activity.id
   end
 
   test "Follow another user using user_id" do