aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRoman Chvanikov <chvanikoff@gmail.com>2019-04-19 22:16:17 +0700
committerRoman Chvanikov <chvanikoff@gmail.com>2019-04-19 22:16:17 +0700
commitaeafa0b2ef996f15f9ff4a6ade70a693b12b208f (patch)
tree3c7c46964542b55182012c40d31a2eed2f5a7ed9 /lib
parent2f0203a4a1c7a507aa5cf50be2fd372536ebfc81 (diff)
downloadpleroma-aeafa0b2ef996f15f9ff4a6ade70a693b12b208f.tar.gz
Add Notification.for_user_since/2
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/notification.ex21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex
index 29845b9da..d79f0f563 100644
--- a/lib/pleroma/notification.ex
+++ b/lib/pleroma/notification.ex
@@ -17,6 +17,8 @@ defmodule Pleroma.Notification do
import Ecto.Query
import Ecto.Changeset
+ @type t :: %__MODULE__{}
+
schema "notifications" do
field(:seen, :boolean, default: false)
belongs_to(:user, User, type: Pleroma.FlakeId)
@@ -51,6 +53,25 @@ defmodule Pleroma.Notification do
|> Pagination.fetch_paginated(opts)
end
+ @doc """
+ Returns notifications for user received since given date.
+
+ ## Examples
+
+ iex> Pleroma.Notification.for_user_since(%Pleroma.User{}, ~N[2019-04-13 11:22:33])
+ [%Pleroma.Notification{}, %Pleroma.Notification{}]
+
+ iex> Pleroma.Notification.for_user_since(%Pleroma.User{}, ~N[2019-04-15 11:22:33])
+ []
+ """
+ @spec for_user_since(Pleroma.User.t(), NaiveDateTime.t()) :: [t()]
+ def for_user_since(user, date) do
+ from(n in for_user_query(user),
+ where: n.updated_at > ^date
+ )
+ |> Repo.all()
+ end
+
def set_read_up_to(%{id: user_id} = _user, id) do
query =
from(