Streamer: fix crash in MastodonAPI.StatusView
authorAlex Gleason <alex@alexgleason.me>
Fri, 13 Aug 2021 15:25:42 +0000 (10:25 -0500)
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Fri, 13 Aug 2021 15:58:03 +0000 (17:58 +0200)
Backport of: https://git.pleroma.social/pleroma/pleroma/-/merge_requests/3508

CHANGELOG.md
lib/pleroma/web/mastodon_api/views/status_view.ex

index 369a8bbdd857796aa031a35143203ec2a00182f8..f06bbfdf04d05d0b400447cccb96a5a78b14fff7 100644 (file)
@@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 - Subscription(Bell) Notifications: Don't create from Pipeline Ingested replies
 - AdminAPI: Fix rendering reports containing a `nil` object
 - Mastodon API: Activity Search fallbacks on status fetching after a DB Timeout/Error
+- Mastodon API: Fix crash in Streamer related to reblogging
 
 ## 2.4.0 - 2021-08-08
 
index da44e0a74a1918124f7e58b20e03e932a5d3963f..463f3419855f75d0c4960f09b43d9b3900c87abb 100644 (file)
@@ -65,11 +65,19 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
 
   defp get_context_id(_), do: nil
 
-  defp reblogged?(activity, user) do
-    object = Object.normalize(activity, fetch: false) || %{}
-    present?(user && user.ap_id in (object.data["announcements"] || []))
+  # Check if the user reblogged this status
+  defp reblogged?(activity, %User{ap_id: ap_id}) do
+    with %Object{data: %{"announcements" => announcements}} when is_list(announcements) <-
+           Object.normalize(activity, fetch: false) do
+      ap_id in announcements
+    else
+      _ -> false
+    end
   end
 
+  # False if the user is logged out
+  defp reblogged?(_activity, _user), do: false
+
   def render("index.json", opts) do
     reading_user = opts[:for]