alias Pleroma.Web.PleromaAPI.ChatView
import Ecto.Query
- import Pleroma.Web.ActivityPub.ObjectValidator, only: [stringify_keys: 1]
action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
plug(
OAuthScopesPlug,
- %{scopes: ["write:statuses"]}
+ %{scopes: ["write:chats"]}
when action in [
:post_chat_message,
:create,
plug(
OAuthScopesPlug,
- %{scopes: ["read:statuses"]} when action in [:messages, :index, :show]
+ %{scopes: ["read:chats"]} when action in [:messages, :index, :show]
)
plug(OpenApiSpex.Plug.CastAndValidate, render_error: Pleroma.Web.ApiSpec.RenderError)
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) do
+ {_n, _} <-
+ MessageReference.set_all_seen_for_chat(chat, last_read_id) do
conn
|> put_view(ChatView)
|> render("show.json", chat: chat)
cm_refs =
chat
|> MessageReference.for_chat_query()
- |> Pagination.fetch_paginated(params |> stringify_keys())
+ |> Pagination.fetch_paginated(params)
conn
|> put_view(MessageReferenceView)
end
end
- def index(%{assigns: %{user: %{id: user_id} = user}} = conn, params) do
+ def index(%{assigns: %{user: %{id: user_id} = user}} = conn, _params) do
blocked_ap_ids = User.blocked_users_ap_ids(user)
chats =
where: c.recipient not in ^blocked_ap_ids,
order_by: [desc: c.updated_at]
)
- |> Pagination.fetch_paginated(params |> stringify_keys)
+ |> Repo.all()
conn
|> put_view(ChatView)