diff options
Diffstat (limited to 'lib/pleroma/web/twitter_api')
-rw-r--r-- | lib/pleroma/web/twitter_api/representers/activity_representer.ex | 14 | ||||
-rw-r--r-- | lib/pleroma/web/twitter_api/twitter_api.ex | 20 | ||||
-rw-r--r-- | lib/pleroma/web/twitter_api/twitter_api_controller.ex | 2 |
3 files changed, 29 insertions, 7 deletions
diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex index 32c6a48e9..5fe0df359 100644 --- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex @@ -3,6 +3,20 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do alias Pleroma.Web.TwitterAPI.Representers.{UserRepresenter, ObjectRepresenter} alias Pleroma.Activity + def to_map(%Activity{data: %{"type" => "Follow"}} = activity, %{user: user} = opts) do + %{ + "id" => activity.id, + "user" => UserRepresenter.to_map(user, opts), + "attentions" => [], + "statusnet_html" => "", # TODO: add summary + "text" => "", + "is_local" => true, + "is_post_verb" => false, + "created_at" => get_in(activity.data, ["published"]), + "in_reply_to_status_id" => nil, + } + end + def to_map(%Activity{} = activity, %{user: user} = opts) do content = get_in(activity.data, ["object", "content"]) published = get_in(activity.data, ["object", "published"]) diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index 2aaa73b78..932bef5ef 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -6,8 +6,6 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do import Ecto.Query def create_status(user = %User{}, data = %{}) do - date = DateTime.utc_now() |> DateTime.to_iso8601 - attachments = Enum.map(data["media_ids"] || [], fn (media_id) -> Repo.get(Object, media_id).data end) @@ -35,11 +33,11 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do "type" => "Note", "to" => to, "content" => content_html, - "published" => date, + "published" => make_date, "context" => context, "attachment" => attachments }, - "published" => date, + "published" => make_date, "context" => context } @@ -103,9 +101,15 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do def follow(%User{} = follower, followed_id) do with %User{} = followed <- Repo.get(User, followed_id), - { :ok, follower } <- User.follow(follower, followed) + { :ok, follower } <- User.follow(follower, followed), + { :ok, activity } <- ActivityPub.insert(%{ + "type" => "Follow", + "actor" => follower.ap_id, + "object" => followed.ap_id, + "published" => make_date + }) do - { :ok, follower, followed } + { :ok, follower, followed, activity } end end @@ -178,4 +182,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do mentioned_users = Repo.all(from user in User, where: user.ap_id in ^activity.data["to"]) ActivityRepresenter.to_map(activity, Map.merge(opts, %{user: user, mentioned: mentioned_users})) end + + defp make_date do + DateTime.utc_now() |> DateTime.to_iso8601 + end end diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 02b902d08..f2c893e96 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -44,7 +44,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end def follow(%{assigns: %{user: user}} = conn, %{ "user_id" => followed_id }) do - { :ok, _user, follower } = TwitterAPI.follow(user, followed_id) + { :ok, _user, follower, _activity } = TwitterAPI.follow(user, followed_id) response = follower |> UserRepresenter.to_json(%{for: user}) |