fix(notifications): skip the filter check for objects without content

Regex.match? raised on objects without content (for example posts with
only attachments), so no notifications were created for them when the
recipient had an irreversible filter.
This commit is contained in:
Lain Soykaf 2026-10-27 12:53:21 +04:00
commit 21a5d1dca2
No known key found for this signature in database
3 changed files with 21 additions and 0 deletions

View file

@ -0,0 +1 @@
Do not crash when creating notifications for posts without content while the user has filters

View file

@ -821,6 +821,9 @@ defmodule Pleroma.Notification do
object.data["actor"] == user.ap_id -> object.data["actor"] == user.ap_id ->
false false
not is_binary(object.data["content"]) ->
false
not is_nil(regex = Pleroma.Filter.compose_regex(user, :re)) -> not is_nil(regex = Pleroma.Filter.compose_regex(user, :re)) ->
Regex.match?(regex, object.data["content"]) Regex.match?(regex, object.data["content"])

View file

@ -9,6 +9,7 @@ defmodule Pleroma.NotificationTest do
alias Pleroma.FollowingRelationship alias Pleroma.FollowingRelationship
alias Pleroma.Notification alias Pleroma.Notification
alias Pleroma.Object
alias Pleroma.Repo alias Pleroma.Repo
alias Pleroma.Tests.ObanHelpers alias Pleroma.Tests.ObanHelpers
alias Pleroma.User alias Pleroma.User
@ -276,6 +277,22 @@ defmodule Pleroma.NotificationTest do
assert {:ok, []} == Notification.create_notifications(status) assert {:ok, []} == Notification.create_notifications(status)
end end
test "it creates notifications for objects without content when the user has filters" do
author = insert(:user)
user = insert(:user)
insert(:filter, user: user, phrase: "cofe", hide: true)
{:ok, status} = CommonAPI.post(author, %{status: "hey @#{user.nickname}"})
object = Object.normalize(status, fetch: false)
{:ok, _} =
object
|> Object.change(%{data: Map.delete(object.data, "content")})
|> Object.update_and_set_cache()
assert {:ok, [_]} = Notification.create_notifications(Pleroma.Activity.get_by_id(status.id))
end
test "it creates notifications if content matches with a not irreversible filter" do test "it creates notifications if content matches with a not irreversible filter" do
user = insert(:user) user = insert(:user)
subscriber = insert(:user) subscriber = insert(:user)