Merging with develop
authorAlex S <alex.strizhakov@gmail.com>
Wed, 1 May 2019 05:29:33 +0000 (12:29 +0700)
committerAlex S <alex.strizhakov@gmail.com>
Wed, 1 May 2019 05:29:33 +0000 (12:29 +0700)
Conflicts:
lib/pleroma/web/activity_pub/transmogrifier.ex
lib/pleroma/user.ex

1  2 
lib/pleroma/user.ex
lib/pleroma/web/activity_pub/relay.ex
lib/pleroma/web/activity_pub/transmogrifier.ex
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
lib/pleroma/web/twitter_api/twitter_api.ex

index 5e8dfc669ded609bd871d51e24a86395f0abf4a0,c5b1ddc5da0991b15d4ba93a44a693c00b927b74..755d8f773f96e67e56362aef6aaab8e02d266561
@@@ -1162,20 -1213,23 +1221,23 @@@ defmodule Pleroma.User d
    end
  
    def get_or_fetch_by_ap_id(ap_id) do
-     user = get_by_ap_id(ap_id)
+     user = get_cached_by_ap_id(ap_id)
  
      if !is_nil(user) and !User.needs_update?(user) do
 -      user
 +      {:ok, user}
      else
-       with %User{} = user <- fetch_by_ap_id(ap_id) do
-         if Pleroma.Config.get([:fetch_initial_posts, :enabled]) do
+       # Whether to fetch initial posts for the user (if it's a new user & the fetching is enabled)
+       should_fetch_initial = is_nil(user) and Pleroma.Config.get([:fetch_initial_posts, :enabled])
 -      user = fetch_by_ap_id(ap_id)
 -
+       if should_fetch_initial do
 -        with %User{} = user do
++        with {:ok, %User{} = user} = fetch_by_ap_id(ap_id) do
            {:ok, _} = Task.start(__MODULE__, :fetch_initial_posts, [user])
          end
 -      end
  
 -      user
 +        {:ok, user}
 +      else
 +        _ -> {:error, "Could not fetch by AP id"}
 +      end
      end
    end
  
Simple merge
index 546134f4656031c47bce6e64564368be571885b7,b1e859d7cf83d7bd2a5fd0ac28fdd94d8893e122..80317171d45d5b34d63874477d9d782763ad976b
@@@ -402,9 -436,13 +436,13 @@@ defmodule Pleroma.Web.ActivityPub.Trans
          %{"type" => "Follow", "object" => followed, "actor" => follower, "id" => id} = data
        ) do
      with %User{local: true} = followed <- User.get_cached_by_ap_id(followed),
 -         %User{} = follower <- User.get_or_fetch_by_ap_id(follower),
 +         {:ok, %User{} = follower} <- User.get_or_fetch_by_ap_id(follower),
           {:ok, activity} <- ActivityPub.follow(follower, followed, id, false) do
