changeset 57:c420f39eb474

chatuser_key
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 04 Mar 2025 07:05:12 -0700
parents 323ddacc1593
children 7b6691bd65c3
files src/lib/Chat.luan src/lib/Db.luan
diffstat 2 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/Chat.luan	Tue Mar 04 07:00:42 2025 -0700
+++ b/src/lib/Chat.luan	Tue Mar 04 07:05:12 2025 -0700
@@ -62,22 +62,22 @@
 		error()
 	end
 
-	local function get_chatuser_id(user)
+	local function get_chatuser_key(user)
 		return chat.id.."~"..user.id
 	end
 
 	function chat.unread(user)
-		local doc = Db.get_document("chatuser_id:"..get_chatuser_id(user))
+		local doc = Db.get_document("chatuser_key:"..get_chatuser_key(user))
 		local read_date = doc and doc.read_date or 0
 		return Db.count("+post_chat_id:"..chat.id.." +post_date:["..read_date.." TO *]")
 	end
 
 	function chat.read(user)
 		run_in_transaction( function()
-			local chatuser_id = get_chatuser_id(user)
-			local doc = Db.get_document("chatuser_id:"..chatuser_id) or {
+			local chatuser_key = get_chatuser_key(user)
+			local doc = Db.get_document("chatuser_key:"..chatuser_key) or {
 				type = "chatuser"
-				chatuser_id = chatuser_id
+				chatuser_key = chatuser_key
 				chatuser_chat_id = chat.id or error()
 			}
 			doc.read_date = time_now()
--- a/src/lib/Db.luan	Tue Mar 04 07:00:42 2025 -0700
+++ b/src/lib/Db.luan	Tue Mar 04 07:05:12 2025 -0700
@@ -28,7 +28,7 @@
 Db.indexed_fields.post_chat_id = Lucene.type.long
 Db.indexed_fields.post_date = Lucene.type.long
 
-Db.indexed_fields.chatuser_id = Lucene.type.string
+Db.indexed_fields.chatuser_key = Lucene.type.string
 Db.indexed_fields.chatuser_chat_id = Lucene.type.long
 
 function Db.not_in_transaction()
@@ -46,6 +46,9 @@
 	[2] = function()
 		Db.delete("type:chatuser")
 	end
+	[3] = function()
+		Db.delete("type:chatuser")
+	end
 }
 
 if Http.is_serving then