forked from AkkomaGang/akkoma
Add Follow Activity representer
This commit is contained in:
parent
8075badafe
commit
b502d7981c
2 changed files with 22 additions and 5 deletions
|
@ -3,6 +3,20 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
|
||||||
alias Pleroma.Web.TwitterAPI.Representers.{UserRepresenter, ObjectRepresenter}
|
alias Pleroma.Web.TwitterAPI.Representers.{UserRepresenter, ObjectRepresenter}
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
|
|
||||||
|
def to_map(%Activity{data: %{"type" => "Follow"}} = activity, %{user: user} = opts) do
|
||||||
|
%{
|
||||||
|
"id" => activity.id,
|
||||||
|
"user" => UserRepresenter.to_map(user, opts),
|
||||||
|
"attentions" => [],
|
||||||
|
"statusnet_html" => "", # TODO: add summary
|
||||||
|
"text" => "",
|
||||||
|
"is_local" => true,
|
||||||
|
"is_post_verb" => false,
|
||||||
|
"created_at" => get_in(activity.data, ["published"]),
|
||||||
|
"in_reply_to_status_id" => nil,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def to_map(%Activity{} = activity, %{user: user} = opts) do
|
def to_map(%Activity{} = activity, %{user: user} = opts) do
|
||||||
content = get_in(activity.data, ["object", "content"])
|
content = get_in(activity.data, ["object", "content"])
|
||||||
published = get_in(activity.data, ["object", "published"])
|
published = get_in(activity.data, ["object", "published"])
|
||||||
|
|
|
@ -6,8 +6,6 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
def create_status(user = %User{}, data = %{}) do
|
def create_status(user = %User{}, data = %{}) do
|
||||||
date = DateTime.utc_now() |> DateTime.to_iso8601
|
|
||||||
|
|
||||||
attachments = Enum.map(data["media_ids"] || [], fn (media_id) ->
|
attachments = Enum.map(data["media_ids"] || [], fn (media_id) ->
|
||||||
Repo.get(Object, media_id).data
|
Repo.get(Object, media_id).data
|
||||||
end)
|
end)
|
||||||
|
@ -35,11 +33,11 @@ def create_status(user = %User{}, data = %{}) do
|
||||||
"type" => "Note",
|
"type" => "Note",
|
||||||
"to" => to,
|
"to" => to,
|
||||||
"content" => content_html,
|
"content" => content_html,
|
||||||
"published" => date,
|
"published" => make_date,
|
||||||
"context" => context,
|
"context" => context,
|
||||||
"attachment" => attachments
|
"attachment" => attachments
|
||||||
},
|
},
|
||||||
"published" => date,
|
"published" => make_date,
|
||||||
"context" => context
|
"context" => context
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +105,8 @@ def follow(%User{} = follower, followed_id) do
|
||||||
{ :ok, activity } <- ActivityPub.insert(%{
|
{ :ok, activity } <- ActivityPub.insert(%{
|
||||||
"type" => "Follow",
|
"type" => "Follow",
|
||||||
"actor" => follower.ap_id,
|
"actor" => follower.ap_id,
|
||||||
"object" => followed.ap_id
|
"object" => followed.ap_id,
|
||||||
|
"published" => make_date
|
||||||
})
|
})
|
||||||
do
|
do
|
||||||
{ :ok, follower, followed, activity }
|
{ :ok, follower, followed, activity }
|
||||||
|
@ -183,4 +182,8 @@ defp activity_to_status(activity, opts) do
|
||||||
mentioned_users = Repo.all(from user in User, where: user.ap_id in ^activity.data["to"])
|
mentioned_users = Repo.all(from user in User, where: user.ap_id in ^activity.data["to"])
|
||||||
ActivityRepresenter.to_map(activity, Map.merge(opts, %{user: user, mentioned: mentioned_users}))
|
ActivityRepresenter.to_map(activity, Map.merge(opts, %{user: user, mentioned: mentioned_users}))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp make_date do
|
||||||
|
DateTime.utc_now() |> DateTime.to_iso8601
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue