From: Egor Kislitsyn Date: Mon, 1 Jun 2020 11:48:51 +0000 (+0400) Subject: Merge remote-tracking branch 'origin/develop' into global-status-expiration X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=a7627bdc7ae67a5c103f968eea02d6b1cf1ef8da;p=akkoma Merge remote-tracking branch 'origin/develop' into global-status-expiration --- a7627bdc7ae67a5c103f968eea02d6b1cf1ef8da diff --cc CHANGELOG.md index 9a38e4c11,839bf90ab..997be5dc0 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@@ -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
API Changes - **Breaking:** Emoji API: changed methods and renamed routes. diff --cc docs/configuration/cheatsheet.md index 8b8988fa7,505acb293..456762151 --- a/docs/configuration/cheatsheet.md +++ b/docs/configuration/cheatsheet.md @@@ -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 diff --cc lib/pleroma/web/activity_pub/activity_pub.ex index 4b865b342,b8a2873d8..7f6b59cc6 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@@ -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), diff --cc lib/pleroma/web/common_api/common_api.ex index 84888115b,dbb3d7ade..d452429c0 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@@ -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 diff --cc test/workers/cron/purge_expired_activities_worker_test.exs index beac55fb2,5864f9e5f..6d2991a60 --- a/test/workers/cron/purge_expired_activities_worker_test.exs +++ b/test/workers/cron/purge_expired_activities_worker_test.exs @@@ -39,35 -36,6 +39,35 @@@ defmodule Pleroma.Workers.Cron.PurgeExp refute Pleroma.Repo.get(Pleroma.ActivityExpiration, expiration.id) end + 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"}) ++ {: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 ->