From b248fc7dfb8c0d3b42a75225d4ad5489c51b5103 Mon Sep 17 00:00:00 2001 From: dtluna Date: Thu, 20 Apr 2017 10:57:37 +0300 Subject: [PATCH] Refactor unfollow/2 --- lib/pleroma/web/twitter_api/twitter_api.ex | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index 32d38b276..912467dee 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -124,24 +124,16 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do end end - def unfollow(%User{} = follower, %{ "user_id" => followed_id }) do - with %User{} = followed <- Repo.get(User, followed_id), - { :ok, follower } <- User.unfollow(follower, followed) + def unfollow(%User{} = follower, params) do + with { :ok, %User{} = unfollowed } <- get_user(params), + { :ok, follower } <- User.unfollow(follower, unfollowed) do - { :ok, follower, followed } + { :ok, follower, unfollowed} else err -> err end end - def unfollow(%User{} = follower, %{ "screen_name" => followed_name }) do - with %User{} = followed <- Repo.get_by(User, nickname: followed_name), - { :ok, follower } <- User.unfollow(follower, followed) - do - { :ok, follower, followed } - end - end - def favorite(%User{} = user, %Activity{data: %{"object" => object}} = activity) do object = Object.get_by_ap_id(object["id"]) -- 2.45.2