Pleroma API: POST /api/v1/pleroma/conversations/read to mark all user's conversations as read
This commit is contained in:
parent
fd6d05dc45
commit
52ed2f8f2d
7 changed files with 72 additions and 0 deletions
|
|
@ -69,6 +69,19 @@ defmodule Pleroma.Conversation.Participation do
|
|||
end
|
||||
end
|
||||
|
||||
def mark_all_as_read(user) do
|
||||
{_, participations} =
|
||||
__MODULE__
|
||||
|> where([p], p.user_id == ^user.id)
|
||||
|> where([p], not p.read)
|
||||
|> update([p], set: [read: true])
|
||||
|> select([p], p)
|
||||
|> Repo.update_all([])
|
||||
|
||||
User.set_unread_conversation_count(user)
|
||||
{:ok, participations}
|
||||
end
|
||||
|
||||
def mark_as_unread(participation) do
|
||||
participation
|
||||
|> read_cng(%{read: false})
|
||||
|
|
|
|||
|
|
@ -79,6 +79,15 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIController do
|
|||
end
|
||||
end
|
||||
|
||||
def read_conversations(%{assigns: %{user: user}} = conn, _params) do
|
||||
with {:ok, participations} <- Participation.mark_all_as_read(user) do
|
||||
conn
|
||||
|> add_link_headers(participations)
|
||||
|> put_view(ConversationView)
|
||||
|> render("participations.json", participations: participations, for: user)
|
||||
end
|
||||
end
|
||||
|
||||
def read_notification(%{assigns: %{user: user}} = conn, %{"id" => notification_id}) do
|
||||
with {:ok, notification} <- Notification.read_one(user, notification_id) do
|
||||
conn
|
||||
|
|
|
|||
|
|
@ -266,6 +266,7 @@ defmodule Pleroma.Web.Router do
|
|||
|
||||
get("/conversations/:id/statuses", PleromaAPIController, :conversation_statuses)
|
||||
get("/conversations/:id", PleromaAPIController, :conversation)
|
||||
post("/conversations/read", PleromaAPIController, :read_conversations)
|
||||
end
|
||||
|
||||
scope [] do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue