Merge remote-tracking branch 'origin/develop' into global-status-expiration
authorEgor Kislitsyn <egor@kislitsyn.com>
Mon, 1 Jun 2020 11:48:51 +0000 (15:48 +0400)
committerEgor Kislitsyn <egor@kislitsyn.com>
Mon, 1 Jun 2020 11:48:51 +0000 (15:48 +0400)
1  2 
CHANGELOG.md
config/config.exs
config/description.exs
docs/configuration/cheatsheet.md
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/common_api/activity_draft.ex
lib/pleroma/web/common_api/common_api.ex
test/web/activity_pub/activity_pub_test.exs
test/workers/cron/purge_expired_activities_worker_test.exs

diff --cc CHANGELOG.md
index 9a38e4c115fc24de786b18a7c0709ced05e43e86,839bf90ab984a3a09c8e54021dfd42a135228894..997be5dc057eac24c46281bc3b74cfa8ff6769f9
@@@ -6,6 -6,6 +6,7 @@@ The format is based on [Keep a Changelo
  ## [unreleased]
  
  ### Changed
++- MFR policy to set global expiration for all local Create activities
  <details>
    <summary>API Changes</summary>
  - **Breaking:** Emoji API: changed methods and renamed routes.
Simple merge
Simple merge
index 8b8988fa75102cd602448485c84cbc405ebcc87e,505acb293fcb5f02d13a61e16949e0106dc94a6d..456762151fc82d844b507899e2ddd925d1fc8214
@@@ -146,10 -149,11 +150,15 @@@ config :pleroma, :mrf_user_allowlist
    * `:strip_followers` removes followers from the ActivityPub recipient list, ensuring they won't be delivered to home timelines
    * `:reject` rejects the message entirely
  
+ #### mrf_steal_emoji
+ * `hosts`: List of hosts to steal emojis from
+ * `rejected_shortcodes`: Regex-list of shortcodes to reject
+ * `size_limit`: File size limit (in bytes), checked before an emoji is saved to the disk
 +#### :mrf_activity_expiration
 +
 +* `days`: Default global expiration time for all local Create activities (in days)
 +
  ### :activitypub
  * `unfollow_blocked`: Whether blocks result in people getting unfollowed
  * `outgoing_blocks`: Whether to federate blocks to other instances
index 4b865b3429cb3653acb32cfdd1579b91532f5fb8,b8a2873d84b7a568fa0bec2237ede6a535164f25..7f6b59cc625ffe96d3b7abe9040284062a0f1342
@@@ -201,14 -192,15 +195,23 @@@ defmodule Pleroma.Web.ActivityPub.Activ
      end
    end
  
+   def notify_and_stream(activity) do
+     Notification.create_notifications(activity)
+     conversation = create_or_bump_conversation(activity, activity.actor)
+     participations = get_participations(conversation)
+     stream_out(activity)
+     stream_out_participations(participations)
+   end
 +  defp maybe_create_activity_expiration({:ok, %{data: %{"expires_at" => expires_at}} = activity}) do
 +    with {:ok, _} <- ActivityExpiration.create(activity, expires_at) do
 +      {:ok, activity}
 +    end
 +  end
 +
 +  defp maybe_create_activity_expiration(result), do: result
 +
    defp create_or_bump_conversation(activity, actor) do
      with {:ok, conversation} <- Conversation.create_or_bump_for(activity),
           %User{} = user <- User.get_cached_by_ap_id(actor),
index 84888115bbd412339798d9cb07288d0cadbd4285,dbb3d7ade5d7bed0f3a855c56d1cc103a54085ec..d452429c01185ab92602a5a48ceaee2801748a9e
@@@ -321,9 -372,11 +372,9 @@@ defmodule Pleroma.Web.CommonAPI d
      end
    end
  
-   def post(user, %{"status" => _} = data) do
+   def post(user, %{status: _} = data) do
      with {:ok, draft} <- Pleroma.Web.CommonAPI.ActivityDraft.create(user, data) do
 -      draft.changes
 -      |> ActivityPub.create(draft.preview?)
 -      |> maybe_create_activity_expiration(draft.expires_at)
 +      ActivityPub.create(draft.changes, draft.preview?)
      end
    end
  
index beac55fb270c31487e35a728f31e6a2959638a43,5864f9e5f675f2d420cad8ac39de3b1b3ec8b94e..6d2991a6071d3b19ea5aab0d787fa86a2f007a9f
@@@ -39,35 -36,6 +39,35 @@@ defmodule Pleroma.Workers.Cron.PurgeExp
      refute Pleroma.Repo.get(Pleroma.ActivityExpiration, expiration.id)
    end
  
-     {:ok, %{id: id} = activity} = Pleroma.Web.CommonAPI.post(user, %{"status" => "cofe"})
 +  test "works with ActivityExpirationPolicy" do
 +    Pleroma.Config.put([ActivityExpiration, :enabled], true)
 +
 +    Pleroma.Config.put(
 +      [:instance, :rewrite_policy],
 +      Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicy
 +    )
 +
 +    user = insert(:user)
 +
 +    days = Pleroma.Config.get([:mrf_activity_expiration, :days], 365)
 +
++    {:ok, %{id: id} = activity} = Pleroma.Web.CommonAPI.post(user, %{status: "cofe"})
 +
 +    past_date =
 +      NaiveDateTime.utc_now() |> Timex.shift(days: -days) |> NaiveDateTime.truncate(:second)
 +
 +    activity
 +    |> Repo.preload(:expiration)
 +    |> Map.get(:expiration)
 +    |> Ecto.Changeset.change(%{scheduled_at: past_date})
 +    |> Repo.update!()
 +
 +    Pleroma.Workers.Cron.PurgeExpiredActivitiesWorker.perform(:ops, :pid)
 +
 +    assert [%{data: %{"type" => "Delete", "deleted_activity_id" => ^id}}] =
 +             Pleroma.Repo.all(Pleroma.Activity)
 +  end
 +
    describe "delete_activity/1" do
      test "adds log message if activity isn't find" do
        assert capture_log([level: :error], fn ->