Merge branch 'develop' of ssh.gitgud.io:lambadalambda/pleroma into feature/help-test
This commit is contained in:
commit
84c2012810
11 changed files with 80 additions and 17 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -27,13 +27,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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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})
|
||||
|
||||
|
|
@ -83,10 +83,24 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|
|||
|> send_resp(200, response)
|
||||
end
|
||||
|
||||
def help_test(conn, _) do
|
||||
def help_test(conn, _params) do
|
||||
conn |> json_reply(200, Poison.encode!("ok"))
|
||||
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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue