diff options
author | eugenijm <eugenijm@protonmail.com> | 2019-10-02 00:37:08 +0300 |
---|---|---|
committer | eugenijm <eugenijm@protonmail.com> | 2019-10-04 00:53:23 +0300 |
commit | 06d9df79c5c99069dd12e863c99167eb20b6495b (patch) | |
tree | 28a318577f31aef00a01ff321119117dbc44f10c /lib/pleroma/conversation | |
parent | 4fe2af3b2d6b0701de2ae88f9932e4b6039ced11 (diff) | |
download | pleroma-06d9df79c5c99069dd12e863c99167eb20b6495b.tar.gz |
Mastodon API: Add `pleroma.unread_conversation_count` to the Account entity
Diffstat (limited to 'lib/pleroma/conversation')
-rw-r--r-- | lib/pleroma/conversation/participation.ex | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/pleroma/conversation/participation.ex b/lib/pleroma/conversation/participation.ex index e946f6de2..ab81f3217 100644 --- a/lib/pleroma/conversation/participation.ex +++ b/lib/pleroma/conversation/participation.ex @@ -52,6 +52,15 @@ defmodule Pleroma.Conversation.Participation do participation |> read_cng(%{read: true}) |> Repo.update() + |> case do + {:ok, participation} -> + participation = Repo.preload(participation, :user) + User.set_unread_conversation_count(participation.user) + {:ok, participation} + + error -> + error + end end def mark_as_unread(participation) do @@ -135,4 +144,12 @@ defmodule Pleroma.Conversation.Participation do {:ok, Repo.preload(participation, :recipients, force: true)} end + + def unread_conversation_count_for_user(user) do + from(p in __MODULE__, + where: p.user_id == ^user.id, + where: not p.read, + select: %{count: count(p.id)} + ) + end end |