1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4 defmodule Pleroma.Web.PleromaAPI.ChatController do
5 use Pleroma.Web, :controller
12 def index(%{assigns: %{user: %{id: user_id}}} = conn, _params) do
15 where: c.user_id == ^user_id,
16 order_by: [desc: c.updated_at]
21 Enum.map(chats, fn chat ->
24 recipient: chat.recipient,
30 |> json(represented_chats)
33 def create(%{assigns: %{user: user}} = conn, params) do
34 recipient = params["ap_id"] |> URI.decode_www_form()
36 with {:ok, %Chat{} = chat} <- Chat.get_or_create(user.id, recipient) do
39 recipient: chat.recipient,
44 |> json(represented_chat)