mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-31 12:28:43 +00:00
Merge branch 'norifications-marker' into 'develop'
Fix 'Setting a marker should mark notifications as read' Closes #2769 See merge request pleroma/pleroma!4223
This commit is contained in:
commit
c91fc03e61
3 changed files with 45 additions and 1 deletions
1
changelog.d/notifications-marker.change
Normal file
1
changelog.d/notifications-marker.change
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Fix 'Setting a marker should mark notifications as read'
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
defmodule Pleroma.Web.MastodonAPI.MarkerController do
|
defmodule Pleroma.Web.MastodonAPI.MarkerController do
|
||||||
use Pleroma.Web, :controller
|
use Pleroma.Web, :controller
|
||||||
|
|
||||||
alias Pleroma.Web.Plugs.OAuthScopesPlug
|
alias Pleroma.Web.Plugs.OAuthScopesPlug
|
||||||
|
|
||||||
plug(Pleroma.Web.ApiSpec.CastAndValidate)
|
plug(Pleroma.Web.ApiSpec.CastAndValidate)
|
||||||
|
@ -30,9 +31,16 @@ defmodule Pleroma.Web.MastodonAPI.MarkerController do
|
||||||
def upsert(%{assigns: %{user: user}, body_params: params} = conn, _) do
|
def upsert(%{assigns: %{user: user}, body_params: params} = conn, _) do
|
||||||
params = Map.new(params, fn {key, value} -> {to_string(key), value} end)
|
params = Map.new(params, fn {key, value} -> {to_string(key), value} end)
|
||||||
|
|
||||||
with {:ok, result} <- Pleroma.Marker.upsert(user, params),
|
with {:ok, _} <- mark_notifications_read(user, params),
|
||||||
|
{:ok, result} <- Pleroma.Marker.upsert(user, params),
|
||||||
markers <- Map.values(result) do
|
markers <- Map.values(result) do
|
||||||
render(conn, "markers.json", %{markers: markers})
|
render(conn, "markers.json", %{markers: markers})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp mark_notifications_read(user, %{"notifications" => %{last_read_id: last_read_id}}) do
|
||||||
|
Pleroma.Notification.set_read_up_to(user, last_read_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp mark_notifications_read(_, _), do: {:ok, :noop}
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,6 +5,10 @@
|
||||||
defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do
|
defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do
|
||||||
use Pleroma.Web.ConnCase, async: true
|
use Pleroma.Web.ConnCase, async: true
|
||||||
|
|
||||||
|
alias Pleroma.Notification
|
||||||
|
alias Pleroma.Repo
|
||||||
|
alias Pleroma.Web.CommonAPI
|
||||||
|
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
describe "GET /api/v1/markers" do
|
describe "GET /api/v1/markers" do
|
||||||
|
@ -127,5 +131,36 @@ defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do
|
||||||
|
|
||||||
assert response == %{"error" => "Insufficient permissions: write:statuses."}
|
assert response == %{"error" => "Insufficient permissions: write:statuses."}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "marks notifications as read", %{conn: conn} do
|
||||||
|
user1 = insert(:user)
|
||||||
|
token = insert(:oauth_token, user: user1, scopes: ["write:statuses"])
|
||||||
|
|
||||||
|
user2 = insert(:user)
|
||||||
|
{:ok, _activity1} = CommonAPI.post(user2, %{status: "hi @#{user1.nickname}"})
|
||||||
|
{:ok, _activity2} = CommonAPI.post(user2, %{status: "hi @#{user1.nickname}"})
|
||||||
|
{:ok, _activity3} = CommonAPI.post(user2, %{status: "HIE @#{user1.nickname}"})
|
||||||
|
|
||||||
|
[notification3, notification2, notification1] = Notification.for_user(user1, %{limit: 3})
|
||||||
|
|
||||||
|
refute Repo.get(Notification, notification1.id).seen
|
||||||
|
refute Repo.get(Notification, notification2.id).seen
|
||||||
|
refute Repo.get(Notification, notification3.id).seen
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> assign(:user, user1)
|
||||||
|
|> assign(:token, token)
|
||||||
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|> post("/api/v1/markers", %{
|
||||||
|
notifications: %{last_read_id: to_string(notification2.id)}
|
||||||
|
})
|
||||||
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
|
[notification3, notification2, notification1] = Notification.for_user(user1, %{limit: 3})
|
||||||
|
|
||||||
|
assert Repo.get(Notification, notification1.id).seen
|
||||||
|
assert Repo.get(Notification, notification2.id).seen
|
||||||
|
refute Repo.get(Notification, notification3.id).seen
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue