Merge branch 'develop' of ssh.gitgud.io:lambadalambda/pleroma into feature/unfollow...
authordtluna <dtluna@openmailbox.org>
Sun, 16 Apr 2017 10:28:23 +0000 (13:28 +0300)
committerdtluna <dtluna@openmailbox.org>
Sun, 16 Apr 2017 10:28:23 +0000 (13:28 +0300)
1  2 
lib/pleroma/web/twitter_api/twitter_api.ex
lib/pleroma/web/twitter_api/twitter_api_controller.ex
test/web/twitter_api/twitter_api_test.exs

index 897adf5ee5a38503a435c544cc9268adfb78d041,735d88832e5bf962c7e46c1cc4d44fca78dd7047..569ef5d14a7e7dd379c4512aa4c24997401c5857
@@@ -123,15 -125,46 +125,54 @@@ defmodule Pleroma.Web.TwitterAPI.Twitte
      end
    end
  
-   def upload(%Plug.Upload{} = file) do
 +  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"])
+     {: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"])