Merge branch 'stream-poll-end' into 'develop'

Stream end of poll notification over websockets and web push

See merge request pleroma/pleroma!4137
This commit is contained in:
feld 2024-06-08 17:55:01 +00:00
commit 9d67827619
5 changed files with 35 additions and 8 deletions

View File

@ -0,0 +1 @@
End of poll notifications were not streamed over websockets or web push

View File

@ -479,6 +479,8 @@ defmodule Pleroma.Notification do
end end
end) end)
stream(notifications)
{:ok, notifications} {:ok, notifications}
end end
end end
@ -757,8 +759,9 @@ defmodule Pleroma.Notification do
|> Repo.update_all(set: [seen: true]) |> Repo.update_all(set: [seen: true])
end end
@spec send(list(Notification.t())) :: :ok @doc "Streams a list of notifications over websockets and web push"
def send(notifications) do @spec stream(list(Notification.t())) :: :ok
def stream(notifications) do
Enum.each(notifications, fn notification -> Enum.each(notifications, fn notification ->
Streamer.stream(["user", "user:notification"], notification) Streamer.stream(["user", "user:notification"], notification)
Push.send(notification) Push.send(notification)

View File

@ -201,7 +201,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
def notify_and_stream(activity) do def notify_and_stream(activity) do
{:ok, notifications} = Notification.create_notifications(activity) {:ok, notifications} = Notification.create_notifications(activity)
Notification.send(notifications) Notification.stream(notifications)
original_activity = original_activity =
case activity do case activity do

View File

@ -592,9 +592,9 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
with {:ok, _} <- Repo.delete(object), do: :ok with {:ok, _} <- Repo.delete(object), do: :ok
end end
defp send_notifications(meta) do defp stream_notifications(meta) do
Keyword.get(meta, :notifications, []) Keyword.get(meta, :notifications, [])
|> Notification.send() |> Notification.stream()
meta meta
end end
@ -625,7 +625,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
@impl true @impl true
def handle_after_transaction(meta) do def handle_after_transaction(meta) do
meta meta
|> send_notifications() |> stream_notifications()
|> send_streamables() |> send_streamables()
end end
end end

View File

@ -5,6 +5,7 @@
defmodule Pleroma.NotificationTest do defmodule Pleroma.NotificationTest do
use Pleroma.DataCase, async: false use Pleroma.DataCase, async: false
import Mock
import Pleroma.Factory import Pleroma.Factory
alias Pleroma.FollowingRelationship alias Pleroma.FollowingRelationship
@ -183,9 +184,31 @@ defmodule Pleroma.NotificationTest do
{:ok, _, _} = CommonAPI.vote(user2, question, [0]) {:ok, _, _} = CommonAPI.vote(user2, question, [0])
{:ok, _, _} = CommonAPI.vote(user3, question, [1]) {:ok, _, _} = CommonAPI.vote(user3, question, [1])
{:ok, notifications} = Notification.create_poll_notifications(activity) with_mocks([
{
Pleroma.Web.Streamer,
[],
[
stream: fn _, _ -> nil end
]
},
{
Pleroma.Web.Push,
[],
[
send: fn _ -> nil end
]
}
]) do
{:ok, notifications} = Notification.create_poll_notifications(activity)
assert [user2.id, user3.id, user1.id] == Enum.map(notifications, & &1.user_id) Enum.each(notifications, fn notification ->
assert called(Pleroma.Web.Streamer.stream(["user", "user:notification"], notification))
assert called(Pleroma.Web.Push.send(notification))
end)
assert [user2.id, user3.id, user1.id] == Enum.map(notifications, & &1.user_id)
end
end end
describe "create_notification" do describe "create_notification" do