+ url =
+ if user.local do
+ Pleroma.Web.Router.Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, activity)
+ else
+ object.data["url"] || object.data["external_url"] || object.data["id"]
+ end
+
+ direct_conversation_id =
+ with {_, nil} <- {:direct_conversation_id, opts[:direct_conversation_id]},
+ {_, true} <- {:include_id, opts[:with_direct_conversation_id]},
+ {_, %User{} = for_user} <- {:for_user, opts[:for]} do
+ Activity.direct_conversation_id(activity, for_user)
+ else
+ {:direct_conversation_id, participation_id} when is_integer(participation_id) ->
+ participation_id
+
+ _e ->
+ nil
+ end
+
+ emoji_reactions =
+ object.data
+ |> Map.get("reactions", [])
+ |> EmojiReactionController.filter_allowed_users(
+ opts[:for],
+ Map.get(opts, :with_muted, false)
+ )
+ |> Stream.map(fn {emoji, users, url} ->
+ build_emoji_map(emoji, users, url, opts[:for])
+ end)
+ |> Enum.to_list()
+
+ # Status muted state (would do 1 request per status unless user mutes are preloaded)
+ muted =
+ thread_muted? ||
+ UserRelationship.exists?(
+ get_in(opts, [:relationships, :user_relationships]),
+ :mute,
+ opts[:for],
+ user,
+ fn for_user, user -> User.mutes?(for_user, user) end
+ )
+
+ {pinned?, pinned_at} = pin_data(object, user)
+
+ quote = Activity.get_quoted_activity_from_object(object)
+
+ %{
+ id: to_string(activity.id),
+ uri: object.data["id"],
+ url: url,
+ account:
+ AccountView.render("show.json", %{
+ user: user,
+ for: opts[:for]
+ }),
+ in_reply_to_id: reply_to && to_string(reply_to.id),
+ in_reply_to_account_id: reply_to_user && to_string(reply_to_user.id),
+ reblog: nil,
+ card: card,
+ content: content_html,
+ text: opts[:with_source] && get_source_text(object.data["source"]),
+ created_at: created_at,
+ edited_at: edited_at,
+ reblogs_count: announcement_count,
+ replies_count: object.data["repliesCount"] || 0,
+ favourites_count: like_count,
+ reblogged: reblogged?(activity, opts[:for]),
+ favourited: present?(favorited),
+ bookmarked: present?(bookmarked),
+ muted: muted,
+ pinned: pinned?,
+ sensitive: sensitive,
+ spoiler_text: summary,
+ visibility: get_visibility(object),
+ media_attachments: attachments,
+ poll: render(PollView, "show.json", object: object, for: opts[:for]),
+ mentions: mentions,
+ tags: build_tags(tags),
+ application: build_application(object.data["generator"]),
+ language: nil,
+ emojis: build_emojis(object.data["emoji"]),
+ quote_id: if(quote, do: quote.id, else: nil),
+ quote: maybe_render_quote(quote, opts),
+ emoji_reactions: emoji_reactions,
+ pleroma: %{
+ local: activity.local,
+ conversation_id: get_context_id(activity),
+ context: object.data["context"],
+ in_reply_to_account_acct: reply_to_user && reply_to_user.nickname,
+ content: %{"text/plain" => content_plaintext},
+ spoiler_text: %{"text/plain" => summary},
+ expires_at: expires_at,
+ direct_conversation_id: direct_conversation_id,
+ thread_muted: thread_muted?,
+ emoji_reactions: emoji_reactions,
+ parent_visible: visible_for_user?(reply_to, opts[:for]),
+ pinned_at: pinned_at
+ },
+ akkoma: %{
+ source: object.data["source"]
+ }
+ }
+ else
+ nil -> nil
+ end
+ end