X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Fstreamer.ex;h=6aac472dcdefbc6486d0d0151a477b1eb1b146b7;hb=392bd9ef562a98bb026d49ddd83f108cbe9fdb19;hp=3375af8414acfc742716d1e34955ead8d2f3102c;hpb=a9baf955fa47b58ec9ae1f90da14abc10379dcde;p=akkoma diff --git a/lib/pleroma/web/streamer.ex b/lib/pleroma/web/streamer.ex index 3375af841..6aac472dc 100644 --- a/lib/pleroma/web/streamer.ex +++ b/lib/pleroma/web/streamer.ex @@ -3,6 +3,10 @@ defmodule Pleroma.Web.Streamer do require Logger alias Pleroma.{User, Notification} + def init(args) do + {:ok, args} + end + def start_link do spawn(fn -> # 30 seconds @@ -42,6 +46,19 @@ defmodule Pleroma.Web.Streamer do {:noreply, topics} end + def handle_cast(%{action: :stream, topic: "direct", item: item}, topics) do + recipient_topics = + User.get_recipients_from_activity(item) + |> Enum.map(fn %{id: id} -> "direct:#{id}" end) + + Enum.each(recipient_topics || [], fn user_topic -> + Logger.debug("Trying to push direct message to #{user_topic}\n\n") + push_to_socket(topics, user_topic, item) + end) + + {:noreply, topics} + end + def handle_cast(%{action: :stream, topic: "user", item: %Notification{} = item}, topics) do topic = "user:#{item.user_id}" @@ -133,8 +150,8 @@ defmodule Pleroma.Web.Streamer do end) end - defp internal_topic("user", socket) do - "user:#{socket.assigns[:user].id}" + defp internal_topic(topic, socket) when topic in ~w[user, direct] do + "#{topic}:#{socket.assigns[:user].id}" end defp internal_topic(topic, _), do: topic