Merge branch 'fork' into multilang
This commit is contained in:
commit
ef50dd588b
17 changed files with 71 additions and 55 deletions
1
changelog.d/familiar-followers.add
Normal file
1
changelog.d/familiar-followers.add
Normal file
|
@ -0,0 +1 @@
|
|||
Implement `/api/v1/accounts/familiar_followers`
|
1
changelog.d/mark-read.fix
Normal file
1
changelog.d/mark-read.fix
Normal file
|
@ -0,0 +1 @@
|
|||
The query for marking notifications as read has been simplified
|
1
changelog.d/missing-mrfs.add
Normal file
1
changelog.d/missing-mrfs.add
Normal file
|
@ -0,0 +1 @@
|
|||
Startup detection for configured MRF modules that are missing or incorrectly defined
|
|
@ -1 +0,0 @@
|
|||
Strip actor property from objects before federating
|
|
@ -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
|
||||
|
|
|
@ -9,7 +9,6 @@ defmodule Pleroma.Constants do
|
|||
|
||||
const(object_internal_fields,
|
||||
do: [
|
||||
"actor",
|
||||
"reactions",
|
||||
"reaction_count",
|
||||
"likes",
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
|
8
test/fixtures/create-chat-message.json
vendored
8
test/fixtures/create-chat-message.json
vendored
|
@ -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. <script>alert('XSS')</script>",
|
||||
"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"
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue