logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

follow_handler.ex (1015B)


      1 # Pleroma: A lightweight social networking server
      2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
      3 # SPDX-License-Identifier: AGPL-3.0-only
      4 
      5 defmodule Pleroma.Web.OStatus.FollowHandler do
      6   alias Pleroma.User
      7   alias Pleroma.Web.ActivityPub.ActivityPub
      8   alias Pleroma.Web.OStatus
      9   alias Pleroma.Web.XML
     10 
     11   def handle(entry, doc) do
     12     with {:ok, actor} <- OStatus.find_make_or_update_actor(doc),
     13          id when not is_nil(id) <- XML.string_from_xpath("/entry/id", entry),
     14          followed_uri when not is_nil(followed_uri) <-
     15            XML.string_from_xpath("/entry/activity:object/id", entry),
     16          {:ok, followed} <- OStatus.find_or_make_user(followed_uri),
     17          {:locked, false} <- {:locked, followed.info.locked},
     18          {:ok, activity} <- ActivityPub.follow(actor, followed, id, false) do
     19       User.follow(actor, followed)
     20       {:ok, activity}
     21     else
     22       {:locked, true} ->
     23         {:error, "It's not possible to follow locked accounts over OStatus"}
     24     end
     25   end
     26 end