aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Chvanikov <chvanikoff@gmail.com>2019-04-14 22:29:05 +0700
committerRoman Chvanikov <chvanikoff@gmail.com>2019-04-14 22:29:05 +0700
commitdc21181f6504b55afa68de63f170fcb0f1084a6b (patch)
tree6c7a22e3386a0e744a5195222405022951b9e801
parent0cd4b6024d043efb096a353d6bd84ea0aeb74a6f (diff)
downloadpleroma-dc21181f6504b55afa68de63f170fcb0f1084a6b.tar.gz
Update updated_at field on notification read
-rw-r--r--lib/pleroma/notification.ex5
-rw-r--r--test/notification_test.exs23
2 files changed, 27 insertions, 1 deletions
diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex
index b357d5399..29845b9da 100644
--- a/lib/pleroma/notification.ex
+++ b/lib/pleroma/notification.ex
@@ -58,7 +58,10 @@ defmodule Pleroma.Notification do
where: n.user_id == ^user_id,
where: n.id <= ^id,
update: [
- set: [seen: true]
+ set: [
+ seen: true,
+ updated_at: ^NaiveDateTime.utc_now()
+ ]
]
)
diff --git a/test/notification_test.exs b/test/notification_test.exs
index c3db77b6c..907b9e669 100644
--- a/test/notification_test.exs
+++ b/test/notification_test.exs
@@ -300,6 +300,29 @@ defmodule Pleroma.NotificationTest do
assert n2.seen == true
assert n3.seen == false
end
+
+ test "Updates `updated_at` field" do
+ user1 = insert(:user)
+ user2 = insert(:user)
+
+ Enum.each(0..10, fn i ->
+ {:ok, _activity} =
+ TwitterAPI.create_status(user1, %{
+ "status" => "#{i} hi @#{user2.nickname}"
+ })
+ end)
+
+ Process.sleep(1000)
+
+ [notification | _] = Notification.for_user(user2)
+
+ Notification.set_read_up_to(user2, notification.id)
+
+ Notification.for_user(user2)
+ |> Enum.each(fn notification ->
+ assert notification.updated_at > notification.inserted_at
+ end)
+ end
end
describe "notification target determination" do