forked from AkkomaGang/akkoma
Merge branch 'feature/801-add-support-destroy-multiple-mastofe' into 'develop'
adding destroy multiple for mastofe See merge request pleroma/pleroma!1046
This commit is contained in:
commit
30a4318ef1
4 changed files with 67 additions and 2 deletions
|
@ -98,6 +98,14 @@ def clear(user) do
|
||||||
|> Repo.delete_all()
|
|> Repo.delete_all()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy_multiple(%{id: user_id} = _user, ids) do
|
||||||
|
from(n in Notification,
|
||||||
|
where: n.id in ^ids,
|
||||||
|
where: n.user_id == ^user_id
|
||||||
|
)
|
||||||
|
|> Repo.delete_all()
|
||||||
|
end
|
||||||
|
|
||||||
def dismiss(%{id: user_id} = _user, id) do
|
def dismiss(%{id: user_id} = _user, id) do
|
||||||
notification = Repo.get(Notification, id)
|
notification = Repo.get(Notification, id)
|
||||||
|
|
||||||
|
@ -173,8 +181,7 @@ def skip?(:local, %{local: false}, %{info: %{notification_settings: %{"remote" =
|
||||||
def skip?(:muted, activity, user) do
|
def skip?(:muted, activity, user) do
|
||||||
actor = activity.data["actor"]
|
actor = activity.data["actor"]
|
||||||
|
|
||||||
User.mutes?(user, %{ap_id: actor}) or
|
User.mutes?(user, %{ap_id: actor}) or CommonAPI.thread_muted?(user, activity)
|
||||||
CommonAPI.thread_muted?(user, activity)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def skip?(
|
def skip?(
|
||||||
|
|
|
@ -612,6 +612,11 @@ def dismiss_notification(%{assigns: %{user: user}} = conn, %{"id" => id} = _para
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy_multiple(%{assigns: %{user: user}} = conn, %{"ids" => ids} = _params) do
|
||||||
|
Notification.destroy_multiple(user, ids)
|
||||||
|
json(conn, %{})
|
||||||
|
end
|
||||||
|
|
||||||
def relationships(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
def relationships(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||||
id = List.wrap(id)
|
id = List.wrap(id)
|
||||||
q = from(u in User, where: u.id in ^id)
|
q = from(u in User, where: u.id in ^id)
|
||||||
|
|
|
@ -261,6 +261,7 @@ defmodule Pleroma.Web.Router do
|
||||||
post("/notifications/dismiss", MastodonAPIController, :dismiss_notification)
|
post("/notifications/dismiss", MastodonAPIController, :dismiss_notification)
|
||||||
get("/notifications", MastodonAPIController, :notifications)
|
get("/notifications", MastodonAPIController, :notifications)
|
||||||
get("/notifications/:id", MastodonAPIController, :get_notification)
|
get("/notifications/:id", MastodonAPIController, :get_notification)
|
||||||
|
delete("/notifications/destroy_multiple", MastodonAPIController, :destroy_multiple)
|
||||||
|
|
||||||
get("/scheduled_statuses", MastodonAPIController, :scheduled_statuses)
|
get("/scheduled_statuses", MastodonAPIController, :scheduled_statuses)
|
||||||
get("/scheduled_statuses/:id", MastodonAPIController, :show_scheduled_status)
|
get("/scheduled_statuses/:id", MastodonAPIController, :show_scheduled_status)
|
||||||
|
|
|
@ -944,6 +944,58 @@ test "filters notifications using exclude_types", %{conn: conn} do
|
||||||
|
|
||||||
assert [%{"id" => ^reblog_notification_id}] = json_response(conn_res, 200)
|
assert [%{"id" => ^reblog_notification_id}] = json_response(conn_res, 200)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "destroy multiple", %{conn: conn} do
|
||||||
|
user = insert(:user)
|
||||||
|
other_user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, activity1} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||||
|
{:ok, activity2} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||||
|
{:ok, activity3} = CommonAPI.post(user, %{"status" => "hi @#{other_user.nickname}"})
|
||||||
|
{:ok, activity4} = CommonAPI.post(user, %{"status" => "hi @#{other_user.nickname}"})
|
||||||
|
|
||||||
|
notification1_id = Repo.get_by(Notification, activity_id: activity1.id).id |> to_string()
|
||||||
|
notification2_id = Repo.get_by(Notification, activity_id: activity2.id).id |> to_string()
|
||||||
|
notification3_id = Repo.get_by(Notification, activity_id: activity3.id).id |> to_string()
|
||||||
|
notification4_id = Repo.get_by(Notification, activity_id: activity4.id).id |> to_string()
|
||||||
|
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> assign(:user, user)
|
||||||
|
|
||||||
|
conn_res =
|
||||||
|
conn
|
||||||
|
|> get("/api/v1/notifications")
|
||||||
|
|
||||||
|
result = json_response(conn_res, 200)
|
||||||
|
assert [%{"id" => ^notification2_id}, %{"id" => ^notification1_id}] = result
|
||||||
|
|
||||||
|
conn2 =
|
||||||
|
conn
|
||||||
|
|> assign(:user, other_user)
|
||||||
|
|
||||||
|
conn_res =
|
||||||
|
conn2
|
||||||
|
|> get("/api/v1/notifications")
|
||||||
|
|
||||||
|
result = json_response(conn_res, 200)
|
||||||
|
assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
|
||||||
|
|
||||||
|
conn_destroy =
|
||||||
|
conn
|
||||||
|
|> delete("/api/v1/notifications/destroy_multiple", %{
|
||||||
|
"ids" => [notification1_id, notification2_id]
|
||||||
|
})
|
||||||
|
|
||||||
|
assert json_response(conn_destroy, 200) == %{}
|
||||||
|
|
||||||
|
conn_res =
|
||||||
|
conn2
|
||||||
|
|> get("/api/v1/notifications")
|
||||||
|
|
||||||
|
result = json_response(conn_res, 200)
|
||||||
|
assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "reblogging" do
|
describe "reblogging" do
|
||||||
|
|
Loading…
Reference in a new issue