Allow to mark a single notification as read
This commit is contained in:
parent
4b3c86c1a6
commit
43fb03be5a
5 changed files with 62 additions and 0 deletions
|
|
@ -13,6 +13,7 @@ defmodule Pleroma.Notification do
|
|||
alias Pleroma.Web.CommonAPI.Utils
|
||||
|
||||
import Ecto.Query
|
||||
import Ecto.Changeset
|
||||
|
||||
schema "notifications" do
|
||||
field(:seen, :boolean, default: false)
|
||||
|
|
@ -22,6 +23,11 @@ defmodule Pleroma.Notification do
|
|||
timestamps()
|
||||
end
|
||||
|
||||
def changeset(%Notification{} = notification, attrs) do
|
||||
notification
|
||||
|> cast(attrs, [:seen])
|
||||
end
|
||||
|
||||
# TODO: Make generic and unify (see activity_pub.ex)
|
||||
defp restrict_max(query, %{"max_id" => max_id}) do
|
||||
from(activity in query, where: activity.id < ^max_id)
|
||||
|
|
@ -68,6 +74,14 @@ defmodule Pleroma.Notification do
|
|||
Repo.update_all(query, [])
|
||||
end
|
||||
|
||||
def read_one(%User{} = user, notification_id) do
|
||||
with {:ok, %Notification{} = notification} <- get(user, notification_id) do
|
||||
notification
|
||||
|> changeset(%{seen: true})
|
||||
|> Repo.update()
|
||||
end
|
||||
end
|
||||
|
||||
def get(%{id: user_id} = _user, id) do
|
||||
query =
|
||||
from(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue