aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMaksim Pechnikov <parallel588@gmail.com>2019-10-24 09:50:41 +0300
committerMaksim Pechnikov <parallel588@gmail.com>2019-10-24 12:17:50 +0300
commit922e3d082c38ccd108710e21d4bda8e65b551f9c (patch)
treeec507af94b47050efb8f263dd74ede0f72bf9514 /lib
parent99cf1ef9be93ebab04d088848804369e6295a76d (diff)
downloadpleroma-922e3d082c38ccd108710e21d4bda8e65b551f9c.tar.gz
add test
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/marker.ex14
-rw-r--r--lib/pleroma/notification.ex14
2 files changed, 15 insertions, 13 deletions
diff --git a/lib/pleroma/marker.ex b/lib/pleroma/marker.ex
index 5f6a47f38..a7ea542dd 100644
--- a/lib/pleroma/marker.ex
+++ b/lib/pleroma/marker.ex
@@ -51,19 +51,7 @@ defmodule Pleroma.Marker do
def multi_set_unread_count(multi, %User{} = user, "notifications") do
multi
|> Multi.run(:counters, fn _repo, _changes ->
- query =
- from(q in Pleroma.Notification,
- where: q.user_id == ^user.id,
- select: %{
- timeline: "notifications",
- user_id: type(^user.id, :string),
- unread_count: fragment("SUM( CASE WHEN seen = false THEN 1 ELSE 0 END )"),
- last_read_id:
- type(fragment("MAX( CASE WHEN seen = true THEN id ELSE null END )"), :string)
- }
- )
-
- {:ok, Repo.one(query)}
+ {:ok, Repo.one(Pleroma.Notification.notifications_info_query(user))}
end)
|> Multi.insert(
:marker,
diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex
index af56cc667..373f9b06a 100644
--- a/lib/pleroma/notification.ex
+++ b/lib/pleroma/notification.ex
@@ -36,6 +36,20 @@ defmodule Pleroma.Notification do
|> cast(attrs, [:seen])
end
+ @spec notifications_info_query(User.t()) :: Ecto.Queryable.t()
+ def notifications_info_query(user) do
+ from(q in Pleroma.Notification,
+ where: q.user_id == ^user.id,
+ select: %{
+ timeline: "notifications",
+ user_id: type(^user.id, :string),
+ unread_count: fragment("SUM( CASE WHEN seen = false THEN 1 ELSE 0 END )"),
+ last_read_id:
+ type(fragment("MAX( CASE WHEN seen = true THEN id ELSE null END )"), :string)
+ }
+ )
+ end
+
def for_user_query(user, opts \\ []) do
Notification
|> where(user_id: ^user.id)