-       if not User.locked?(followed) do
+       with deny_follow_blocked <- Pleroma.Config.get([:user, :deny_follow_blocked]),
+            {:user_blocked, false} <-
+              {:user_blocked, User.blocks?(followed, follower) && deny_follow_blocked},
+            {:user_locked, false} <- {:user_locked, User.locked?(followed)},
+            {:follow, {:ok, follower}} <- {:follow, User.follow(follower, followed)} do
          ActivityPub.accept(%{
            to: [follower.ap_id],
            actor: followed,
    def handle_incoming(
          %{"type" => "Accept", "object" => follow_object, "actor" => _actor, "id" => _id} = data
        ) do
-     with actor <- get_actor(data),
+     with actor <- Containment.get_actor(data),
 -         %User{} = followed <- User.get_or_fetch_by_ap_id(actor),
 +         {:ok, %User{} = followed} <- User.get_or_fetch_by_ap_id(actor),
           {:ok, follow_activity} <- get_follow_activity(follow_object, followed),
           {:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "accept"),
           %User{local: true} = follower <- User.get_cached_by_ap_id(follow_activity.data["actor"]),
    def handle_incoming(
          %{"type" => "Reject", "object" => follow_object, "actor" => _actor, "id" => _id} = data
        ) do
-     with actor <- get_actor(data),
+     with actor <- Containment.get_actor(data),
 -         %User{} = followed <- User.get_or_fetch_by_ap_id(actor),
 +         {:ok, %User{} = followed} <- User.get_or_fetch_by_ap_id(actor),
           {:ok, follow_activity} <- get_follow_activity(follow_object, followed),
           {:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "reject"),
           %User{local: true} = follower <- User.get_cached_by_ap_id(follow_activity.data["actor"]),
    def handle_incoming(
          %{"type" => "Like", "object" => object_id, "actor" => _actor, "id" => id} = data
        ) do
-     with actor <- get_actor(data),
+     with actor <- Containment.get_actor(data),
 -         %User{} = actor <- User.get_or_fetch_by_ap_id(actor),
 +         {:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(actor),
-          {:ok, object} <- get_obj_helper(object_id) || fetch_obj_helper(object_id),
+          {:ok, object} <- get_obj_helper(object_id),
           {:ok, activity, _object} <- ActivityPub.like(actor, object, id, false) do
        {:ok, activity}
      else
    def handle_incoming(
          %{"type" => "Announce", "object" => object_id, "actor" => _actor, "id" => id} = data
        ) do
-     with actor <- get_actor(data),
+     with actor <- Containment.get_actor(data),
 -         %User{} = actor <- User.get_or_fetch_by_ap_id(actor),
 +         {:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(actor),
-          {:ok, object} <- get_obj_helper(object_id) || fetch_obj_helper(object_id),
+          {:ok, object} <- get_obj_helper(object_id),
           public <- Visibility.is_public?(data),
           {:ok, activity, _object} <- ActivityPub.announce(actor, object, id, false, public) do
        {:ok, activity}
        ) do
      object_id = Utils.get_ap_id(object_id)
  
-     with actor <- get_actor(data),
+     with actor <- Containment.get_actor(data),
 -         %User{} = actor <- User.get_or_fetch_by_ap_id(actor),
 +         {:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(actor),
-          {:ok, object} <- get_obj_helper(object_id) || fetch_obj_helper(object_id),
-          :ok <- contain_origin(actor.ap_id, object.data),
+          {:ok, object} <- get_obj_helper(object_id),
+          :ok <- Containment.contain_origin(actor.ap_id, object.data),
           {:ok, activity} <- ActivityPub.delete(object, false) do
        {:ok, activity}
      else
            "id" => id
          } = data
        ) do
-     with actor <- get_actor(data),
+     with actor <- Containment.get_actor(data),
 -         %User{} = actor <- User.get_or_fetch_by_ap_id(actor),
 +         {:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(actor),
-          {:ok, object} <- get_obj_helper(object_id) || fetch_obj_helper(object_id),
+          {:ok, object} <- get_obj_helper(object_id),
           {:ok, activity, _} <- ActivityPub.unannounce(actor, object, id, false) do
        {:ok, activity}
      else
            "id" => id
          } = data
        ) do
-     with actor <- get_actor(data),
+     with actor <- Containment.get_actor(data),
 -         %User{} = actor <- User.get_or_fetch_by_ap_id(actor),
 +         {:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(actor),
-          {:ok, object} <- get_obj_helper(object_id) || fetch_obj_helper(object_id),
+          {:ok, object} <- get_obj_helper(object_id),
           {:ok, activity, _, _} <- ActivityPub.unlike(actor, object, id, false) do
        {:ok, activity}
      else
index feadf86705474eac122f2414ab454271d6067dd1,adeac6f3c71489aa8f746fd954b3e852de10cbb6..3a777464784078dda93c10e388a8c41d11463e02
@@@ -282,37 -292,8 +292,8 @@@ defmodule Pleroma.Web.TwitterAPI.Twitte
      _activities = Repo.all(q)
    end
  
-   # DEPRECATED mostly, context objects are now created at insertion time.
-   def context_to_conversation_id(context) do
-     with %Object{id: id} <- Object.get_cached_by_ap_id(context) do
-       id
-     else
-       _e ->
-         changeset = Object.context_mapping(context)
-         case Repo.insert(changeset) do
-           {:ok, %{id: id}} ->
-             id
-           # This should be solved by an upsert, but it seems ecto
-           # has problems accessing the constraint inside the jsonb.
-           {:error, _} ->
-             Object.get_cached_by_ap_id(context).id
-         end
-     end
-   end
-   def conversation_id_to_context(id) do
-     with %Object{data: %{"id" => context}} <- Repo.get(Object, id) do
-       context
-     else
-       _e ->
-         {:error, "No such conversation"}
-     end
-   end
    def get_external_profile(for_user, uri) do
 -    with %User{} = user <- User.get_or_fetch(uri) do
 +    with {:ok, %User{} = user} <- User.get_or_fetch(uri) do
        {:ok, UserView.render("show.json", %{user: user, for: for_user})}
      else
        _e ->