require Logger
alias Pleroma.Activity
+ alias Pleroma.ChatMessageReference
alias Pleroma.Config
alias Pleroma.Conversation.Participation
alias Pleroma.Notification
alias Pleroma.Object
- alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Visibility
end)
end
- defp do_stream(topic, %{data: %{"type" => "ChatMessage"}} = object)
+ defp do_stream(topic, {user, %ChatMessageReference{} = cm_ref})
when topic in ["user", "user:pleroma_chat"] do
- recipients = [object.data["actor"] | object.data["to"]]
-
- topics =
- %{ap_id: recipients, local: true}
- |> Pleroma.User.Query.build()
- |> Repo.all()
- |> Enum.map(fn %{id: id} = user -> {user, "#{topic}:#{id}"} end)
-
- Enum.each(topics, fn {user, topic} ->
- Registry.dispatch(@registry, topic, fn list ->
- Enum.each(list, fn {pid, _auth} ->
- text = StreamerView.render("chat_update.json", object, user, recipients)
- send(pid, {:text, text})
- end)
+ topic = "#{topic}:#{user.id}"
+
+ text = StreamerView.render("chat_update.json", %{chat_message_reference: cm_ref})
+
+ Registry.dispatch(@registry, topic, fn list ->
+ Enum.each(list, fn {pid, _auth} ->
+ send(pid, {:text, text})
end)
end)
end