1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.StreamerView do
9 alias Pleroma.Conversation.Participation
10 alias Pleroma.Notification
12 alias Pleroma.Web.MastodonAPI.NotificationView
14 def render("update.json", %Activity{} = activity, %User{} = user) do
18 Pleroma.Web.MastodonAPI.StatusView.render(
28 def render("status_update.json", %Activity{} = activity, %User{} = user) do
30 event: "status.update",
32 Pleroma.Web.MastodonAPI.StatusView.render(
42 def render("notification.json", %Notification{} = notify, %User{} = user) do
44 event: "notification",
46 NotificationView.render(
48 %{notification: notify, for: user}
55 def render("update.json", %Activity{} = activity) do
59 Pleroma.Web.MastodonAPI.StatusView.render(
68 def render("status_update.json", %Activity{} = activity) do
70 event: "status.update",
72 Pleroma.Web.MastodonAPI.StatusView.render(
81 def render("chat_update.json", %{chat_message_reference: cm_ref}) do
82 # Explicitly giving the cmr for the object here, so we don't accidentally
83 # send a later 'last_message' that was inserted between inserting this and
86 # It also contains the chat with a cache of the correct unread count
87 Logger.debug("Trying to stream out #{inspect(cm_ref)}")
90 Pleroma.Web.PleromaAPI.ChatView.render(
92 %{last_message: cm_ref, chat: cm_ref.chat}
96 event: "pleroma:chat_update",
104 def render("follow_relationships_update.json", item) do
106 event: "pleroma:follow_relationships_update",
111 id: item.follower.id,
112 follower_count: item.follower.follower_count,
113 following_count: item.follower.following_count
116 id: item.following.id,
117 follower_count: item.following.follower_count,
118 following_count: item.following.following_count
126 def render("conversation.json", %Participation{} = participation) do
128 event: "conversation",
130 Pleroma.Web.MastodonAPI.ConversationView.render("participation.json", %{
131 participation: participation,
132 for: participation.user