diff options
author | eugenijm <eugenijm@protonmail.com> | 2019-03-15 20:06:28 +0300 |
---|---|---|
committer | eugenijm <eugenijm@protonmail.com> | 2019-03-15 23:56:14 +0300 |
commit | 43fb03be5a8968c1df23938ed4f5a93825ab476c (patch) | |
tree | 31b8bc6913a212c1739aa6b27feec0c8ac1b16bf /lib/pleroma/notification.ex | |
parent | 4b3c86c1a61a029202a262229c713cc3737b2a1b (diff) | |
download | pleroma-43fb03be5a8968c1df23938ed4f5a93825ab476c.tar.gz |
Allow to mark a single notification as read
Diffstat (limited to 'lib/pleroma/notification.ex')
-rw-r--r-- | lib/pleroma/notification.ex | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index fe8181d8b..765191275 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -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( |