diff --git a/changelog.d/instance-rules.add b/changelog.d/instance-rules.add
new file mode 100644
index 0000000000..42f3cbfa18
--- /dev/null
+++ b/changelog.d/instance-rules.add
@@ -0,0 +1 @@
+Add instance rules
\ No newline at end of file
diff --git a/changelog.d/strip-object-actor.fix b/changelog.d/strip-object-actor.fix
new file mode 100644
index 0000000000..71cf7ee65b
--- /dev/null
+++ b/changelog.d/strip-object-actor.fix
@@ -0,0 +1 @@
+Strip actor property from objects before federating
diff --git a/changelog.d/web_push_filtered.fix b/changelog.d/web_push_filtered.fix
new file mode 100644
index 0000000000..b9159362ab
--- /dev/null
+++ b/changelog.d/web_push_filtered.fix
@@ -0,0 +1 @@
+Web Push notifications are no longer generated for muted/blocked threads and users.
diff --git a/lib/pleroma/constants.ex b/lib/pleroma/constants.ex
index 1e45c28072..46d03ed18c 100644
--- a/lib/pleroma/constants.ex
+++ b/lib/pleroma/constants.ex
@@ -9,6 +9,7 @@ defmodule Pleroma.Constants do
const(object_internal_fields,
do: [
+ "actor",
"reactions",
"reaction_count",
"likes",
@@ -20,6 +21,7 @@ defmodule Pleroma.Constants do
"deleted_activity_id",
"pleroma_internal",
"generator",
+ "rules",
"assigned_account",
"rules",
"content_type",
diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex
index 288558db79..bf70274ae1 100644
--- a/lib/pleroma/notification.ex
+++ b/lib/pleroma/notification.ex
@@ -368,20 +368,20 @@ def dismiss(%{id: user_id} = _user, id) do
end
end
- @spec create_notifications(Activity.t(), keyword()) :: {:ok, [Notification.t()] | []}
- def create_notifications(activity, options \\ [])
+ @spec create_notifications(Activity.t()) :: {:ok, [Notification.t()] | []}
+ def create_notifications(activity)
- def create_notifications(%Activity{data: %{"to" => _, "type" => "Create"}} = activity, options) do
+ def create_notifications(%Activity{data: %{"to" => _, "type" => "Create"}} = activity) do
object = Object.normalize(activity, fetch: false)
if object && object.data["type"] == "Answer" do
{:ok, []}
else
- do_create_notifications(activity, options)
+ do_create_notifications(activity)
end
end
- def create_notifications(%Activity{data: %{"type" => type}} = activity, options)
+ def create_notifications(%Activity{data: %{"type" => type}} = activity)
when type in [
"Follow",
"Like",
@@ -393,41 +393,29 @@ def create_notifications(%Activity{data: %{"type" => type}} = activity, options)
"Accept",
"Join"
] do
- do_create_notifications(activity, options)
+ do_create_notifications(activity)
end
- def create_notifications(_, _), do: {:ok, []}
+ def create_notifications(_), do: {:ok, []}
- defp do_create_notifications(%Activity{} = activity, options) do
- do_send = Keyword.get(options, :do_send, true)
+ defp do_create_notifications(%Activity{} = activity) do
+ enabled_participants = get_notified_participants_from_activity(activity)
- {enabled_participants, disabled_participants} =
- get_notified_participants_from_activity(activity)
+ enabled_receivers = get_notified_from_activity(activity) -- enabled_participants
- potential_participants = enabled_participants ++ disabled_participants
-
- {enabled_receivers, disabled_receivers} = get_notified_from_activity(activity)
-
- potential_receivers = (enabled_receivers ++ disabled_receivers) -- potential_participants
-
- {enabled_subscribers, disabled_subscribers} = get_notified_subscribers_from_activity(activity)
-
- potential_subscribers =
- (enabled_subscribers ++ disabled_subscribers) --
- (potential_participants ++ potential_receivers)
+ enabled_subscribers =
+ get_notified_subscribers_from_activity(activity) --
+ (enabled_participants ++ enabled_receivers)
notifications =
- (Enum.map(potential_receivers, fn user ->
- do_send = do_send && user in enabled_receivers
- create_notification(activity, user, do_send: do_send)
+ (Enum.map(enabled_receivers, fn user ->
+ create_notification(activity, user)
end) ++
- Enum.map(potential_subscribers, fn user ->
- do_send = do_send && user in enabled_subscribers
- create_notification(activity, user, do_send: do_send, type: "status")
+ Enum.map(enabled_subscribers, fn user ->
+ create_notification(activity, user, type: "status")
end) ++
- Enum.map(potential_participants, fn user ->
- do_send = do_send && user in enabled_participants
- create_notification(activity, user, do_send: do_send, type: "pleroma:event_update")
+ Enum.map(enabled_participants, fn user ->
+ create_notification(activity, user, type: "pleroma:event_update")
end))
|> Enum.reject(&is_nil/1)
@@ -493,7 +481,6 @@ defp type_from_activity_object(%{data: %{"type" => "Create"}} = activity) do
# TODO move to sql, too.
def create_notification(%Activity{} = activity, %User{} = user, opts \\ []) do
- do_send = Keyword.get(opts, :do_send, true)
type = Keyword.get(opts, :type, type_from_activity(activity))
unless skip?(activity, user, opts) do
@@ -508,11 +495,6 @@ def create_notification(%Activity{} = activity, %User{} = user, opts \\ []) do
|> Marker.multi_set_last_read_id(user, "notifications")
|> Repo.transaction()
- if do_send do
- Streamer.stream(["user", "user:notification"], notification)
- Push.send(notification)
- end
-
notification
end
end
@@ -594,10 +576,7 @@ def get_notified_from_activity(%Activity{data: %{"type" => type}} = activity, lo
|> exclude_relationship_restricted_ap_ids(activity)
|> exclude_thread_muter_ap_ids(activity)
- notification_enabled_users =
- Enum.filter(potential_receivers, fn u -> u.ap_id in notification_enabled_ap_ids end)
-
- {notification_enabled_users, potential_receivers -- notification_enabled_users}
+ Enum.filter(potential_receivers, fn u -> u.ap_id in notification_enabled_ap_ids end)
end
def get_notified_from_activity(_, _local_only), do: {[], []}
@@ -615,10 +594,7 @@ def get_notified_subscribers_from_activity(
potential_receivers =
User.get_users_from_set(notification_enabled_ap_ids, local_only: local_only)
- notification_enabled_users =
- Enum.filter(potential_receivers, fn u -> u.ap_id in notification_enabled_ap_ids end)
-
- {notification_enabled_users, potential_receivers -- notification_enabled_users}
+ Enum.filter(potential_receivers, fn u -> u.ap_id in notification_enabled_ap_ids end)
end
def get_notified_subscribers_from_activity(_, _), do: {[], []}
@@ -636,10 +612,7 @@ def get_notified_participants_from_activity(
potential_receivers =
User.get_users_from_set(notification_enabled_ap_ids, local_only: local_only)
- notification_enabled_users =
- Enum.filter(potential_receivers, fn u -> u.ap_id in notification_enabled_ap_ids end)
-
- {notification_enabled_users, potential_receivers -- notification_enabled_users}
+ Enum.filter(potential_receivers, fn u -> u.ap_id in notification_enabled_ap_ids end)
end
def get_notified_participants_from_activity(_, _), do: {[], []}
@@ -780,6 +753,7 @@ def skip?(activity, user, opts \\ [])
def skip?(%Activity{} = activity, %User{} = user, opts) do
[
:self,
+ :internal,
:invisible,
:block_from_strangers,
:recently_followed,
@@ -799,6 +773,12 @@ def skip?(:self, %Activity{} = activity, %User{} = user, opts) do
end
end
+ def skip?(:internal, %Activity{} = activity, _user, _opts) do
+ actor = activity.data["actor"]
+ user = User.get_cached_by_ap_id(actor)
+ User.internal?(user)
+ end
+
def skip?(:invisible, %Activity{} = activity, _user, _opts) do
actor = activity.data["actor"]
user = User.get_cached_by_ap_id(actor)
@@ -885,4 +865,12 @@ def mark_context_as_read(%User{id: id}, context) do
)
|> Repo.update_all(set: [seen: true])
end
+
+ @spec send(list(Notification.t())) :: :ok
+ def send(notifications) do
+ Enum.each(notifications, fn notification ->
+ Streamer.stream(["user", "user:notification"], notification)
+ Push.send(notification)
+ end)
+ end
end
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index fb8e36bbfd..8f2ce837e4 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -1515,6 +1515,7 @@ def fetch_activities_query(recipients, opts \\ %{}) do
|> restrict_announce_object_actor(opts)
|> restrict_object(opts)
|> restrict_filtered(opts)
+ |> restrict_rule(opts)
|> restrict_quote_url(opts)
|> restrict_rule(opts)
|> maybe_restrict_deactivated_users(opts)
diff --git a/lib/pleroma/web/activity_pub/side_effects.ex b/lib/pleroma/web/activity_pub/side_effects.ex
index dc0b932e5f..9fc979578f 100644
--- a/lib/pleroma/web/activity_pub/side_effects.ex
+++ b/lib/pleroma/web/activity_pub/side_effects.ex
@@ -21,7 +21,6 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
alias Pleroma.Web.ActivityPub.Builder
alias Pleroma.Web.ActivityPub.Pipeline
alias Pleroma.Web.ActivityPub.Utils
- alias Pleroma.Web.Push
alias Pleroma.Web.Streamer
alias Pleroma.Workers.EventReminderWorker
alias Pleroma.Workers.PollWorker
@@ -115,7 +114,7 @@ def handle(
nil
end
- {:ok, notifications} = Notification.create_notifications(object, do_send: false)
+ {:ok, notifications} = Notification.create_notifications(object)
meta =
meta
@@ -174,7 +173,11 @@ def handle(%{data: %{"type" => "Like"}} = object, meta) do
liked_object = Object.get_by_ap_id(object.data["object"])
Utils.add_like_to_object(object, liked_object)
- Notification.create_notifications(object)
+ {:ok, notifications} = Notification.create_notifications(object)
+
+ meta =
+ meta
+ |> add_notifications(notifications)
{:ok, object, meta}
end
@@ -192,7 +195,7 @@ def handle(%{data: %{"type" => "Like"}} = object, meta) do
def handle(%{data: %{"type" => "Create"}} = activity, meta) do
with {:ok, object, meta} <- handle_object_creation(meta[:object_data], activity, meta),
%User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do
- {:ok, notifications} = Notification.create_notifications(activity, do_send: false)
+ {:ok, notifications} = Notification.create_notifications(activity)
{:ok, _user} = ActivityPub.increase_note_count_if_public(user, object)
{:ok, _user} = ActivityPub.update_last_status_at_if_public(user, object)
@@ -250,11 +253,13 @@ def handle(%{data: %{"type" => "Announce"}} = object, meta) do
Utils.add_announce_to_object(object, announced_object)
- if !User.internal?(user) do
- Notification.create_notifications(object)
+ {:ok, notifications} = Notification.create_notifications(object)
- ap_streamer().stream_out(object)
- end
+ if !User.internal?(user), do: ap_streamer().stream_out(object)
+
+ meta =
+ meta
+ |> add_notifications(notifications)
{:ok, object, meta}
end
@@ -275,7 +280,11 @@ def handle(%{data: %{"type" => "EmojiReact"}} = object, meta) do
reacted_object = Object.get_by_ap_id(object.data["object"])
Utils.add_emoji_reaction_to_object(object, reacted_object)
- Notification.create_notifications(object)
+ {:ok, notifications} = Notification.create_notifications(object)
+
+ meta =
+ meta
+ |> add_notifications(notifications)
{:ok, object, meta}
end
@@ -679,10 +688,7 @@ defp delete_object(object) do
defp send_notifications(meta) do
Keyword.get(meta, :notifications, [])
- |> Enum.each(fn notification ->
- Streamer.stream(["user", "user:notification"], notification)
- Push.send(notification)
- end)
+ |> Notification.send()
meta
end
diff --git a/lib/pleroma/web/admin_api/views/report_view.ex b/lib/pleroma/web/admin_api/views/report_view.ex
index c60a5436a3..da61660509 100644
--- a/lib/pleroma/web/admin_api/views/report_view.ex
+++ b/lib/pleroma/web/admin_api/views/report_view.ex
@@ -60,8 +60,8 @@ def render("show.json", %{
}),
state: report.data["state"],
notes: render(__MODULE__, "index_notes.json", %{notes: report.report_notes}),
- assigned_account: assigned_account,
- rules: rules(Map.get(report.data, "rules", nil))
+ rules: rules(Map.get(report.data, "rules", nil)),
+ assigned_account: assigned_account
}
end
diff --git a/lib/pleroma/web/api_spec.ex b/lib/pleroma/web/api_spec.ex
index 6afa5d4354..6cf23c8943 100644
--- a/lib/pleroma/web/api_spec.ex
+++ b/lib/pleroma/web/api_spec.ex
@@ -97,6 +97,7 @@ def spec(opts \\ []) do
"Frontend management",
"Instance configuration",
"Instance documents",
+ "Instance rule managment",
"Invites",
"MediaProxy cache",
"OAuth application management",
diff --git a/lib/pleroma/web/api_spec/operations/admin/report_operation.ex b/lib/pleroma/web/api_spec/operations/admin/report_operation.ex
index d3b2b1ad4d..58669a1fc1 100644
--- a/lib/pleroma/web/api_spec/operations/admin/report_operation.ex
+++ b/lib/pleroma/web/api_spec/operations/admin/report_operation.ex
@@ -198,9 +198,6 @@ defp report do
}
}
},
- assigned_account:
- account_admin()
- |> Map.put(:nullable, true),
rules: %Schema{
type: :array,
items: %Schema{
@@ -211,7 +208,10 @@ defp report do
hint: %Schema{type: :string, nullable: true}
}
}
- }
+ },
+ assigned_account:
+ account_admin()
+ |> Map.put(:nullable, true)
}
}
end
diff --git a/lib/pleroma/web/mastodon_api/views/instance_view.ex b/lib/pleroma/web/mastodon_api/views/instance_view.ex
index 1bd75dec8a..4ba1197421 100644
--- a/lib/pleroma/web/mastodon_api/views/instance_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/instance_view.ex
@@ -185,10 +185,10 @@ def features do
defp common_information(instance) do
%{
- title: Keyword.get(instance, :name),
- version: "#{@mastodon_api_level} (compatible; #{Pleroma.Application.compat_version()})",
languages: Keyword.get(instance, :languages, ["en"]),
- rules: render(__MODULE__, "rules.json")
+ rules: render(__MODULE__, "rules.json"),
+ title: Keyword.get(instance, :name),
+ version: "#{@mastodon_api_level} (compatible; #{Pleroma.Application.compat_version()})"
}
end
diff --git a/lib/pleroma/web/rich_media/parser/card.ex b/lib/pleroma/web/rich_media/parser/card.ex
deleted file mode 100644
index 5bd5823d1d..0000000000
--- a/lib/pleroma/web/rich_media/parser/card.ex
+++ /dev/null
@@ -1,155 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.RichMedia.Parser.Card do
- alias Pleroma.Web.RichMedia.Parser.Card
- alias Pleroma.Web.RichMedia.Parser.Embed
-
- @types ["link", "photo", "video", "rich"]
-
- # https://docs.joinmastodon.org/entities/card/
- defstruct url: nil,
- title: nil,
- description: "",
- type: "link",
- author_name: "",
- author_url: "",
- provider_name: "",
- provider_url: "",
- html: "",
- width: 0,
- height: 0,
- image: nil,
- image_description: "",
- embed_url: "",
- blurhash: nil
-
- def parse(%Embed{url: url, oembed: %{"type" => type, "title" => title} = oembed} = embed)
- when type in @types and is_binary(url) do
- uri = URI.parse(url)
-
- %Card{
- url: url,
- title: title,
- description: get_description(embed),
- type: oembed["type"],
- author_name: oembed["author_name"],
- author_url: oembed["author_url"],
- provider_name: oembed["provider_name"] || uri.host,
- provider_url: oembed["provider_url"] || "#{uri.scheme}://#{uri.host}",
- html: sanitize_html(oembed["html"]),
- width: oembed["width"],
- height: oembed["height"],
- image: get_image(oembed) |> fix_uri(url) |> proxy(),
- image_description: get_image_description(embed),
- embed_url: oembed["url"] |> fix_uri(url) |> proxy()
- }
- |> IO.inspect
- |> validate()
- end
-
- def parse(%Embed{url: url} = embed) when is_binary(url) do
- uri = URI.parse(url)
-
- %Card{
- url: url,
- title: get_title(embed),
- description: get_description(embed),
- type: "link",
- provider_name: uri.host,
- provider_url: "#{uri.scheme}://#{uri.host}",
- image: get_image(embed) |> fix_uri(url) |> proxy(),
- image_description: get_image_description(embed),
- }
- |> validate()
- end
-
- def parse(card), do: {:error, {:invalid_metadata, card}}
-
- defp get_title(embed) do
- case embed do
- %{meta: %{"twitter:title" => title}} when is_binary(title) and title != "" -> title
- %{meta: %{"og:title" => title}} when is_binary(title) and title != "" -> title
- %{title: title} when is_binary(title) and title != "" -> title
- _ -> nil
- end
- end
-
- defp get_description(%{meta: meta}) do
- case meta do
- %{"twitter:description" => desc} when is_binary(desc) and desc != "" -> desc
- %{"og:description" => desc} when is_binary(desc) and desc != "" -> desc
- %{"description" => desc} when is_binary(desc) and desc != "" -> desc
- _ -> ""
- end
- end
-
- defp get_image(%{meta: meta}) do
- case meta do
- %{"twitter:image" => image} when is_binary(image) and image != "" -> image
- %{"og:image" => image} when is_binary(image) and image != "" -> image
- _ -> ""
- end
- end
-
- defp get_image(%{"thumbnail_url" => image}) when is_binary(image) and image != "", do: image
- defp get_image(%{"type" => "photo", "url" => image}), do: image
- defp get_image(_), do: ""
-
- defp get_image_description(%{meta: %{"og:image:alt" => image_description}}), do: image_description
- defp get_image_description(_), do: ""
-
- defp sanitize_html(html) do
- with {:ok, html} <- FastSanitize.Sanitizer.scrub(html, Pleroma.HTML.Scrubber.OEmbed),
- {:ok, [{"iframe", _, _}]} <- Floki.parse_fragment(html) do
- html
- else
- _ -> ""
- end
- end
-
- def to_map(%Card{} = card) do
- card
- |> Map.from_struct()
- |> stringify_keys()
- end
-
- def to_map(%{} = card), do: stringify_keys(card)
-
- defp stringify_keys(%{} = map), do: Map.new(map, fn {k, v} -> {Atom.to_string(k), v} end)
-
- def fix_uri("http://" <> _ = uri, _base_uri), do: uri
- def fix_uri("https://" <> _ = uri, _base_uri), do: uri
- def fix_uri("/" <> _ = uri, base_uri), do: URI.merge(base_uri, uri) |> URI.to_string()
- def fix_uri("", _base_uri), do: nil
-
- def fix_uri(uri, base_uri) when is_binary(uri),
- do: URI.merge(base_uri, "/#{uri}") |> URI.to_string()
-
- def fix_uri(_uri, _base_uri), do: nil
-
- defp proxy(url) when is_binary(url), do: Pleroma.Web.MediaProxy.url(url)
- defp proxy(_), do: nil
-
- def validate(%Card{type: type, html: html} = card)
- when type in ["video", "rich"] and (is_binary(html) == false or html == "") do
- card
- |> Map.put(:type, "link")
- |> validate()
- end
-
- def validate(%Card{type: type, title: title} = card)
- when type in @types and is_binary(title) and title != "" do
- {:ok, card}
- end
-
- def validate(%Embed{} = embed) do
- case Card.parse(embed) do
- {:ok, %Card{} = card} -> validate(card)
- card -> {:error, {:invalid_metadata, card}}
- end
- end
-
- def validate(card), do: {:error, {:invalid_metadata, card}}
-end
diff --git a/lib/pleroma/workers/notification_worker.ex b/lib/pleroma/workers/notification_worker.ex
index a94c5a70e5..92ac7a033e 100644
--- a/lib/pleroma/workers/notification_worker.ex
+++ b/lib/pleroma/workers/notification_worker.ex
@@ -14,8 +14,9 @@ defmodule Pleroma.Workers.NotificationWorker do
@impl Oban.Worker
@spec perform(Oban.Job.t()) :: {:error, :activity_not_found} | {:ok, [Pleroma.Notification.t()]}
def perform(%Job{args: %{"op" => "create", "activity_id" => activity_id}}) do
- with %Activity{} = activity <- find_activity(activity_id) do
- Notification.create_notifications(activity)
+ with %Activity{} = activity <- find_activity(activity_id),
+ {:ok, notifications} <- Notification.create_notifications(activity) do
+ Notification.send(notifications)
end
end
diff --git a/test/fixtures/create-chat-message.json b/test/fixtures/create-chat-message.json
index 9c23a1c9b9..a5e5f559b7 100644
--- a/test/fixtures/create-chat-message.json
+++ b/test/fixtures/create-chat-message.json
@@ -1,10 +1,10 @@
{
- "actor": "http://2hu.gensokyo/users/raymoo",
- "id": "http://2hu.gensokyo/objects/1",
+ "actor": "http://mastodon.example.org/users/admin",
+ "id": "http://mastodon.example.org/objects/1",
"object": {
- "attributedTo": "http://2hu.gensokyo/users/raymoo",
+ "attributedTo": "http://mastodon.example.org/users/admin",
"content": "You expected a cute girl? Too bad. ",
- "id": "http://2hu.gensokyo/objects/2",
+ "id": "http://mastodon.example.org/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 62ff2bfde6..ecbddad489 100644
--- a/test/pleroma/notification_test.exs
+++ b/test/pleroma/notification_test.exs
@@ -6,7 +6,6 @@ defmodule Pleroma.NotificationTest do
use Pleroma.DataCase, async: false
import Pleroma.Factory
- import Mock
alias Pleroma.FollowingRelationship
alias Pleroma.Notification
@@ -18,8 +17,6 @@ defmodule Pleroma.NotificationTest do
alias Pleroma.Web.ActivityPub.Transmogrifier
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.MastodonAPI.NotificationView
- alias Pleroma.Web.Push
- alias Pleroma.Web.Streamer
setup do
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config)
@@ -392,83 +389,6 @@ test "create_poll_notifications/1" do
end
describe "create_notification" do
- @tag needs_streamer: true
- test "it creates a notification for user and send to the 'user' and the 'user:notification' stream" do
- %{user: user, token: oauth_token} = oauth_access(["read"])
-
- task =
- Task.async(fn ->
- {:ok, _topic} = Streamer.get_topic_and_add_socket("user", user, oauth_token)
- assert_receive {:render_with_user, _, _, _, _}, 4_000
- end)
-
- task_user_notification =
- Task.async(fn ->
- {:ok, _topic} =
- Streamer.get_topic_and_add_socket("user:notification", user, oauth_token)
-
- assert_receive {:render_with_user, _, _, _, _}, 4_000
- end)
-
- activity = insert(:note_activity)
-
- notify = Notification.create_notification(activity, user)
- assert notify.user_id == user.id
- Task.await(task)
- Task.await(task_user_notification)
- end
-
- test "it creates a notification for user if the user blocks the activity author" do
- activity = insert(:note_activity)
- author = User.get_cached_by_ap_id(activity.data["actor"])
- user = insert(:user)
- {:ok, _user_relationship} = User.block(user, author)
-
- assert Notification.create_notification(activity, user)
- end
-
- test "it creates a notification for the user if the user mutes the activity author" do
- muter = insert(:user)
- muted = insert(:user)
- {:ok, _} = User.mute(muter, muted)
- muter = Repo.get(User, muter.id)
- {:ok, activity} = CommonAPI.post(muted, %{status: "Hi @#{muter.nickname}"})
-
- notification = Notification.create_notification(activity, muter)
-
- assert notification.id
- assert notification.seen
- end
-
- test "notification created if user is muted without notifications" do
- muter = insert(:user)
- muted = insert(:user)
-
- {:ok, _user_relationships} = User.mute(muter, muted, %{notifications: false})
-
- {:ok, activity} = CommonAPI.post(muted, %{status: "Hi @#{muter.nickname}"})
-
- assert Notification.create_notification(activity, muter)
- end
-
- test "it creates a notification for an activity from a muted thread" do
- muter = insert(:user)
- other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(muter, %{status: "hey"})
- CommonAPI.add_mute(muter, activity)
-
- {:ok, activity} =
- CommonAPI.post(other_user, %{
- status: "Hi @#{muter.nickname}",
- in_reply_to_status_id: activity.id
- })
-
- notification = Notification.create_notification(activity, muter)
-
- assert notification.id
- assert notification.seen
- end
-
test "it disables notifications from strangers" do
follower = insert(:user)
@@ -856,7 +776,7 @@ test "it sends notifications to addressed users in new messages" do
status: "hey @#{other_user.nickname}!"
})
- {enabled_receivers, _disabled_receivers} = Notification.get_notified_from_activity(activity)
+ enabled_receivers = Notification.get_notified_from_activity(activity)
assert other_user in enabled_receivers
end
@@ -888,7 +808,7 @@ test "it sends notifications to mentioned users in new messages" do
{:ok, activity} = Transmogrifier.handle_incoming(create_activity)
- {enabled_receivers, _disabled_receivers} = Notification.get_notified_from_activity(activity)
+ enabled_receivers = Notification.get_notified_from_activity(activity)
assert other_user in enabled_receivers
end
@@ -915,7 +835,7 @@ test "it does not send notifications to users who are only cc in new messages" d
{:ok, activity} = Transmogrifier.handle_incoming(create_activity)
- {enabled_receivers, _disabled_receivers} = Notification.get_notified_from_activity(activity)
+ enabled_receivers = Notification.get_notified_from_activity(activity)
assert other_user not in enabled_receivers
end
@@ -932,8 +852,7 @@ test "it does not send notification to mentioned users in likes" do
{:ok, activity_two} = CommonAPI.favorite(third_user, activity_one.id)
- {enabled_receivers, _disabled_receivers} =
- Notification.get_notified_from_activity(activity_two)
+ enabled_receivers = Notification.get_notified_from_activity(activity_two)
assert other_user not in enabled_receivers
end
@@ -955,7 +874,7 @@ test "it only notifies the post's author in likes" do
|> Map.put("to", [other_user.ap_id | like_data["to"]])
|> ActivityPub.persist(local: true)
- {enabled_receivers, _disabled_receivers} = Notification.get_notified_from_activity(like)
+ enabled_receivers = Notification.get_notified_from_activity(like)
assert other_user not in enabled_receivers
end
@@ -972,39 +891,36 @@ test "it does not send notification to mentioned users in announces" do
{:ok, activity_two} = CommonAPI.repeat(activity_one.id, third_user)
- {enabled_receivers, _disabled_receivers} =
- Notification.get_notified_from_activity(activity_two)
+ enabled_receivers = Notification.get_notified_from_activity(activity_two)
assert other_user not in enabled_receivers
end
- test "it returns blocking recipient in disabled recipients list" do
+ test "it does not return blocking recipient in recipients list" do
user = insert(:user)
other_user = insert(:user)
{:ok, _user_relationship} = User.block(other_user, user)
{:ok, activity} = CommonAPI.post(user, %{status: "hey @#{other_user.nickname}!"})
- {enabled_receivers, disabled_receivers} = Notification.get_notified_from_activity(activity)
+ enabled_receivers = Notification.get_notified_from_activity(activity)
assert [] == enabled_receivers
- assert [other_user] == disabled_receivers
end
- test "it returns notification-muting recipient in disabled recipients list" do
+ test "it does not return notification-muting recipient in recipients list" do
user = insert(:user)
other_user = insert(:user)
{:ok, _user_relationships} = User.mute(other_user, user)
{:ok, activity} = CommonAPI.post(user, %{status: "hey @#{other_user.nickname}!"})
- {enabled_receivers, disabled_receivers} = Notification.get_notified_from_activity(activity)
+ enabled_receivers = Notification.get_notified_from_activity(activity)
assert [] == enabled_receivers
- assert [other_user] == disabled_receivers
end
- test "it returns thread-muting recipient in disabled recipients list" do
+ test "it does not return thread-muting recipient in recipients list" do
user = insert(:user)
other_user = insert(:user)
@@ -1018,14 +934,12 @@ test "it returns thread-muting recipient in disabled recipients list" do
in_reply_to_status_id: activity.id
})
- {enabled_receivers, disabled_receivers} =
- Notification.get_notified_from_activity(same_context_activity)
+ enabled_receivers = Notification.get_notified_from_activity(same_context_activity)
- assert [other_user] == disabled_receivers
refute other_user in enabled_receivers
end
- test "it returns non-following domain-blocking recipient in disabled recipients list" do
+ test "it does not return non-following domain-blocking recipient in recipients list" do
blocked_domain = "blocked.domain"
user = insert(:user, %{ap_id: "https://#{blocked_domain}/@actor"})
other_user = insert(:user)
@@ -1034,10 +948,9 @@ test "it returns non-following domain-blocking recipient in disabled recipients
{:ok, activity} = CommonAPI.post(user, %{status: "hey @#{other_user.nickname}!"})
- {enabled_receivers, disabled_receivers} = Notification.get_notified_from_activity(activity)
+ enabled_receivers = Notification.get_notified_from_activity(activity)
assert [] == enabled_receivers
- assert [other_user] == disabled_receivers
end
test "it returns following domain-blocking recipient in enabled recipients list" do
@@ -1050,10 +963,9 @@ test "it returns following domain-blocking recipient in enabled recipients list"
{:ok, activity} = CommonAPI.post(user, %{status: "hey @#{other_user.nickname}!"})
- {enabled_receivers, disabled_receivers} = Notification.get_notified_from_activity(activity)
+ enabled_receivers = Notification.get_notified_from_activity(activity)
assert [other_user] == enabled_receivers
- assert [] == disabled_receivers
end
test "it sends edited notifications to those who repeated a status" do
@@ -1073,11 +985,10 @@ test "it sends edited notifications to those who repeated a status" do
status: "hey @#{other_user.nickname}! mew mew"
})
- {enabled_receivers, _disabled_receivers} =
- Notification.get_notified_from_activity(edit_activity)
+ enabled_receivers = Notification.get_notified_from_activity(edit_activity)
assert repeated_user in enabled_receivers
- assert other_user not in enabled_receivers
+ refute other_user in enabled_receivers
end
end
@@ -1354,7 +1265,7 @@ test "it doesn't return notifications for muted thread", %{user: user} do
assert Notification.for_user(user) == []
end
- test "it returns notifications from a muted user when with_muted is set", %{user: user} do
+ test "it doesn't return notifications from a muted user when with_muted is set", %{user: user} do
muted = insert(:user)
{:ok, _user_relationships} = User.mute(user, muted)
@@ -1362,7 +1273,7 @@ test "it returns notifications from a muted user when with_muted is set", %{user
Pleroma.Tests.ObanHelpers.perform_all()
- assert length(Notification.for_user(user, %{with_muted: true})) == 1
+ assert Enum.empty?(Notification.for_user(user, %{with_muted: true}))
end
test "it doesn't return notifications from a blocked user when with_muted is set", %{
diff --git a/test/pleroma/user/backup_test.exs b/test/pleroma/user/backup_test.exs
index 1b6a47f88d..12d7af9442 100644
--- a/test/pleroma/user/backup_test.exs
+++ b/test/pleroma/user/backup_test.exs
@@ -230,7 +230,6 @@ test "it creates a zip archive with user data" do
"orderedItems" => [
%{
"object" => %{
- "actor" => "http://cofe.io/users/cofe",
"content" => "status1",
"type" => "Note"
},
@@ -238,7 +237,6 @@ 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/side_effects_test.exs b/test/pleroma/web/activity_pub/side_effects_test.exs
index 2dde0a6e0b..32a7a08bb4 100644
--- a/test/pleroma/web/activity_pub/side_effects_test.exs
+++ b/test/pleroma/web/activity_pub/side_effects_test.exs
@@ -854,31 +854,6 @@ test "creates a notification", %{announce: announce, poster: poster} do
{:ok, announce, _} = SideEffects.handle(announce)
assert Repo.get_by(Notification, user_id: poster.id, activity_id: announce.id)
end
-
- test "it streams out the announce", %{announce: announce} do
- with_mocks([
- {
- Pleroma.Web.Streamer,
- [],
- [
- stream: fn _, _ -> nil end
- ]
- },
- {
- Pleroma.Web.Push,
- [],
- [
- send: fn _ -> nil end
- ]
- }
- ]) do
- {:ok, announce, _} = SideEffects.handle(announce)
-
- assert called(Pleroma.Web.Streamer.stream(["user", "list"], announce))
-
- assert called(Pleroma.Web.Push.send(:_))
- end
- end
end
describe "removing a follower" do
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 c798a0fc9b..0866417502 100644
--- a/test/pleroma/web/activity_pub/transmogrifier/chat_message_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier/chat_message_test.exs
@@ -116,8 +116,6 @@ 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 241ed6033a..673ef86f45 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 modified["object"]["actor"] == modified["object"]["attributedTo"]
+ assert activity.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 modified["object"]["actor"] == modified["object"]["attributedTo"]
+ assert activity.actor == modified["object"]["attributedTo"]
end
test "it strips internal hashtag data" do
@@ -266,6 +266,7 @@ 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/mastodon_api/controllers/instance_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs
index cde7941282..c6299f0345 100644
--- a/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs
@@ -103,31 +103,6 @@ test "get peers", %{conn: conn} do
assert ["peer1.com", "peer2.com"] == Enum.sort(result)
end
- test "get instance rules", %{conn: conn} do
- Rule.create(%{text: "Example rule", hint: "Rule description", priority: 1})
- Rule.create(%{text: "Third rule", priority: 2})
- Rule.create(%{text: "Second rule", priority: 1})
-
- conn = get(conn, "/api/v1/instance")
-
- assert result = json_response_and_validate_schema(conn, 200)
-
- assert [
- %{
- "text" => "Example rule",
- "hint" => "Rule description"
- },
- %{
- "text" => "Second rule",
- "hint" => ""
- },
- %{
- "text" => "Third rule",
- "hint" => ""
- }
- ] = result["rules"]
- end
-
test "get instance configuration", %{conn: conn} do
clear_config([:instance, :limit], 476)
@@ -275,4 +250,29 @@ test "instance domains", %{conn: conn} do
|> get("/api/v1/instance")
|> json_response_and_validate_schema(200)
end
+
+ test "get instance rules", %{conn: conn} do
+ Rule.create(%{text: "Example rule", hint: "Rule description", priority: 1})
+ Rule.create(%{text: "Third rule", priority: 2})
+ Rule.create(%{text: "Second rule", priority: 1})
+
+ conn = get(conn, "/api/v1/instance")
+
+ assert result = json_response_and_validate_schema(conn, 200)
+
+ assert [
+ %{
+ "text" => "Example rule",
+ "hint" => "Rule description"
+ },
+ %{
+ "text" => "Second rule",
+ "hint" => ""
+ },
+ %{
+ "text" => "Third rule",
+ "hint" => ""
+ }
+ ] = result["rules"]
+ end
end