aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub.ex6
-rw-r--r--lib/pleroma/web/router.ex3
-rw-r--r--lib/pleroma/web/twitter_api/representers/activity_representer.ex21
-rw-r--r--lib/pleroma/web/twitter_api/twitter_api.ex2
-rw-r--r--lib/pleroma/web/twitter_api/twitter_api_controller.ex20
5 files changed, 44 insertions, 8 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 52030d684..40350ad0c 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
post "/friendships/create", TwitterAPI.Controller, :follow
post "/friendships/destroy", TwitterAPI.Controller, :unfollow
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 66f78f340..f4ab5bdc6 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 f6574b8de..13de1661d 100644
--- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex
+++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex
@@ -45,12 +45,12 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
def follow(%{assigns: %{user: user}} = conn, %{ "user_id" => followed_id }) do
case TwitterAPI.follow(user, followed_id) do
- { :ok, _user, followed, _activity } ->
+ { :ok, user, followed, _activity } ->
response = followed |> UserRepresenter.to_json(%{for: user})
- conn |> json_reply(200, response)
+ conn
+ |> json_reply(200, response)
{ :error, msg } -> forbidden_json_reply(conn, msg)
end
-
end
def unfollow(%{assigns: %{user: user}} = conn, %{ "user_id" => followed_id }) do
@@ -86,6 +86,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")