diff options
author | eugenijm <eugenijm@protonmail.com> | 2019-03-13 09:04:49 +0300 |
---|---|---|
committer | eugenijm <eugenijm@protonmail.com> | 2019-03-13 20:28:36 +0300 |
commit | e416c344dd3e71447c49f8626750a56c35e389f6 (patch) | |
tree | d480733a1ec14ce4d1f503a007d95b62fdbab76b /lib/pleroma/web/common_api/common_api.ex | |
parent | 92a0210fb03ca3e0aefe769fb6b0ab7bda6e5336 (diff) | |
download | pleroma-e416c344dd3e71447c49f8626750a56c35e389f6.tar.gz |
Unify unfollow, accept and reject follow requests using CommonAPI
Diffstat (limited to 'lib/pleroma/web/common_api/common_api.ex')
-rw-r--r-- | lib/pleroma/web/common_api/common_api.ex | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index 12b3d308c..de0759fb0 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -27,6 +27,42 @@ defmodule Pleroma.Web.CommonAPI do end end + def unfollow(follower, unfollowed) do + with {:ok, follower, _follow_activity} <- User.unfollow(follower, unfollowed), + {:ok, _activity} <- ActivityPub.unfollow(follower, unfollowed) do + {:ok, follower} + end + end + + def accept_follow_request(follower, followed) do + with {:ok, follower} <- User.maybe_follow(follower, followed), + %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed), + {:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "accept"), + {:ok, _activity} <- + ActivityPub.accept(%{ + to: [follower.ap_id], + actor: followed, + object: follow_activity.data["id"], + type: "Accept" + }) do + {:ok, follower} + end + end + + def reject_follow_request(follower, followed) do + with %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed), + {:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "reject"), + {:ok, _activity} <- + ActivityPub.reject(%{ + to: [follower.ap_id], + actor: followed, + object: follow_activity.data["id"], + type: "Reject" + }) do + {:ok, follower} + end + end + def delete(activity_id, user) do with %Activity{data: %{"object" => %{"id" => object_id}}} <- Repo.get(Activity, activity_id), %Object{} = object <- Object.normalize(object_id), |