WIP: post editing #103
3 changed files with 38 additions and 4 deletions
|
@ -51,6 +51,7 @@ def index(conn, %{account_id: account_id} = params) do
|
||||||
move
|
move
|
||||||
pleroma:emoji_reaction
|
pleroma:emoji_reaction
|
||||||
poll
|
poll
|
||||||
|
update
|
||||||
}
|
}
|
||||||
def index(%{assigns: %{user: user}} = conn, params) do
|
def index(%{assigns: %{user: user}} = conn, params) do
|
||||||
params =
|
params =
|
||||||
|
|
|
@ -17,7 +17,11 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
|
||||||
alias Pleroma.Web.MastodonAPI.NotificationView
|
alias Pleroma.Web.MastodonAPI.NotificationView
|
||||||
alias Pleroma.Web.MastodonAPI.StatusView
|
alias Pleroma.Web.MastodonAPI.StatusView
|
||||||
|
|
||||||
@parent_types ~w{Like Announce EmojiReact}
|
defp object_id_for(%{data: %{"object" => %{"id" => id}}}) when is_binary(id), do: id
|
||||||
|
|
||||||
|
defp object_id_for(%{data: %{"object" => id}}) when is_binary(id), do: id
|
||||||
|
|
||||||
|
@parent_types ~w{Like Announce EmojiReact Update}
|
||||||
|
|
||||||
def render("index.json", %{notifications: notifications, for: reading_user} = opts) do
|
def render("index.json", %{notifications: notifications, for: reading_user} = opts) do
|
||||||
activities = Enum.map(notifications, & &1.activity)
|
activities = Enum.map(notifications, & &1.activity)
|
||||||
|
@ -28,7 +32,7 @@ def render("index.json", %{notifications: notifications, for: reading_user} = op
|
||||||
%{data: %{"type" => type}} ->
|
%{data: %{"type" => type}} ->
|
||||||
type in @parent_types
|
type in @parent_types
|
||||||
end)
|
end)
|
||||||
|> Enum.map(& &1.data["object"])
|
|> Enum.map(&object_id_for/1)
|
||||||
|> Activity.create_by_object_ap_id()
|
|> Activity.create_by_object_ap_id()
|
||||||
|> Activity.with_preloaded_object(:left)
|
|> Activity.with_preloaded_object(:left)
|
||||||
|> Pleroma.Repo.all()
|
|> Pleroma.Repo.all()
|
||||||
|
@ -76,9 +80,9 @@ def render(
|
||||||
|
|
||||||
parent_activity_fn = fn ->
|
parent_activity_fn = fn ->
|
||||||
if opts[:parent_activities] do
|
if opts[:parent_activities] do
|
||||||
Activity.Queries.find_by_object_ap_id(opts[:parent_activities], activity.data["object"])
|
Activity.Queries.find_by_object_ap_id(opts[:parent_activities], object_id_for(activity))
|
||||||
else
|
else
|
||||||
Activity.get_create_by_object_ap_id(activity.data["object"])
|
Activity.get_create_by_object_ap_id(object_id_for(activity))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -107,6 +111,9 @@ def render(
|
||||||
"reblog" ->
|
"reblog" ->
|
||||||
put_status(response, parent_activity_fn.(), reading_user, status_render_opts)
|
put_status(response, parent_activity_fn.(), reading_user, status_render_opts)
|
||||||
|
|
||||||
|
"update" ->
|
||||||
|
put_status(response, parent_activity_fn.(), reading_user, status_render_opts)
|
||||||
|
|
||||||
"move" ->
|
"move" ->
|
||||||
put_target(response, activity, reading_user, %{})
|
put_target(response, activity, reading_user, %{})
|
||||||
|
|
||||||
|
|
|
@ -285,6 +285,32 @@ test "Report notification" do
|
||||||
test_notifications_rendering([notification], moderator_user, [expected])
|
test_notifications_rendering([notification], moderator_user, [expected])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "Edit notification" do
|
||||||
|
user = insert(:user)
|
||||||
|
repeat_user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, activity} = CommonAPI.post(user, %{status: "mew"})
|
||||||
|
{:ok, _} = CommonAPI.repeat(activity.id, repeat_user)
|
||||||
|
{:ok, update} = CommonAPI.update(user, activity, %{status: "mew mew"})
|
||||||
|
|
||||||
|
user = Pleroma.User.get_by_ap_id(user.ap_id)
|
||||||
|
activity = Pleroma.Activity.normalize(activity)
|
||||||
|
update = Pleroma.Activity.normalize(update)
|
||||||
|
|
||||||
|
{:ok, [notification]} = Notification.create_notifications(update)
|
||||||
|
|
||||||
|
expected = %{
|
||||||
|
id: to_string(notification.id),
|
||||||
|
pleroma: %{is_seen: false, is_muted: false},
|
||||||
|
type: "update",
|
||||||
|
account: AccountView.render("show.json", %{user: user, for: repeat_user}),
|
||||||
|
created_at: Utils.to_masto_date(notification.inserted_at),
|
||||||
|
status: StatusView.render("show.json", %{activity: activity, for: repeat_user})
|
||||||
|
}
|
||||||
|
|
||||||
|
test_notifications_rendering([notification], repeat_user, [expected])
|
||||||
|
end
|
||||||
|
|
||||||
test "muted notification" do
|
test "muted notification" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
another_user = insert(:user)
|
another_user = insert(:user)
|
||||||
|
|
Loading…
Reference in a new issue