diff options
| author | kaniini <nenolod@gmail.com> | 2019-03-16 19:27:56 +0000 | 
|---|---|---|
| committer | kaniini <nenolod@gmail.com> | 2019-03-16 19:27:56 +0000 | 
| commit | 6d6f48d0795cc12d3c5aca5d90ae51b10086996d (patch) | |
| tree | 15c78f3bff24635de54ed07197cf4830bc72aa73 /lib | |
| parent | 28df397454de5fd824490086206c70803b4da2d5 (diff) | |
| parent | 423fd07928d64dd7810ac408265a37ae1274956f (diff) | |
| download | pleroma-6d6f48d0795cc12d3c5aca5d90ae51b10086996d.tar.gz pleroma-6d6f48d0795cc12d3c5aca5d90ae51b10086996d.zip | |
Merge branch 'feature/federated-flags' into 'develop'
Federated reports
See merge request pleroma/pleroma!935
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/pleroma/web/activity_pub/activity_pub.ex | 28 | ||||
| -rw-r--r-- | lib/pleroma/web/activity_pub/transmogrifier.ex | 34 | ||||
| -rw-r--r-- | lib/pleroma/web/activity_pub/utils.ex | 8 | ||||
| -rw-r--r-- | lib/pleroma/web/common_api/common_api.ex | 9 | 
4 files changed, 66 insertions, 13 deletions
| diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index a65d6e020..2470b4a71 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -370,20 +370,38 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do            content: content          } = params        ) do -    additional = params[:additional] || %{} -      # only accept false as false value      local = !(params[:local] == false) +    forward = !(params[:forward] == false) + +    additional = params[:additional] || %{} -    %{ +    params = %{        actor: actor,        context: context,        account: account,        statuses: statuses,        content: content      } -    |> make_flag_data(additional) -    |> insert(local) + +    additional = +      if forward do +        Map.merge(additional, %{"to" => [], "cc" => [account.ap_id]}) +      else +        Map.merge(additional, %{"to" => [], "cc" => []}) +      end + +    with flag_data <- make_flag_data(params, additional), +         {:ok, activity} <- insert(flag_data, local), +         :ok <- maybe_federate(activity) do +      Enum.each(User.all_superusers(), fn superuser -> +        superuser +        |> Pleroma.AdminEmail.report(actor, account, statuses, content) +        |> Pleroma.Mailer.deliver_async() +      end) + +      {:ok, activity} +    end    end    def fetch_activities_for_context(context, opts \\ %{}) do diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 1247e4b61..8e4bf7b47 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -355,6 +355,40 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do      end    end +  # Flag objects are placed ahead of the ID check because Mastodon 2.8 and earlier send them +  # with nil ID. +  def handle_incoming(%{"type" => "Flag", "object" => objects, "actor" => actor} = data) do +    with context <- data["context"] || Utils.generate_context_id(), +         content <- data["content"] || "", +         %User{} = actor <- User.get_cached_by_ap_id(actor), + +         # Reduce the object list to find the reported user. +         %User{} = account <- +           Enum.reduce_while(objects, nil, fn ap_id, _ -> +             with %User{} = user <- User.get_cached_by_ap_id(ap_id) do +               {:halt, user} +             else +               _ -> {:cont, nil} +             end +           end), + +         # Remove the reported user from the object list. +         statuses <- Enum.filter(objects, fn ap_id -> ap_id != account.ap_id end) do +      params = %{ +        actor: actor, +        context: context, +        account: account, +        statuses: statuses, +        content: content, +        additional: %{ +          "cc" => [account.ap_id] +        } +      } + +      ActivityPub.flag(params) +    end +  end +    # disallow objects with bogus IDs    def handle_incoming(%{"id" => nil}), do: :error    def handle_incoming(%{"id" => ""}), do: :error diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 182f9cacb..af317245f 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -621,7 +621,13 @@ defmodule Pleroma.Web.ActivityPub.Utils do    #### Flag-related helpers    def make_flag_data(params, additional) do -    status_ap_ids = Enum.map(params.statuses || [], & &1.data["id"]) +    status_ap_ids = +      Enum.map(params.statuses || [], fn +        %Activity{} = act -> act.data["id"] +        act when is_map(act) -> act["id"] +        act when is_binary(act) -> act +      end) +      object = [params.account.ap_id] ++ status_ap_ids      %{ diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index 84d66efc9..b5f79c3bf 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -284,14 +284,9 @@ defmodule Pleroma.Web.CommonAPI do               actor: user,               account: account,               statuses: statuses, -             content: content_html +             content: content_html, +             forward: data["forward"] || false             }) do -      Enum.each(User.all_superusers(), fn superuser -> -        superuser -        |> Pleroma.AdminEmail.report(user, account, statuses, content_html) -        |> Pleroma.Mailer.deliver_async() -      end) -        {:ok, activity}      else        {:error, err} -> {:error, err} | 
