Pleroma API: `POST /api/v1/pleroma/conversations/read` to mark all user's conversatio...
[akkoma] / lib / pleroma / conversation / participation.ex
index e17f49e58da622ec8db706bc2dfad9ca0a2a8f5b..41918fa78e4cd21962c902563b95fa004ebe50d9 100644 (file)
@@ -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})