diff --git a/changelog.d/familiar-followers.add b/changelog.d/familiar-followers.add new file mode 100644 index 0000000000..6e7ec9d257 --- /dev/null +++ b/changelog.d/familiar-followers.add @@ -0,0 +1 @@ +Implement `/api/v1/accounts/familiar_followers` \ No newline at end of file diff --git a/changelog.d/mark-read.fix b/changelog.d/mark-read.fix new file mode 100644 index 0000000000..346eb19e2a --- /dev/null +++ b/changelog.d/mark-read.fix @@ -0,0 +1 @@ +The query for marking notifications as read has been simplified diff --git a/changelog.d/missing-mrfs.add b/changelog.d/missing-mrfs.add new file mode 100644 index 0000000000..6a17f9e1ae --- /dev/null +++ b/changelog.d/missing-mrfs.add @@ -0,0 +1 @@ +Startup detection for configured MRF modules that are missing or incorrectly defined diff --git a/changelog.d/strip-object-actor.fix b/changelog.d/strip-object-actor.fix deleted file mode 100644 index 71cf7ee65b..0000000000 --- a/changelog.d/strip-object-actor.fix +++ /dev/null @@ -1 +0,0 @@ -Strip actor property from objects before federating diff --git a/lib/pleroma/application_requirements.ex b/lib/pleroma/application_requirements.ex index b3d9762ed0..db1bfc133a 100644 --- a/lib/pleroma/application_requirements.ex +++ b/lib/pleroma/application_requirements.ex @@ -28,6 +28,7 @@ def verify! do |> check_welcome_message_config!() |> check_rum!() |> check_repo_pool_size!() + |> check_mrfs() |> handle_result() end @@ -268,4 +269,25 @@ defp check_filter(filter, command_required) do true end end + + defp check_mrfs(:ok) do + mrfs = Config.get!([:mrf, :policies]) + + missing_mrfs = + Enum.reduce(mrfs, [], fn x, acc -> + if Code.ensure_compiled(x) do + acc + else + acc ++ [x] + end + end) + + if Enum.empty?(missing_mrfs) do + :ok + else + {:error, "The following MRF modules are configured but missing: #{inspect(missing_mrfs)}"} + end + end + + defp check_mrfs(result), do: result end diff --git a/lib/pleroma/constants.ex b/lib/pleroma/constants.ex index 46d03ed18c..2eaf602d9a 100644 --- a/lib/pleroma/constants.ex +++ b/lib/pleroma/constants.ex @@ -9,7 +9,6 @@ defmodule Pleroma.Constants do const(object_internal_fields, do: [ - "actor", "reactions", "reaction_count", "likes", diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index bf70274ae1..f6b8ebffdf 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -285,17 +285,13 @@ def set_read_up_to(%{id: user_id} = user, id) do select: n.id ) - {:ok, %{ids: {_, notification_ids}, marker: marker}} = + {:ok, %{marker: marker}} = Multi.new() |> Multi.update_all(:ids, query, set: [seen: true, updated_at: NaiveDateTime.utc_now()]) |> Marker.multi_set_last_read_id(user, "notifications") |> Repo.transaction() Streamer.stream(["user", "user:notification"], marker) - - for_user_query(user) - |> where([n], n.id in ^notification_ids) - |> Repo.all() end @spec read_one(User.t(), String.t()) :: @@ -306,10 +302,6 @@ def read_one(%User{} = user, notification_id) do |> Multi.update(:update, changeset(notification, %{seen: true})) |> Marker.multi_set_last_read_id(user, "notifications") |> Repo.transaction() - |> case do - {:ok, %{update: notification}} -> {:ok, notification} - {:error, :update, changeset, _} -> {:error, changeset} - end end end @@ -579,7 +571,7 @@ def get_notified_from_activity(%Activity{data: %{"type" => type}} = activity, lo Enum.filter(potential_receivers, fn u -> u.ap_id in notification_enabled_ap_ids end) end - def get_notified_from_activity(_, _local_only), do: {[], []} + def get_notified_from_activity(_, _local_only), do: [] def get_notified_subscribers_from_activity(activity, local_only \\ true) @@ -597,7 +589,7 @@ def get_notified_subscribers_from_activity( Enum.filter(potential_receivers, fn u -> u.ap_id in notification_enabled_ap_ids end) end - def get_notified_subscribers_from_activity(_, _), do: {[], []} + def get_notified_subscribers_from_activity(_, _), do: [] def get_notified_participants_from_activity(activity, local_only \\ true) diff --git a/lib/pleroma/web/api_spec/operations/account_operation.ex b/lib/pleroma/web/api_spec/operations/account_operation.ex index e5ddd95538..10ed654f19 100644 --- a/lib/pleroma/web/api_spec/operations/account_operation.ex +++ b/lib/pleroma/web/api_spec/operations/account_operation.ex @@ -524,9 +524,10 @@ def identity_proofs_operation do def familiar_followers_operation do %Operation{ tags: ["Retrieve account information"], - summary: "Followers you know", - operationId: "AccountController.relationships", - description: "Returns followers of given account you know.", + summary: "Followers that you follow", + operationId: "AccountController.familiar_followers", + description: + "Obtain a list of all accounts that follow a given account, filtered for accounts you follow.", security: [%{"oAuth" => ["read:follows"]}], parameters: [ Operation.parameter( diff --git a/lib/pleroma/web/api_spec/operations/pleroma_notification_operation.ex b/lib/pleroma/web/api_spec/operations/pleroma_notification_operation.ex index a994345dbd..0e28651914 100644 --- a/lib/pleroma/web/api_spec/operations/pleroma_notification_operation.ex +++ b/lib/pleroma/web/api_spec/operations/pleroma_notification_operation.ex @@ -5,7 +5,6 @@ defmodule Pleroma.Web.ApiSpec.PleromaNotificationOperation do alias OpenApiSpex.Operation alias OpenApiSpex.Schema - alias Pleroma.Web.ApiSpec.NotificationOperation alias Pleroma.Web.ApiSpec.Schemas.ApiError import Pleroma.Web.ApiSpec.Helpers @@ -35,12 +34,7 @@ def mark_as_read_operation do Operation.response( "A Notification or array of Notifications", "application/json", - %Schema{ - anyOf: [ - %Schema{type: :array, items: NotificationOperation.notification()}, - NotificationOperation.notification() - ] - } + %Schema{type: :string} ), 400 => Operation.response("Bad Request", "application/json", ApiError) } diff --git a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex index bc8e895f77..b93cf6987b 100644 --- a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex @@ -643,7 +643,7 @@ def endorsements(%{assigns: %{user: user}} = conn, params) do @doc "GET /api/v1/accounts/familiar_followers" def familiar_followers( %{assigns: %{user: user}, private: %{open_api_spex: %{params: %{id: id}}}} = conn, - _ + _id ) do users = User.get_all_by_ids(List.wrap(id)) diff --git a/lib/pleroma/web/pleroma_api/controllers/notification_controller.ex b/lib/pleroma/web/pleroma_api/controllers/notification_controller.ex index f860eaf7e6..435ccfabe4 100644 --- a/lib/pleroma/web/pleroma_api/controllers/notification_controller.ex +++ b/lib/pleroma/web/pleroma_api/controllers/notification_controller.ex @@ -23,8 +23,9 @@ def mark_as_read( } = conn, _ ) do - with {:ok, notification} <- Notification.read_one(user, notification_id) do - render(conn, "show.json", notification: notification, for: user) + with {:ok, _} <- Notification.read_one(user, notification_id) do + conn + |> json("ok") else {:error, message} -> conn @@ -38,11 +39,14 @@ def mark_as_read( conn, _ ) do - notifications = - user - |> Notification.set_read_up_to(max_id) - |> Enum.take(80) - - render(conn, "index.json", notifications: notifications, for: user) + with {:ok, _} <- Notification.set_read_up_to(user, max_id) do + conn + |> json("ok") + else + {:error, message} -> + conn + |> put_status(:bad_request) + |> json(%{"error" => message}) + end end end diff --git a/test/fixtures/create-chat-message.json b/test/fixtures/create-chat-message.json index a5e5f559b7..9c23a1c9b9 100644 --- a/test/fixtures/create-chat-message.json +++ b/test/fixtures/create-chat-message.json @@ -1,10 +1,10 @@ { - "actor": "http://mastodon.example.org/users/admin", - "id": "http://mastodon.example.org/objects/1", + "actor": "http://2hu.gensokyo/users/raymoo", + "id": "http://2hu.gensokyo/objects/1", "object": { - "attributedTo": "http://mastodon.example.org/users/admin", + "attributedTo": "http://2hu.gensokyo/users/raymoo", "content": "You expected a cute girl? Too bad. ", - "id": "http://mastodon.example.org/objects/2", + "id": "http://2hu.gensokyo/objects/2", "published": "2020-02-12T14:08:20Z", "to": [ "http://2hu.gensokyo/users/marisa" diff --git a/test/pleroma/notification_test.exs b/test/pleroma/notification_test.exs index ecbddad489..9fd1964289 100644 --- a/test/pleroma/notification_test.exs +++ b/test/pleroma/notification_test.exs @@ -668,9 +668,7 @@ test "it sets all notifications as read up to a specified notification ID" do Pleroma.Tests.ObanHelpers.perform_all() - [_, read_notification] = Notification.set_read_up_to(other_user, n2.id) - - assert read_notification.activity.object + Notification.set_read_up_to(other_user, n2.id) [n3, n2, n1] = Notification.for_user(other_user) diff --git a/test/pleroma/user/backup_test.exs b/test/pleroma/user/backup_test.exs index 12d7af9442..1b6a47f88d 100644 --- a/test/pleroma/user/backup_test.exs +++ b/test/pleroma/user/backup_test.exs @@ -230,6 +230,7 @@ test "it creates a zip archive with user data" do "orderedItems" => [ %{ "object" => %{ + "actor" => "http://cofe.io/users/cofe", "content" => "status1", "type" => "Note" }, @@ -237,6 +238,7 @@ test "it creates a zip archive with user data" do }, %{ "object" => %{ + "actor" => "http://cofe.io/users/cofe", "content" => "status2" } }, diff --git a/test/pleroma/web/activity_pub/transmogrifier/chat_message_test.exs b/test/pleroma/web/activity_pub/transmogrifier/chat_message_test.exs index 0866417502..c798a0fc9b 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/chat_message_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/chat_message_test.exs @@ -116,6 +116,8 @@ test "it fetches the actor if they aren't in our system" do data = File.read!("test/fixtures/create-chat-message.json") |> Jason.decode!() + |> Map.put("actor", "http://mastodon.example.org/users/admin") + |> put_in(["object", "actor"], "http://mastodon.example.org/users/admin") _recipient = insert(:user, ap_id: List.first(data["to"]), local: true) diff --git a/test/pleroma/web/activity_pub/transmogrifier_test.exs b/test/pleroma/web/activity_pub/transmogrifier_test.exs index 673ef86f45..241ed6033a 100644 --- a/test/pleroma/web/activity_pub/transmogrifier_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier_test.exs @@ -169,7 +169,7 @@ test "it inlines private announced objects" do {:ok, modified} = Transmogrifier.prepare_outgoing(announce_activity.data) assert modified["object"]["content"] == "hey" - assert activity.actor == modified["object"]["attributedTo"] + assert modified["object"]["actor"] == modified["object"]["attributedTo"] end test "it turns mentions into tags" do @@ -220,7 +220,7 @@ test "it sets the 'attributedTo' property to the actor of the object if it doesn {:ok, activity} = CommonAPI.post(user, %{status: "hey"}) {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data) - assert activity.actor == modified["object"]["attributedTo"] + assert modified["object"]["actor"] == modified["object"]["attributedTo"] end test "it strips internal hashtag data" do @@ -266,7 +266,6 @@ test "it strips internal fields" do assert is_nil(modified["object"]["announcements"]) assert is_nil(modified["object"]["announcement_count"]) assert is_nil(modified["object"]["generator"]) - assert is_nil(modified["object"]["actor"]) end test "it strips internal fields of article" do diff --git a/test/pleroma/web/pleroma_api/controllers/notification_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/notification_controller_test.exs index 2e2935d8e6..9ccae2f212 100644 --- a/test/pleroma/web/pleroma_api/controllers/notification_controller_test.exs +++ b/test/pleroma/web/pleroma_api/controllers/notification_controller_test.exs @@ -26,13 +26,11 @@ test "it marks a single notification as read", %{user: user1, conn: conn} do {:ok, [notification1]} = Notification.create_notifications(activity1) {:ok, [notification2]} = Notification.create_notifications(activity2) - response = - conn - |> put_req_header("content-type", "application/json") - |> post("/api/v1/pleroma/notifications/read", %{id: notification1.id}) - |> json_response_and_validate_schema(:ok) + conn + |> put_req_header("content-type", "application/json") + |> post("/api/v1/pleroma/notifications/read", %{id: notification1.id}) + |> json_response_and_validate_schema(:ok) - assert %{"pleroma" => %{"is_seen" => true}} = response assert Repo.get(Notification, notification1.id).seen refute Repo.get(Notification, notification2.id).seen end @@ -46,14 +44,17 @@ test "it marks multiple notifications as read", %{user: user1, conn: conn} do [notification3, notification2, notification1] = Notification.for_user(user1, %{limit: 3}) - [response1, response2] = - conn - |> put_req_header("content-type", "application/json") - |> post("/api/v1/pleroma/notifications/read", %{max_id: notification2.id}) - |> json_response_and_validate_schema(:ok) + refute Repo.get(Notification, notification1.id).seen + refute Repo.get(Notification, notification2.id).seen + refute Repo.get(Notification, notification3.id).seen + + conn + |> put_req_header("content-type", "application/json") + |> post("/api/v1/pleroma/notifications/read", %{max_id: notification2.id}) + |> json_response_and_validate_schema(:ok) + + [notification3, notification2, notification1] = Notification.for_user(user1, %{limit: 3}) - assert %{"pleroma" => %{"is_seen" => true}} = response1 - assert %{"pleroma" => %{"is_seen" => true}} = response2 assert Repo.get(Notification, notification1.id).seen assert Repo.get(Notification, notification2.id).seen refute Repo.get(Notification, notification3.id).seen