Add attachments to the TwAPI.
This commit is contained in:
parent
42c90855ba
commit
73df2f8e5e
7 changed files with 73 additions and 13 deletions
|
|
@ -1,6 +1,6 @@
|
|||
defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
|
||||
use Pleroma.Web.TwitterAPI.Representers.BaseRepresenter
|
||||
alias Pleroma.Web.TwitterAPI.Representers.UserRepresenter
|
||||
alias Pleroma.Web.TwitterAPI.Representers.{UserRepresenter, ObjectRepresenter}
|
||||
alias Pleroma.Activity
|
||||
|
||||
def to_map(%Activity{} = activity, %{user: user} = opts) do
|
||||
|
|
@ -16,7 +16,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
|
|||
"is_post_verb" => true,
|
||||
"created_at" => published,
|
||||
"in_reply_to_status_id" => activity.data["object"]["inReplyToStatusId"],
|
||||
"statusnet_conversation_id" => activity.data["object"]["statusnetConversationId"]
|
||||
"statusnet_conversation_id" => activity.data["object"]["statusnetConversationId"],
|
||||
"attachments" => (activity.data["attachment"] || []) |> ObjectRepresenter.enum_to_list(opts)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,8 +8,13 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter do
|
|||
%{
|
||||
url: url["href"],
|
||||
mimetype: url["mediaType"],
|
||||
id: object.id,
|
||||
id: data["uuid"],
|
||||
oembed: false
|
||||
}
|
||||
end
|
||||
|
||||
# If we only get the naked data, wrap in an object
|
||||
def to_map(%{} = data, opts) do
|
||||
to_map(%Object{data: data}, opts)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
|
||||
alias Pleroma.{User, Activity, Repo}
|
||||
alias Pleroma.{User, Activity, Repo, Object}
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter
|
||||
|
||||
|
|
@ -8,6 +8,10 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
|
|||
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)
|
||||
|
||||
context = ActivityPub.generate_context_id
|
||||
activity = %{
|
||||
"type" => "Create",
|
||||
|
|
@ -23,7 +27,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
|
|||
"context" => context
|
||||
},
|
||||
"published" => date,
|
||||
"context" => context
|
||||
"context" => context,
|
||||
"attachment" => attachments
|
||||
}
|
||||
|
||||
# Wire up reply info.
|
||||
|
|
|
|||
|
|
@ -11,11 +11,22 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|
|||
end
|
||||
|
||||
def status_update(%{assigns: %{user: user}} = conn, status_data) do
|
||||
{:ok, activity} = TwitterAPI.create_status(user, status_data)
|
||||
media_ids = extract_media_ids(status_data)
|
||||
{:ok, activity} = TwitterAPI.create_status(user, %{ "status" => status_data["status"], "media_ids" => media_ids })
|
||||
conn
|
||||
|> json_reply(200, ActivityRepresenter.to_json(activity, %{user: user}))
|
||||
end
|
||||
|
||||
defp extract_media_ids(status_data) do
|
||||
with media_ids when not is_nil(media_ids) <- status_data["media_ids"],
|
||||
split_ids <- String.split(media_ids, ","),
|
||||
clean_ids <- Enum.reject(split_ids, fn (id) -> String.length(id) == 0 end)
|
||||
do
|
||||
clean_ids
|
||||
else _e -> []
|
||||
end
|
||||
end
|
||||
|
||||
def public_timeline(%{assigns: %{user: user}} = conn, params) do
|
||||
statuses = TwitterAPI.fetch_public_statuses(user, params)
|
||||
{:ok, json} = Poison.encode(statuses)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue