Page MenuHomePhorge

No OneTemporary

Authored By
Unknown
Size
9 KB
Referenced Files
None
Subscribers
None
diff --git a/changelog.d/marker-updated-at-format.fix b/changelog.d/marker-updated-at-format.fix
new file mode 100644
index 000000000..2ff681525
--- /dev/null
+++ b/changelog.d/marker-updated-at-format.fix
@@ -0,0 +1 @@
+Mastodon API: Use the Mastodon date format for marker updated_at
diff --git a/lib/pleroma/web/mastodon_api/views/marker_view.ex b/lib/pleroma/web/mastodon_api/views/marker_view.ex
index 944769b1a..fd067f713 100644
--- a/lib/pleroma/web/mastodon_api/views/marker_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/marker_view.ex
@@ -1,21 +1,23 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.MarkerView do
use Pleroma.Web, :view
+ alias Pleroma.Web.CommonAPI.Utils
+
def render("markers.json", %{markers: markers}) do
Map.new(markers, fn m ->
{m.timeline,
%{
last_read_id: m.last_read_id,
version: m.lock_version,
- updated_at: NaiveDateTime.to_iso8601(m.updated_at),
+ updated_at: Utils.to_masto_date(m.updated_at),
pleroma: %{
unread_count: m.unread_count
}
}}
end)
end
end
diff --git a/test/pleroma/web/mastodon_api/controllers/marker_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/marker_controller_test.exs
index 4050528ff..ff85031f0 100644
--- a/test/pleroma/web/mastodon_api/controllers/marker_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/marker_controller_test.exs
@@ -1,166 +1,167 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do
use Pleroma.Web.ConnCase, async: true
alias Pleroma.Notification
alias Pleroma.Repo
alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.CommonAPI.Utils
import Pleroma.Factory
describe "GET /api/v1/markers" do
test "gets markers with correct scopes", %{conn: conn} do
user = insert(:user)
token = insert(:oauth_token, user: user, scopes: ["read:statuses"])
insert_list(7, :notification, user: user, activity: insert(:note_activity))
{:ok, %{"notifications" => marker}} =
Pleroma.Marker.upsert(
user,
%{"notifications" => %{"last_read_id" => "69420"}}
)
response =
conn
|> assign(:user, user)
|> assign(:token, token)
|> get("/api/v1/markers?timeline[]=notifications")
|> json_response_and_validate_schema(200)
assert response == %{
"notifications" => %{
"last_read_id" => "69420",
- "updated_at" => NaiveDateTime.to_iso8601(marker.updated_at),
+ "updated_at" => Utils.to_masto_date(marker.updated_at),
"version" => 0,
"pleroma" => %{"unread_count" => 7}
}
}
end
test "gets markers with missed scopes", %{conn: conn} do
user = insert(:user)
token = insert(:oauth_token, user: user, scopes: [])
Pleroma.Marker.upsert(user, %{"notifications" => %{"last_read_id" => "69420"}})
response =
conn
|> assign(:user, user)
|> assign(:token, token)
|> get("/api/v1/markers", %{timeline: ["notifications"]})
|> json_response_and_validate_schema(403)
assert response == %{"error" => "Insufficient permissions: read:statuses."}
end
end
describe "POST /api/v1/markers" do
test "creates a marker with correct scopes", %{conn: conn} do
user = insert(:user)
token = insert(:oauth_token, user: user, scopes: ["write:statuses"])
response =
conn
|> assign(:user, user)
|> assign(:token, token)
|> put_req_header("content-type", "application/json")
|> post("/api/v1/markers", %{
home: %{last_read_id: "777"},
notifications: %{"last_read_id" => "69420"}
})
|> json_response_and_validate_schema(200)
assert %{
"notifications" => %{
"last_read_id" => "69420",
"updated_at" => _,
"version" => 0,
"pleroma" => %{"unread_count" => 0}
}
} = response
end
test "updates exist marker", %{conn: conn} do
user = insert(:user)
token = insert(:oauth_token, user: user, scopes: ["write:statuses"])
{:ok, %{"notifications" => marker}} =
Pleroma.Marker.upsert(
user,
%{"notifications" => %{"last_read_id" => "69477"}}
)
response =
conn
|> assign(:user, user)
|> assign(:token, token)
|> put_req_header("content-type", "application/json")
|> post("/api/v1/markers", %{
home: %{last_read_id: "777"},
notifications: %{"last_read_id" => "69888"}
})
|> json_response_and_validate_schema(200)
assert response == %{
"notifications" => %{
"last_read_id" => "69888",
- "updated_at" => NaiveDateTime.to_iso8601(marker.updated_at),
+ "updated_at" => Utils.to_masto_date(marker.updated_at),
"version" => 0,
"pleroma" => %{"unread_count" => 0}
}
}
end
test "creates a marker with missed scopes", %{conn: conn} do
user = insert(:user)
token = insert(:oauth_token, user: user, scopes: [])
response =
conn
|> assign(:user, user)
|> assign(:token, token)
|> put_req_header("content-type", "application/json")
|> post("/api/v1/markers", %{
home: %{last_read_id: "777"},
notifications: %{"last_read_id" => "69420"}
})
|> json_response_and_validate_schema(403)
assert response == %{"error" => "Insufficient permissions: write:statuses."}
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
diff --git a/test/pleroma/web/mastodon_api/views/marker_view_test.exs b/test/pleroma/web/mastodon_api/views/marker_view_test.exs
index 43f8c4302..4f4eeca82 100644
--- a/test/pleroma/web/mastodon_api/views/marker_view_test.exs
+++ b/test/pleroma/web/mastodon_api/views/marker_view_test.exs
@@ -1,29 +1,39 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.MarkerViewTest do
use Pleroma.DataCase, async: true
+ alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.MastodonAPI.MarkerView
import Pleroma.Factory
test "returns markers" do
marker1 = insert(:marker, timeline: "notifications", last_read_id: "17", unread_count: 5)
marker2 = insert(:marker, timeline: "home", last_read_id: "42")
assert MarkerView.render("markers.json", %{markers: [marker1, marker2]}) == %{
"home" => %{
last_read_id: "42",
- updated_at: NaiveDateTime.to_iso8601(marker2.updated_at),
+ updated_at: Utils.to_masto_date(marker2.updated_at),
version: 0,
pleroma: %{unread_count: 0}
},
"notifications" => %{
last_read_id: "17",
- updated_at: NaiveDateTime.to_iso8601(marker1.updated_at),
+ updated_at: Utils.to_masto_date(marker1.updated_at),
version: 0,
pleroma: %{unread_count: 5}
}
}
end
+
+ test "renders updated_at in the Mastodon date format" do
+ marker = insert(:marker, timeline: "home")
+
+ %{"home" => %{updated_at: updated_at}} =
+ MarkerView.render("markers.json", %{markers: [marker]})
+
+ assert updated_at =~ ~r/\.\d{3}Z$/
+ end
end

File Metadata

Mime Type
text/x-diff
Expires
Tue, Nov 17, 10:56 AM (5 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1839476
Default Alt Text
(9 KB)

Event Timeline