Mercurial Hosting > chat
comparison src/lib/Chat.luan @ 53:9298b04607ae
add unread
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 03 Mar 2025 19:39:30 -0700 |
parents | 42b741a1d5c6 |
children | d21ae4920aac |
comparison
equal
deleted
inserted
replaced
52:c3fabb21b6c4 | 53:9298b04607ae |
---|---|
59 end | 59 end |
60 end | 60 end |
61 error() | 61 error() |
62 end | 62 end |
63 | 63 |
64 local function get_chatuser_id(user) | |
65 return chat.id.."~"..user.id | |
66 end | |
67 | |
68 function chat.unread(user) | |
69 local doc = Db.get_document("chatuser_id:"..get_chatuser_id(user)) | |
70 local read_date = doc and doc.read_date or 0 | |
71 return Db.count("+post_chat_id:"..chat.id.." +post_date:["..read_date.." TO *]") | |
72 end | |
73 | |
74 function chat.read(user) | |
75 run_in_transaction( function() | |
76 local chatuser_id = get_chatuser_id(user) | |
77 local doc = Db.get_document("chatuser_id:"..chatuser_id) or { | |
78 type = "chatuser" | |
79 chatuser_id = chatuser_id | |
80 } | |
81 doc.read_date = time_now() | |
82 Db.save(doc) | |
83 end ) | |
84 end | |
85 | |
64 return chat | 86 return chat |
65 end | 87 end |
66 | 88 |
67 function Chat.search(query,sort,rows) | 89 function Chat.search(query,sort,rows) |
68 rows = rows or 1000000 | 90 rows = rows or 1000000 |