Strip status data from Flag (when federating or closing/resolving report)
This commit is contained in:
parent
b08b1d5d91
commit
8eff05d4c6
5 changed files with 119 additions and 35 deletions
|
|
@ -22,6 +22,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
|||
require Pleroma.Constants
|
||||
|
||||
@supported_object_types ["Article", "Note", "Video", "Page", "Question", "Answer", "Audio"]
|
||||
@strip_status_report_states ~w(closed resolved)
|
||||
@supported_report_states ~w(open closed resolved)
|
||||
@valid_visibilities ~w(public unlisted private direct)
|
||||
|
||||
|
|
@ -673,6 +674,20 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
|||
|
||||
#### Report-related helpers
|
||||
|
||||
def update_report_state(%Activity{} = activity, state)
|
||||
when state in @strip_status_report_states do
|
||||
{:ok, stripped_activity} = strip_report_status_data(activity)
|
||||
|
||||
new_data =
|
||||
activity.data
|
||||
|> Map.put("state", state)
|
||||
|> Map.put("object", stripped_activity.data["object"])
|
||||
|
||||
activity
|
||||
|> Changeset.change(data: new_data)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
def update_report_state(%Activity{} = activity, state) when state in @supported_report_states do
|
||||
new_data = Map.put(activity.data, "state", state)
|
||||
|
||||
|
|
@ -683,6 +698,14 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
|||
|
||||
def update_report_state(_, _), do: {:error, "Unsupported state"}
|
||||
|
||||
def strip_report_status_data(activity) do
|
||||
[actor | reported_activities] = activity.data["object"]
|
||||
stripped_activities = Enum.map(reported_activities, & &1["id"])
|
||||
new_data = put_in(activity.data, ["object"], [actor | stripped_activities])
|
||||
|
||||
{:ok, %{activity | data: new_data}}
|
||||
end
|
||||
|
||||
def update_activity_visibility(activity, visibility) when visibility in @valid_visibilities do
|
||||
[to, cc, recipients] =
|
||||
activity
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue