bd86a54c7bc88af42f805a60f86e60e239528099
[akkoma] / lib / pleroma / web / ostatus / handlers / unfollow_handler.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.OStatus.UnfollowHandler do
6 alias Pleroma.Web.{XML, OStatus}
7 alias Pleroma.Web.ActivityPub.ActivityPub
8 alias Pleroma.User
9
10 def handle(entry, doc) do
11 with {:ok, actor} <- OStatus.find_make_or_update_user(doc),
12 id when not is_nil(id) <- XML.string_from_xpath("/entry/id", entry),
13 followed_uri when not is_nil(followed_uri) <-
14 XML.string_from_xpath("/entry/activity:object/id", entry),
15 {:ok, followed} <- OStatus.find_or_make_user(followed_uri),
16 {:ok, activity} <- ActivityPub.unfollow(actor, followed, id, false) do
17 User.unfollow(actor, followed)
18 {:ok, activity}
19 end
20 end
21 end