API compatibility with fedibird, frontend config (#163)
[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, topic) do
15 %{
16 stream: [topic],
17 event: "update",
18 payload:
19 Pleroma.Web.MastodonAPI.StatusView.render(
20 "show.json",
21 activity: activity,
22 for: user
23 )
24 |> Jason.encode!()
25 }
26 |> Jason.encode!()
27 end
28
29 def render("notification.json", %Notification{} = notify, %User{} = user, topic) do
30 %{
31 stream: [topic],
32 event: "notification",
33 payload:
34 NotificationView.render(
35 "show.json",
36 %{notification: notify, for: user}
37 )
38 |> Jason.encode!()
39 }
40 |> Jason.encode!()
41 end
42
43 def render("update.json", %Activity{} = activity, topic) do
44 %{
45 stream: [topic],
46 event: "update",
47 payload:
48 Pleroma.Web.MastodonAPI.StatusView.render(
49 "show.json",
50 activity: activity
51 )
52 |> Jason.encode!()
53 }
54 |> Jason.encode!()
55 end
56
57 def render("follow_relationships_update.json", item, topic) do
58 %{
59 stream: [topic],
60 event: "pleroma:follow_relationships_update",
61 payload:
62 %{
63 state: item.state,
64 follower: %{
65 id: item.follower.id,
66 follower_count: item.follower.follower_count,
67 following_count: item.follower.following_count
68 },
69 following: %{
70 id: item.following.id,
71 follower_count: item.following.follower_count,
72 following_count: item.following.following_count
73 }
74 }
75 |> Jason.encode!()
76 }
77 |> Jason.encode!()
78 end
79
80 def render("conversation.json", %Participation{} = participation, topic) do
81 %{
82 stream: [topic],
83 event: "conversation",
84 payload:
85 Pleroma.Web.MastodonAPI.ConversationView.render("participation.json", %{
86 participation: participation,
87 for: participation.user
88 })
89 |> Jason.encode!()
90 }
91 |> Jason.encode!()
92 end
93 end