aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/object.ex22
-rw-r--r--lib/pleroma/object/fetcher.ex27
-rw-r--r--lib/pleroma/web/activity_pub/side_effects.ex24
3 files changed, 50 insertions, 23 deletions
diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex
index a893f2c1a..670ab8743 100644
--- a/lib/pleroma/object.ex
+++ b/lib/pleroma/object.ex
@@ -445,4 +445,26 @@ defmodule Pleroma.Object do
"orderedItems" => []
}
end
+
+ def maybe_update_history(updated_object, orig_object_data, updated) do
+ if not updated do
+ updated_object
+ else
+ # Put edit history
+ # Note that we may have got the edit history by first fetching the object
+ history = Object.history_for(orig_object_data)
+
+ latest_history_item =
+ orig_object_data
+ |> Map.drop(["id", "formerRepresentations"])
+
+ new_history =
+ history
+ |> Map.put("orderedItems", [latest_history_item | history["orderedItems"]])
+ |> Map.put("totalItems", history["totalItems"] + 1)
+
+ updated_object
+ |> Map.put("formerRepresentations", new_history)
+ end
+ end
end
diff --git a/lib/pleroma/object/fetcher.ex b/lib/pleroma/object/fetcher.ex
index deb3dc711..ce816c1fc 100644
--- a/lib/pleroma/object/fetcher.ex
+++ b/lib/pleroma/object/fetcher.ex
@@ -26,8 +26,35 @@ defmodule Pleroma.Object.Fetcher do
end
defp maybe_reinject_internal_fields(%{data: %{} = old_data}, new_data) do
+ has_history? = fn
+ %{"formerRepresentations" => %{"orderedItems" => list}} when is_list(list) -> true
+ _ -> false
+ end
+
internal_fields = Map.take(old_data, Pleroma.Constants.object_internal_fields())
+ remote_history_exists? = has_history?.(new_data)
+
+ # If the remote history exists, we treat that as the only source of truth.
+ new_data =
+ if has_history?.(old_data) and not remote_history_exists? do
+ Map.put(new_data, "formerRepresentations", old_data["formerRepresentations"])
+ else
+ new_data
+ end
+
+ # If the remote does not have history information, we need to manage it ourselves
+ new_data =
+ if not remote_history_exists? do
+ changed? =
+ Pleroma.Constants.status_updatable_fields()
+ |> Enum.any?(fn field -> Map.get(old_data, field) != Map.get(new_data, field) end)
+
+ new_data |> Object.maybe_update_history(old_data, changed?)
+ else
+ new_data
+ end
+
Map.merge(new_data, internal_fields)
end
diff --git a/lib/pleroma/web/activity_pub/side_effects.ex b/lib/pleroma/web/activity_pub/side_effects.ex
index 49054c320..52a343de7 100644
--- a/lib/pleroma/web/activity_pub/side_effects.ex
+++ b/lib/pleroma/web/activity_pub/side_effects.ex
@@ -431,28 +431,6 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
)
end
- defp maybe_update_history(updated_object, orig_object_data, updated) do
- if not updated do
- updated_object
- else
- # Put edit history
- # Note that we may have got the edit history by first fetching the object
- history = Object.history_for(orig_object_data)
-
- latest_history_item =
- orig_object_data
- |> Map.drop(["id", "formerRepresentations"])
-
- new_history =
- history
- |> Map.put("orderedItems", [latest_history_item | history["orderedItems"]])
- |> Map.put("totalItems", history["totalItems"] + 1)
-
- updated_object
- |> Map.put("formerRepresentations", new_history)
- end
- end
-
defp maybe_update_poll(to_be_updated, updated_object) do
choice_key = fn data ->
if Map.has_key?(data, "anyOf"), do: "anyOf", else: "oneOf"
@@ -487,7 +465,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
updated_object_data =
updated_object_data
- |> maybe_update_history(orig_object_data, updated)
+ |> Object.maybe_update_history(orig_object_data, updated)
|> maybe_update_poll(updated_object)
orig_object