From: dtluna Date: Sun, 16 Apr 2017 10:28:23 +0000 (+0300) Subject: Merge branch 'develop' of ssh.gitgud.io:lambadalambda/pleroma into feature/unfollow... X-Git-Url: http://git.squeep.com/?a=commitdiff_plain;h=9a8c348aed7772c9e2173163687e63943cf491fb;p=akkoma Merge branch 'develop' of ssh.gitgud.io:lambadalambda/pleroma into feature/unfollow-by-screen-name --- 9a8c348aed7772c9e2173163687e63943cf491fb diff --cc lib/pleroma/web/twitter_api/twitter_api.ex index 897adf5ee,735d88832..569ef5d14 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@@ -123,15 -125,46 +125,54 @@@ defmodule Pleroma.Web.TwitterAPI.Twitte 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 upload(%Plug.Upload{} = file) do + def favorite(%User{} = user, %Activity{data: %{"object" => object}} = activity) do + object = Object.get_by_ap_id(object["id"]) + + {:ok, _like_activity, object} = ActivityPub.like(user, object) + new_data = activity.data + |> Map.put("object", object.data) + + status = %{activity | data: new_data} + |> activity_to_status(%{for: user}) + + {:ok, status} + end + + def unfavorite(%User{} = user, %Activity{data: %{"object" => object}} = activity) do + object = Object.get_by_ap_id(object["id"]) + + {:ok, object} = ActivityPub.unlike(user, object) + new_data = activity.data + |> Map.put("object", object.data) + + status = %{activity | data: new_data} + |> activity_to_status(%{for: user}) + + {:ok, status} + end + + def retweet(%User{} = user, %Activity{data: %{"object" => object}} = activity) do + object = Object.get_by_ap_id(object["id"]) + + {:ok, _announce_activity, object} = ActivityPub.announce(user, object) + new_data = activity.data + |> Map.put("object", object.data) + + status = %{activity | data: new_data} + |> activity_to_status(%{for: user}) + + {:ok, status} + end + + def upload(%Plug.Upload{} = file, format \\ "xml") do {:ok, object} = ActivityPub.upload(file) url = List.first(object.data["url"])