summaryrefslogtreecommitdiff
path: root/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pleroma/web/pleroma_api/controllers/chat_controller.ex')
-rw-r--r--lib/pleroma/web/pleroma_api/controllers/chat_controller.ex11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex b/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex
index 175257921..bedae73bd 100644
--- a/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex
+++ b/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex
@@ -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 =