Merge branch 'fix/activity-expirations-again' into 'develop'
authorfeld <feld@feld.me>
Thu, 13 Aug 2020 17:38:19 +0000 (17:38 +0000)
committerfeld <feld@feld.me>
Thu, 13 Aug 2020 17:38:19 +0000 (17:38 +0000)
Fix activity expirations again

See merge request pleroma/pleroma!2866

1  2 
lib/pleroma/web/activity_pub/side_effects.ex

index 5a02f1d69ec6a9a62ba12ba0054c1f6a2839566c,bff7c66290e3086cf93650da5b24c1f6bfa40e50..bcd6fd2fb1d55b10b31f37aa9586aa655dad33bc
@@@ -23,61 -22,10 +23,63 @@@ defmodule Pleroma.Web.ActivityPub.SideE
    alias Pleroma.Web.Streamer
    alias Pleroma.Workers.BackgroundWorker
  
+   require Logger
    def handle(object, meta \\ [])
  
 +  # Task this handles
 +  # - Follows
 +  # - Sends a notification
 +  def handle(
 +        %{
 +          data: %{
 +            "actor" => actor,
 +            "type" => "Accept",
 +            "object" => follow_activity_id
 +          }
 +        } = object,
 +        meta
 +      ) do
 +    with %Activity{actor: follower_id} = follow_activity <-
 +           Activity.get_by_ap_id(follow_activity_id),
 +         %User{} = followed <- User.get_cached_by_ap_id(actor),
 +         %User{} = follower <- User.get_cached_by_ap_id(follower_id),
 +         {:ok, follow_activity} <- Utils.update_follow_state_for_all(follow_activity, "accept"),
 +         {:ok, _relationship} <- FollowingRelationship.update(follower, followed, :follow_accept) do
 +      Notification.update_notification_type(followed, follow_activity)
 +      User.update_follower_count(followed)
 +      User.update_following_count(follower)
 +    end
 +
 +    {:ok, object, meta}
 +  end
 +
 +  # Task this handles
 +  # - Rejects all existing follow activities for this person
 +  # - Updates the follow state
 +  # - Dismisses notification
 +  def handle(
 +        %{
 +          data: %{
 +            "actor" => actor,
 +            "type" => "Reject",
 +            "object" => follow_activity_id
 +          }
 +        } = object,
 +        meta
 +      ) do
 +    with %Activity{actor: follower_id} = follow_activity <-
 +           Activity.get_by_ap_id(follow_activity_id),
 +         %User{} = followed <- User.get_cached_by_ap_id(actor),
 +         %User{} = follower <- User.get_cached_by_ap_id(follower_id),
 +         {:ok, _follow_activity} <- Utils.update_follow_state_for_all(follow_activity, "reject") do
 +      FollowingRelationship.update(follower, followed, :follow_reject)
 +      Notification.dismiss(follow_activity)
 +    end
 +
 +    {:ok, object, meta}
 +  end
 +
    # Tasks this handle
    # - Follows if possible
    # - Sends a notification