extend reject MRF to check if originating instance is blocked
[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("status_update.json", %Activity{} = activity, %User{} = user, topic) do
30 activity = Activity.get_create_by_object_ap_id_with_object(activity.object.data["id"])
31
32 %{
33 stream: [topic],
34 event: "status.update",
35 payload:
36 Pleroma.Web.MastodonAPI.StatusView.render(
37 "show.json",
38 activity: activity,
39 for: user
40 )
41 |> Jason.encode!()
42 }
43 |> Jason.encode!()
44 end
45
46 def render("notification.json", %Notification{} = notify, %User{} = user, topic) do
47 %{
48 stream: [topic],
49 event: "notification",
50 payload:
51 NotificationView.render(
52 "show.json",
53 %{notification: notify, for: user}
54 )
55 |> Jason.encode!()
56 }
57 |> Jason.encode!()
58 end
59
60 def render("update.json", %Activity{} = activity, topic) do
61 %{
62 stream: [topic],
63 event: "update",
64 payload:
65 Pleroma.Web.MastodonAPI.StatusView.render(
66 "show.json",
67 activity: activity
68 )
69 |> Jason.encode!()
70 }
71 |> Jason.encode!()
72 end
73
74 def render("status_update.json", %Activity{} = activity, topic) do
75 activity = Activity.get_create_by_object_ap_id_with_object(activity.object.data["id"])
76
77 %{
78 stream: [topic],
79 event: "status.update",
80 payload:
81 Pleroma.Web.MastodonAPI.StatusView.render(
82 "show.json",
83 activity: activity
84 )
85 |> Jason.encode!()
86 }
87 |> Jason.encode!()
88 end
89
90 def render("follow_relationships_update.json", item, topic) do
91 %{
92 stream: [topic],
93 event: "pleroma:follow_relationships_update",
94 payload:
95 %{
96 state: item.state,
97 follower: %{
98 id: item.follower.id,
99 follower_count: item.follower.follower_count,
100 following_count: item.follower.following_count
101 },
102 following: %{
103 id: item.following.id,
104 follower_count: item.following.follower_count,
105 following_count: item.following.following_count
106 }
107 }
108 |> Jason.encode!()
109 }
110 |> Jason.encode!()
111 end
112
113 def render("conversation.json", %Participation{} = participation, topic) do
114 %{
115 stream: [topic],
116 event: "conversation",
117 payload:
118 Pleroma.Web.MastodonAPI.ConversationView.render("participation.json", %{
119 participation: participation,
120 for: participation.user
121 })
122 |> Jason.encode!()
123 }
124 |> Jason.encode!()
125 end
126 end