From 48b6ae2314ffc087d1db33b0caaee34b877120c3 Mon Sep 17 00:00:00 2001 From: dtluna Date: Mon, 10 Apr 2017 15:41:21 +0300 Subject: Add GET route for verify_credentials --- lib/pleroma/web/router.ex | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 52030d684..0d2432b9e 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -30,6 +30,7 @@ defmodule Pleroma.Web.Router do scope "/api", Pleroma.Web do pipe_through :authenticated_api + get "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials post "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials post "/statuses/update", TwitterAPI.Controller, :status_update get "/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline -- cgit v1.2.3 From 6f99765fbace8081455e57cf2077ba42fd06d338 Mon Sep 17 00:00:00 2001 From: dtluna Date: Mon, 10 Apr 2017 18:26:14 +0300 Subject: Add home timeline --- lib/pleroma/web/router.ex | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 52030d684..66dcbb118 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -32,6 +32,7 @@ defmodule Pleroma.Web.Router do post "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials post "/statuses/update", TwitterAPI.Controller, :status_update + get "/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline get "/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline post "/friendships/create", TwitterAPI.Controller, :follow post "/friendships/destroy", TwitterAPI.Controller, :unfollow -- cgit v1.2.3 From 15655d992e8ba2aa8d4680eb38a8d3039b58703a Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Wed, 12 Apr 2017 16:38:55 +0200 Subject: Fix user representation after following. --- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index f2c893e96..c3a58b63a 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, _activity } = TwitterAPI.follow(user, followed_id) + { :ok, user, follower, _activity } = TwitterAPI.follow(user, followed_id) response = follower |> UserRepresenter.to_json(%{for: user}) -- cgit v1.2.3 From 8eea09889b114a27eaf6ca1998b4d3ca3505ad51 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Wed, 12 Apr 2017 16:45:23 +0200 Subject: Return directly addressed activities in friends timeline. --- lib/pleroma/web/twitter_api/twitter_api.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index 0a942e880..0217b28d6 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -69,7 +69,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do end def fetch_friend_statuses(user, opts \\ %{}) do - ActivityPub.fetch_activities(user.following, opts) + ActivityPub.fetch_activities([user.ap_id | user.following], opts) |> activities_to_statuses(%{for: user}) end -- cgit v1.2.3 From b666f11d2fc32b10dce0d36e72cc285377c28f18 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Wed, 12 Apr 2017 17:11:01 +0200 Subject: Add max_id fetching to activity fetching. --- lib/pleroma/web/activity_pub/activity_pub.ex | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index ec9c5e970..75e4101f2 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -54,6 +54,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do query = from activity in query, where: activity.id > ^since_id + query = if opts["max_id"] do + from activity in query, where: activity.id < ^opts["max_id"] + else + query + end + Repo.all(query) |> Enum.reverse end -- cgit v1.2.3 From 1b086834bd83a490e55d44ffa5167c8856db92d9 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Wed, 12 Apr 2017 17:22:29 +0200 Subject: Don't return html in the text field. --- lib/pleroma/web/twitter_api/representers/activity_representer.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex index 5fe0df359..b0dd85bbb 100644 --- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex @@ -33,7 +33,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do "user" => UserRepresenter.to_map(user, opts), "attentions" => [], "statusnet_html" => content, - "text" => content, + "text" => HtmlSanitizeEx.strip_tags(content), "is_local" => true, "is_post_verb" => true, "created_at" => published, -- cgit v1.2.3 From 129e30f4658312e8bb1737fd5577497107fbdeb1 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Wed, 12 Apr 2017 17:47:05 +0200 Subject: Add basic config endpoint. --- lib/pleroma/web/router.ex | 1 + lib/pleroma/web/twitter_api/twitter_api_controller.ex | 14 ++++++++++++++ 2 files changed, 15 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 52030d684..17eab293a 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -25,6 +25,7 @@ defmodule Pleroma.Web.Router do get "/statuses/public_and_external_timeline", TwitterAPI.Controller, :public_timeline get "/statuses/show/:id", TwitterAPI.Controller, :fetch_status get "/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation + get "/statusnet/config", TwitterAPI.Controller, :config end scope "/api", Pleroma.Web do diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index c3a58b63a..3f299a941 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -83,6 +83,20 @@ defmodule Pleroma.Web.TwitterAPI.Controller do |> send_resp(200, response) end + def config(conn, _params) do + response = %{ + site: %{ + name: Pleroma.Web.base_url, + server: Pleroma.Web.base_url, + textlimit: -1 + } + } + |> Poison.encode! + + conn + |> json_reply(200, response) + end + defp json_reply(conn, status, json) do conn |> put_resp_content_type("application/json") -- cgit v1.2.3 From d2bf099ae66b7332128c854f322bb8a00eb62212 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Wed, 12 Apr 2017 19:34:58 +0200 Subject: Fix twitter api date. --- .../twitter_api/representers/activity_representer.ex | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex index b0dd85bbb..9e4ffaefe 100644 --- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex @@ -3,7 +3,11 @@ 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 + created_at = get_in(activity.data, ["published"]) + |> date_to_asctime + %{ "id" => activity.id, "user" => UserRepresenter.to_map(user, opts), @@ -12,14 +16,15 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do "text" => "", "is_local" => true, "is_post_verb" => false, - "created_at" => get_in(activity.data, ["published"]), + "created_at" => created_at, "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"]) + created_at = get_in(activity.data, ["object", "published"]) + |> date_to_asctime mentions = opts[:mentioned] || [] @@ -36,11 +41,19 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do "text" => HtmlSanitizeEx.strip_tags(content), "is_local" => true, "is_post_verb" => true, - "created_at" => published, + "created_at" => created_at, "in_reply_to_status_id" => activity.data["object"]["inReplyToStatusId"], "statusnet_conversation_id" => activity.data["object"]["statusnetConversationId"], "attachments" => (activity.data["object"]["attachment"] || []) |> ObjectRepresenter.enum_to_list(opts), "attentions" => attentions } end + + defp date_to_asctime(date) do + with {:ok, date, _offset} <- date |> DateTime.from_iso8601 do + Calendar.Strftime.strftime!(date, "%a %b %d %H:%M:%S %z %Y") + else e -> + "" + end + end end -- cgit v1.2.3