Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into remake-remodel-dms
[akkoma] / lib / pleroma / web / pleroma_api / controllers / chat_controller.ex
index 1752579211d8d5cf135e35641766bf62ac276054..bedae73bd8439b8c1c123d15a02ea66856409c36 100644 (file)
@@ -23,7 +23,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatController do
 
   plug(
     OAuthScopesPlug,
-    %{scopes: ["write:statuses"]} when action in [:post_chat_message, :create]
+    %{scopes: ["write:statuses"]} when action in [:post_chat_message, :create, :mark_as_read]
   )
 
   plug(
@@ -51,6 +51,15 @@ defmodule Pleroma.Web.PleromaAPI.ChatController do
     end
   end
 
+  def mark_as_read(%{assigns: %{user: %{id: user_id}}} = conn, %{id: id}) do
+    with %Chat{} = chat <- Repo.get_by(Chat, id: id, user_id: user_id),
+         {:ok, chat} <- Chat.mark_as_read(chat) do
+      conn
+      |> put_view(ChatView)
+      |> render("show.json", chat: chat)
+    end
+  end
+
   def messages(%{assigns: %{user: %{id: user_id} = user}} = conn, %{id: id} = params) do
     with %Chat{} = chat <- Repo.get_by(Chat, id: id, user_id: user_id) do
       messages =