aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>2019-10-04 06:47:36 +0200
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>2019-10-04 07:11:53 +0200
commit5dc14c89cecc121ffb047c2a7c972af0b0f89ef8 (patch)
tree83850723c7bbc241d40cf88e9f8c845dc67dd054
parent703deb66d9346e0c8a160ec6c138b3b53b5183b6 (diff)
downloadpleroma-5dc14c89cecc121ffb047c2a7c972af0b0f89ef8.tar.gz
notification_view.ex: Make sure `account` isn’t empty
Related: https://git.pleroma.social/pleroma/pleroma/issues/1203
-rw-r--r--lib/pleroma/web/mastodon_api/views/notification_view.ex60
-rw-r--r--test/web/mastodon_api/views/notification_view_test.exs6
2 files changed, 38 insertions, 28 deletions
diff --git a/lib/pleroma/web/mastodon_api/views/notification_view.ex b/lib/pleroma/web/mastodon_api/views/notification_view.ex
index 60b58dc90..5e3dbe728 100644
--- a/lib/pleroma/web/mastodon_api/views/notification_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/notification_view.ex
@@ -25,40 +25,44 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
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("show.json", %{user: actor, for: user}),
- pleroma: %{
- is_seen: notification.seen
+ with %{id: _} = account <- AccountView.render("show.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("show.json", %{activity: activity, for: user})
- })
+ case mastodon_type do
+ "mention" ->
+ response
+ |> Map.merge(%{
+ status: StatusView.render("show.json", %{activity: activity, for: user})
+ })
- "favourite" ->
- response
- |> Map.merge(%{
- status: StatusView.render("show.json", %{activity: parent_activity, for: user})
- })
+ "favourite" ->
+ response
+ |> Map.merge(%{
+ status: StatusView.render("show.json", %{activity: parent_activity, for: user})
+ })
- "reblog" ->
- response
- |> Map.merge(%{
- status: StatusView.render("show.json", %{activity: parent_activity, for: user})
- })
+ "reblog" ->
+ response
+ |> Map.merge(%{
+ status: StatusView.render("show.json", %{activity: parent_activity, for: user})
+ })
- "follow" ->
- response
+ "follow" ->
+ response
- _ ->
- nil
+ _ ->
+ nil
+ end
+ else
+ _ -> nil
end
end
end
diff --git a/test/web/mastodon_api/views/notification_view_test.exs b/test/web/mastodon_api/views/notification_view_test.exs
index 81ab82e2b..c9043a69a 100644
--- a/test/web/mastodon_api/views/notification_view_test.exs
+++ b/test/web/mastodon_api/views/notification_view_test.exs
@@ -100,5 +100,11 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest 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