ChatController: Make last_read_id mandatory.

This commit is contained in:
lain 2020-06-07 20:22:08 +02:00
commit fe2a5d0614
3 changed files with 11 additions and 27 deletions

View file

@ -340,10 +340,11 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do
title: "MarkAsReadRequest",
description: "POST body for marking a number of chat messages as read",
type: :object,
required: [:last_read_id],
properties: %{
last_read_id: %Schema{
type: :string,
description: "The content of your message. Optional."
description: "The content of your message."
}
},
example: %{

View file

@ -109,10 +109,13 @@ defmodule Pleroma.Web.PleromaAPI.ChatController do
end
end
def mark_as_read(%{assigns: %{user: %{id: user_id}}} = conn, %{id: id}) do
def mark_as_read(
%{body_params: %{last_read_id: last_read_id}, assigns: %{user: %{id: user_id}}} = conn,
%{id: id}
) do
with %Chat{} = chat <- Repo.get_by(Chat, id: id, user_id: user_id),
{_n, _} <-
MessageReference.set_all_seen_for_chat(chat, conn.body_params[:last_read_id]) do
MessageReference.set_all_seen_for_chat(chat, last_read_id) do
conn
|> put_view(ChatView)
|> render("show.json", chat: chat)