Update updated_at field on notification read
authorRoman Chvanikov <chvanikoff@gmail.com>
Sun, 14 Apr 2019 15:29:05 +0000 (22:29 +0700)
committerRoman Chvanikov <chvanikoff@gmail.com>
Sun, 14 Apr 2019 15:29:05 +0000 (22:29 +0700)
lib/pleroma/notification.ex
test/notification_test.exs

index b357d5399d024cc0968acc5b8719206a2306184c..29845b9da7b279ace549510e57f709754dafe4a4 100644 (file)
@@ -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()
+          ]
         ]
       )
 
index c3db77b6c0943239ce53465e19677e49bebee67c..907b9e6697c9bd31ddfa1686ac5f6f6f24d24aa3 100644 (file)
@@ -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