de2e4d1e984dfc6bcaf0158305b7a17d4621bedb
[akkoma] / lib / pleroma / web / views / streamer_view.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.StreamerView do
6 use Pleroma.Web, :view
7
8 alias Pleroma.Activity
9 alias Pleroma.Conversation.Participation
10 alias Pleroma.Notification
11 alias Pleroma.User
12 alias Pleroma.Web.MastodonAPI.NotificationView
13
14 def render("update.json", %Activity{} = activity, %User{} = user) do
15 %{
16 event: "update",
17 payload:
18 Pleroma.Web.MastodonAPI.StatusView.render(
19 "show.json",
20 activity: activity,
21 for: user
22 )
23 |> Jason.encode!()
24 }
25 |> Jason.encode!()
26 end
27
28 def render("notification.json", %Notification{} = notify, %User{} = user) do
29 %{
30 event: "notification",
31 payload:
32 NotificationView.render(
33 "show.json",
34 %{notification: notify, for: user}
35 )
36 |> Jason.encode!()
37 }
38 |> Jason.encode!()
39 end
40
41 def render("update.json", %Activity{} = activity) do
42 %{
43 event: "update",
44 payload:
45 Pleroma.Web.MastodonAPI.StatusView.render(
46 "show.json",
47 activity: activity
48 )
49 |> Jason.encode!()
50 }
51 |> Jason.encode!()
52 end
53
54 def render("follow_relationships_update.json", item) do
55 %{
56 event: "pleroma:follow_relationships_update",
57 payload:
58 %{
59 state: item.state,
60 follower: %{
61 id: item.follower.id,
62 follower_count: item.follower.follower_count,
63 following_count: item.follower.following_count
64 },
65 following: %{
66 id: item.following.id,
67 follower_count: item.following.follower_count,
68 following_count: item.following.following_count
69 }
70 }
71 |> Jason.encode!()
72 }
73 |> Jason.encode!()
74 end
75
76 def render("conversation.json", %Participation{} = participation) do
77 %{
78 event: "conversation",
79 payload:
80 Pleroma.Web.MastodonAPI.ConversationView.render("participation.json", %{
81 participation: participation,
82 for: participation.user
83 })
84 |> Jason.encode!()
85 }
86 |> Jason.encode!()
87 end
88 end