diff options
author | Haelwenn <contact+git.pleroma.social@hacktivis.me> | 2019-10-19 19:55:16 +0000 |
---|---|---|
committer | Haelwenn <contact+git.pleroma.social@hacktivis.me> | 2019-10-19 19:55:16 +0000 |
commit | cec4b00140ea67de5933357f46e9519271a074a9 (patch) | |
tree | cd96776891e12f87d59d55b5b98e277699b0136b /lib | |
parent | 289f011e0aae5c6365e30bf0db533d597e48e702 (diff) | |
parent | 52ed2f8f2d962154ba61b31a3f5aab13dc7217fc (diff) | |
download | pleroma-cec4b00140ea67de5933357f46e9519271a074a9.tar.gz |
Merge branch 'mark-all-conversations-as-read' into 'develop'
Pleroma API: `POST /api/v1/pleroma/conversations/read`
See merge request pleroma/pleroma!1830
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/conversation/participation.ex | 13 | ||||
-rw-r--r-- | lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex | 9 | ||||
-rw-r--r-- | lib/pleroma/web/router.ex | 1 |
3 files changed, 23 insertions, 0 deletions
diff --git a/lib/pleroma/conversation/participation.ex b/lib/pleroma/conversation/participation.ex index e17f49e58..41918fa78 100644 --- a/lib/pleroma/conversation/participation.ex +++ b/lib/pleroma/conversation/participation.ex @@ -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}) diff --git a/lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex b/lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex index 9d50a7ca9..fc39abf05 100644 --- a/lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex +++ b/lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex @@ -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 diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index d68fb87da..66e7a2263 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -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 |