Do some transmogrifying for the output.
This commit is contained in:
parent
5a371892a0
commit
05ba6ca1b8
4 changed files with 76 additions and 10 deletions
|
|
@ -1,5 +1,6 @@
|
|||
defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||
alias Pleroma.{Activity, Repo, Object, Upload, User, Notification}
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
import Ecto.Query
|
||||
import Pleroma.Web.ActivityPub.Utils
|
||||
require Logger
|
||||
|
|
@ -242,15 +243,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
end
|
||||
end
|
||||
|
||||
# TODO: Extract to own module, align as close to Mastodon format as possible.
|
||||
def sanitize_outgoing_activity_data(data) do
|
||||
data
|
||||
|> Map.put("@context", "https://www.w3.org/ns/activitystreams")
|
||||
end
|
||||
|
||||
def publish(actor, activity) do
|
||||
remote_users = Pleroma.Web.Salmon.remote_users(activity)
|
||||
data = sanitize_outgoing_activity_data(activity.data)
|
||||
{:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
Enum.each remote_users, fn(user) ->
|
||||
if user.info["ap_enabled"] do
|
||||
inbox = user.info["source_data"]["inbox"]
|
||||
|
|
|
|||
|
|
@ -38,7 +38,38 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||
end
|
||||
end
|
||||
|
||||
def prepare_incoming(_) do
|
||||
:error
|
||||
@doc
|
||||
"""
|
||||
internal -> Mastodon
|
||||
"""
|
||||
def prepare_outgoing(%{"type" => "Create", "object" => %{"type" => "Note"} = object} = data) do
|
||||
object = object
|
||||
|> add_mention_tags
|
||||
|> add_attributed_to
|
||||
|
||||
data = data
|
||||
|> Map.put("object", object)
|
||||
|> Map.put("@context", "https://www.w3.org/ns/activitystreams")
|
||||
|
||||
{:ok, data}
|
||||
end
|
||||
|
||||
def add_mention_tags(object) do
|
||||
mentions = object["to"]
|
||||
|> Enum.map(fn (ap_id) -> User.get_cached_by_ap_id(ap_id) end)
|
||||
|> Enum.filter(&(&1))
|
||||
|> Enum.map(fn(user) -> %{"type" => "mention", "href" => user.ap_id, "name" => "@#{user.nickname}"} end)
|
||||
|
||||
tags = object["tags"] || []
|
||||
|
||||
object
|
||||
|> Map.put("tags", tags ++ mentions)
|
||||
end
|
||||
|
||||
def add_attributed_to(object) do
|
||||
attributedTo = object["attributedTo"] || object["actor"]
|
||||
|
||||
object
|
||||
|> Map.put("attributedTo", attributedTo)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ defmodule Pleroma.Web.CommonAPI do
|
|||
cw <- data["spoiler_text"],
|
||||
object <- make_note_data(user.ap_id, to, context, content_html, attachments, inReplyTo, tags, cw),
|
||||
object <- Map.put(object, "emoji", Formatter.get_emoji(status) |> Enum.reduce(%{}, fn({name, file}, acc) -> Map.put(acc, name, "#{Pleroma.Web.Endpoint.static_url}#{file}") end)) do
|
||||
res = ActivityPub.create(%{to: to, actor: user, context: context, object: object})
|
||||
res = ActivityPub.create(%{to: to, actor: user, context: context, object: object, additional: %{"cc" => to}})
|
||||
User.increase_note_count(user)
|
||||
res
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue