X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fpleroma%2Fchat%2Fmessage_reference.ex;h=89537d155723d1435056d7e9393f38860046af17;hb=37c37090fab4c6efa138f35f6e2ec7d77a50644b;hp=7ee7508ca8c24f2adf06523114efe3b57462ee82;hpb=1a11f0e453527070a8ab5511318045470abc95e2;p=akkoma
diff --git a/lib/pleroma/chat/message_reference.ex b/lib/pleroma/chat/message_reference.ex
index 7ee7508ca..89537d155 100644
--- a/lib/pleroma/chat/message_reference.ex
+++ b/lib/pleroma/chat/message_reference.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Chat.MessageReference do
@@ -98,12 +98,20 @@ defmodule Pleroma.Chat.MessageReference do
|> Repo.update()
end
- def set_all_seen_for_chat(chat) do
- chat
- |> for_chat_query()
- |> exclude(:order_by)
- |> exclude(:preload)
- |> where([cmr], cmr.unread == true)
+ def set_all_seen_for_chat(chat, last_read_id \\ nil) do
+ query =
+ chat
+ |> for_chat_query()
+ |> exclude(:order_by)
+ |> exclude(:preload)
+ |> where([cmr], cmr.unread == true)
+
+ if last_read_id do
+ query
+ |> where([cmr], cmr.id <= ^last_read_id)
+ else
+ query
+ end
|> Repo.update_all(set: [unread: false])
end
end