Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into remake-remodel-dms
authorlain <lain@soykaf.club>
Mon, 11 May 2020 15:14:58 +0000 (17:14 +0200)
committerlain <lain@soykaf.club>
Mon, 11 May 2020 15:14:58 +0000 (17:14 +0200)
1  2 
lib/pleroma/web/activity_pub/builder.ex
lib/pleroma/web/activity_pub/transmogrifier.ex
lib/pleroma/web/common_api/common_api.ex
test/web/activity_pub/side_effects_test.exs
test/web/common_api/common_api_test.exs

index 2a21a38119628e263582de341943dc6c8e07997d,4a247ad0ca425834e032d8c01df612c6ea3f5fa4..0107a8baabec82c8ea6916d65e22163a467beb0e
@@@ -63,42 -62,16 +63,52 @@@ defmodule Pleroma.Web.ActivityPub.Build
       }, []}
    end
  
 +  def create(actor, object, recipients) do
 +    {:ok,
 +     %{
 +       "id" => Utils.generate_activity_id(),
 +       "actor" => actor.ap_id,
 +       "to" => recipients,
 +       "object" => object,
 +       "type" => "Create",
 +       "published" => DateTime.utc_now() |> DateTime.to_iso8601()
 +     }, []}
 +  end
 +
 +  def chat_message(actor, recipient, content, opts \\ []) do
 +    basic = %{
 +      "id" => Utils.generate_object_id(),
 +      "actor" => actor.ap_id,
 +      "type" => "ChatMessage",
 +      "to" => [recipient],
 +      "content" => content,
 +      "published" => DateTime.utc_now() |> DateTime.to_iso8601(),
 +      "emoji" => Emoji.Formatter.get_emoji_map(content)
 +    }
 +
 +    case opts[:attachment] do
 +      %Object{data: attachment_data} ->
 +        {
 +          :ok,
 +          Map.put(basic, "attachment", attachment_data),
 +          []
 +        }
 +
 +      _ ->
 +        {:ok, basic, []}
 +    end
 +  end
 +
+   @spec tombstone(String.t(), String.t()) :: {:ok, map(), keyword()}
+   def tombstone(actor, id) do
+     {:ok,
+      %{
+        "id" => id,
+        "actor" => actor,
+        "type" => "Tombstone"
+      }, []}
+   end
    @spec like(User.t(), Object.t()) :: {:ok, map(), keyword()}
    def like(actor, object) do
      with {:ok, data, meta} <- object_action(actor, object) do
index 5501ba18bde0154b52edef29195930f0491bdfca,c524d1c0c3fe5ac5459ad5a81f9e9d4e7930bd9a..bc204e6e816adac628286479c85473bc35268baf
@@@ -24,58 -23,25 +24,76 @@@ defmodule Pleroma.Web.CommonAPITest d
    setup do: clear_config([:instance, :limit])
    setup do: clear_config([:instance, :max_pinned_statuses])
  
 +  describe "posting chat messages" do
 +    setup do: clear_config([:instance, :chat_limit])
 +
 +    test "it posts a chat message" do
 +      author = insert(:user)
 +      recipient = insert(:user)
 +
 +      {:ok, activity} =
 +        CommonAPI.post_chat_message(
 +          author,
 +          recipient,
 +          "a test message <script>alert('uuu')</script> :firefox:"
 +        )
 +
 +      assert activity.data["type"] == "Create"
 +      assert activity.local
 +      object = Object.normalize(activity)
 +
 +      assert object.data["type"] == "ChatMessage"
 +      assert object.data["to"] == [recipient.ap_id]
 +
 +      assert object.data["content"] ==
 +               "a test message &lt;script&gt;alert(&#39;uuu&#39;)&lt;/script&gt; :firefox:"
 +
 +      assert object.data["emoji"] == %{
 +               "firefox" => "http://localhost:4001/emoji/Firefox.gif"
 +             }
 +
 +      assert Chat.get(author.id, recipient.ap_id)
 +      assert Chat.get(recipient.id, author.ap_id)
 +
 +      assert :ok == Pleroma.Web.Federator.perform(:publish, activity)
 +    end
 +
 +    test "it reject messages over the local limit" do
 +      Pleroma.Config.put([:instance, :chat_limit], 2)
 +
 +      author = insert(:user)
 +      recipient = insert(:user)
 +
 +      {:error, message} =
 +        CommonAPI.post_chat_message(
 +          author,
 +          recipient,
 +          "123"
 +        )
 +
 +      assert message == :content_too_long
 +    end
 +  end
 +
    describe "deletion" do
+     test "it works with pruned objects" do
+       user = insert(:user)
+       {:ok, post} = CommonAPI.post(user, %{"status" => "namu amida butsu"})
+       Object.normalize(post, false)
+       |> Object.prune()
+       with_mock Pleroma.Web.Federator,
+         publish: fn _ -> nil end do
+         assert {:ok, delete} = CommonAPI.delete(post.id, user)
+         assert delete.local
+         assert called(Pleroma.Web.Federator.publish(delete))
+       end
+       refute Activity.get_by_id(post.id)
+     end
      test "it allows users to delete their posts" do
        user = insert(:user)