1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MastodonAPI.ConversationView do
10 alias Pleroma.Web.ActivityPub.ActivityPub
11 alias Pleroma.Web.MastodonAPI.AccountView
12 alias Pleroma.Web.MastodonAPI.StatusView
14 def render("participations.json", %{participations: participations, for: user}) do
15 safe_render_many(participations, __MODULE__, "participation.json", %{
21 def render("participation.json", %{participation: participation, for: user}) do
22 participation = Repo.preload(participation, conversation: [], recipients: [])
25 with nil <- participation.last_activity_id do
26 ActivityPub.fetch_latest_activity_id_for_context(participation.conversation.ap_id, %{
28 "blocking_user" => user
32 activity = Activity.get_by_id_with_object(last_activity_id)
33 # Conversations return all users except the current user.
34 users = Enum.reject(participation.recipients, &(&1.id == user.id))
37 id: participation.id |> to_string(),
38 accounts: render(AccountView, "index.json", users: users, as: :user),
39 unread: !participation.read,
41 render(StatusView, "show.json",
43 direct_conversation_id: participation.id