notification_view.ex: Make sure account isn’t empty

Related: https://git.pleroma.social/pleroma/pleroma/issues/1203
This commit is contained in:
Haelwenn (lanodan) Monnier 2019-10-04 06:47:36 +02:00 committed by Ariadne Conill
parent 43be47c161
commit dbd78de176
2 changed files with 38 additions and 28 deletions

View file

@ -25,40 +25,44 @@ def render("show.json", %{
parent_activity = Activity.get_create_by_object_ap_id(activity.data["object"])
mastodon_type = Activity.mastodon_notification_type(activity)
response = %{
id: to_string(notification.id),
type: mastodon_type,
created_at: CommonAPI.Utils.to_masto_date(notification.inserted_at),
account: AccountView.render("account.json", %{user: actor, for: user}),
pleroma: %{
is_seen: notification.seen
with %{id: _} = account <- AccountView.render("account.json", %{user: actor, for: user}) do
response = %{
id: to_string(notification.id),
type: mastodon_type,
created_at: CommonAPI.Utils.to_masto_date(notification.inserted_at),
account: account,
pleroma: %{
is_seen: notification.seen
}
}
}
case mastodon_type do
"mention" ->
response
|> Map.merge(%{
status: StatusView.render("status.json", %{activity: activity, for: user})
})
case mastodon_type do
"mention" ->
response
|> Map.merge(%{
status: StatusView.render("status.json", %{activity: activity, for: user})
})
"favourite" ->
response
|> Map.merge(%{
status: StatusView.render("status.json", %{activity: parent_activity, for: user})
})
"favourite" ->
response
|> Map.merge(%{
status: StatusView.render("status.json", %{activity: parent_activity, for: user})
})
"reblog" ->
response
|> Map.merge(%{
status: StatusView.render("status.json", %{activity: parent_activity, for: user})
})
"reblog" ->
response
|> Map.merge(%{
status: StatusView.render("status.json", %{activity: parent_activity, for: user})
})
"follow" ->
response
"follow" ->
response
_ ->
nil
_ ->
nil
end
else
_ -> nil
end
end
end

View file

@ -100,5 +100,11 @@ test "Follow notification" do
NotificationView.render("index.json", %{notifications: [notification], for: followed})
assert [expected] == result
User.perform(:delete, follower)
notification = Notification |> Repo.one() |> Repo.preload(:activity)
assert [] ==
NotificationView.render("index.json", %{notifications: [notification], for: followed})
end
end