Merge branch 'chore/update-copyrights' into 'develop'
[akkoma] / lib / pleroma / web / views / streamer_view.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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", %User{} = user, %Notification{} = notify) 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("conversation.json", %Participation{} = participation) do
55 %{
56 event: "conversation",
57 payload:
58 Pleroma.Web.MastodonAPI.ConversationView.render("participation.json", %{
59 participation: participation,
60 for: participation.user
61 })
62 |> Jason.encode!()
63 }
64 |> Jason.encode!()
65 end
66 end