Mercurial Hosting > chat
comparison src/lib/Chat.luan @ 57:c420f39eb474
chatuser_key
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Tue, 04 Mar 2025 07:05:12 -0700 |
| parents | d21ae4920aac |
| children | 7b6691bd65c3 |
comparison
equal
deleted
inserted
replaced
| 56:323ddacc1593 | 57:c420f39eb474 |
|---|---|
| 60 end | 60 end |
| 61 end | 61 end |
| 62 error() | 62 error() |
| 63 end | 63 end |
| 64 | 64 |
| 65 local function get_chatuser_id(user) | 65 local function get_chatuser_key(user) |
| 66 return chat.id.."~"..user.id | 66 return chat.id.."~"..user.id |
| 67 end | 67 end |
| 68 | 68 |
| 69 function chat.unread(user) | 69 function chat.unread(user) |
| 70 local doc = Db.get_document("chatuser_id:"..get_chatuser_id(user)) | 70 local doc = Db.get_document("chatuser_key:"..get_chatuser_key(user)) |
| 71 local read_date = doc and doc.read_date or 0 | 71 local read_date = doc and doc.read_date or 0 |
| 72 return Db.count("+post_chat_id:"..chat.id.." +post_date:["..read_date.." TO *]") | 72 return Db.count("+post_chat_id:"..chat.id.." +post_date:["..read_date.." TO *]") |
| 73 end | 73 end |
| 74 | 74 |
| 75 function chat.read(user) | 75 function chat.read(user) |
| 76 run_in_transaction( function() | 76 run_in_transaction( function() |
| 77 local chatuser_id = get_chatuser_id(user) | 77 local chatuser_key = get_chatuser_key(user) |
| 78 local doc = Db.get_document("chatuser_id:"..chatuser_id) or { | 78 local doc = Db.get_document("chatuser_key:"..chatuser_key) or { |
| 79 type = "chatuser" | 79 type = "chatuser" |
| 80 chatuser_id = chatuser_id | 80 chatuser_key = chatuser_key |
| 81 chatuser_chat_id = chat.id or error() | 81 chatuser_chat_id = chat.id or error() |
| 82 } | 82 } |
| 83 doc.read_date = time_now() | 83 doc.read_date = time_now() |
| 84 Db.save(doc) | 84 Db.save(doc) |
| 85 end ) | 85 end ) |
