@doc """
Inserts a full object if it is contained in an activity.
"""
- def insert_full_object(%{"object" => object_data}) when is_map(object_data) do
+ def insert_full_object(%{"object" => %{"type" => type} = object_data}) when is_map(object_data) and type in ["Note"] do
with {:ok, _} <- Object.create(object_data) do
:ok
end
defmodule Pleroma.Web.ActivityPub.UserView do
use Pleroma.Web, :view
alias Pleroma.Web.Salmon
+ alias Pleroma.Web.WebFinger
alias Pleroma.User
def render("user.json", %{user: user}) do
+ {:ok, user} = WebFinger.ensure_keys_present(user)
{:ok, _, public_key} = Salmon.keys_from_pem(user.info["keys"])
public_key = :public_key.pem_entry_encode(:RSAPublicKey, public_key)
public_key = :public_key.pem_encode([public_key])
res
end
end
+
+ def update(user) do
+ ActivityPub.update(%{local: true, to: [user.follower_address], cc: [], actor: user.ap_id, object: Pleroma.Web.ActivityPub.UserView.render("user.json", %{user: user})})
+ end
end
end
def update_credentials(%{assigns: %{user: user}} = conn, params) do
+ original_user = user
params = if bio = params["note"] do
Map.put(params, "bio", bio)
else
with %Plug.Upload{} <- avatar,
{:ok, object} <- ActivityPub.upload(avatar),
change = Ecto.Changeset.change(user, %{avatar: object.data}),
- {:ok, user} = Repo.update(change) do
+ {:ok, user} = User.update_and_set_cache(change) do
user
else
_e -> user
{:ok, object} <- ActivityPub.upload(banner),
new_info <- Map.put(user.info, "banner", object.data),
change <- User.info_changeset(user, %{info: new_info}),
- {:ok, user} <- Repo.update(change) do
+ {:ok, user} <- User.update_and_set_cache(change) do
user
else
_e -> user
end
with changeset <- User.update_changeset(user, params),
- {:ok, user} <- Repo.update(changeset) do
+ {:ok, user} <- User.update_and_set_cache(changeset) do
+ if original_user != user do
+ CommonAPI.update(user)
+ end
json conn, AccountView.render("account.json", %{user: user})
else
_e ->
{:ok, object} = ActivityPub.upload(params)
change = Changeset.change(user, %{avatar: object.data})
{:ok, user} = User.update_and_set_cache(change)
+ CommonAPI.update(user)
render(conn, UserView, "show.json", %{user: user, for: user})
end
with {:ok, object} <- ActivityPub.upload(%{"img" => params["banner"]}),
new_info <- Map.put(user.info, "banner", object.data),
change <- User.info_changeset(user, %{info: new_info}),
- {:ok, _user} <- User.update_and_set_cache(change) do
+ {:ok, user} <- User.update_and_set_cache(change) do
+ CommonAPI.update(user)
%{"url" => [ %{ "href" => href } | _ ]} = object.data
response = %{ url: href } |> Poison.encode!
conn
with changeset <- User.update_changeset(user, params),
{:ok, user} <- User.update_and_set_cache(changeset) do
+ CommonAPI.update(user)
render(conn, UserView, "user.json", %{user: user, for: user})
else
error ->
assert activity.data["id"] == given_id
end
- test "adds an id to a given object if it lacks one and inserts it to the object database" do
+ test "adds an id to a given object if it lacks one and is a note and inserts it to the object database" do
data = %{
"object" => %{
+ "type" => "Note",
"ok" => true
}
}