diff options
author | dtluna <dtluna@openmailbox.org> | 2017-04-13 17:15:02 +0300 |
---|---|---|
committer | dtluna <dtluna@openmailbox.org> | 2017-04-13 17:15:02 +0300 |
commit | 443381d0a05849d7dcdc0abb11844cb4d4a75a55 (patch) | |
tree | 48d66563e0156a22e6fe91ab99350e571c8d482c /lib | |
parent | a7e74ee01232897a6172f6462cec282a451c319a (diff) | |
parent | d2bf099ae66b7332128c854f322bb8a00eb62212 (diff) | |
download | pleroma-443381d0a05849d7dcdc0abb11844cb4d4a75a55.tar.gz |
Merge branch 'develop' of ssh.gitgud.io:lambadalambda/pleroma into feature/user-timeline
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/web/activity_pub/activity_pub.ex | 6 | ||||
-rw-r--r-- | lib/pleroma/web/router.ex | 3 | ||||
-rw-r--r-- | lib/pleroma/web/twitter_api/representers/activity_representer.ex | 21 | ||||
-rw-r--r-- | lib/pleroma/web/twitter_api/twitter_api.ex | 2 | ||||
-rw-r--r-- | lib/pleroma/web/twitter_api/twitter_api_controller.ex | 16 |
5 files changed, 42 insertions, 6 deletions
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 diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 8e6a2b012..1ced7f3ea 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -25,13 +25,16 @@ 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 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/home_timeline", TwitterAPI.Controller, :friends_timeline get "/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline get "/statuses/user_timeline", TwitterAPI.Controller, :user_timeline post "/friendships/create", TwitterAPI.Controller, :follow diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex index 5fe0df359..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] || [] @@ -33,14 +38,22 @@ 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, + "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 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 diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 741689ebf..11e7b3bdf 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -64,7 +64,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}) @@ -103,6 +103,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") |