Mercurial Hosting > chat
diff src/lib/User.luan @ 30:f4708943f29e
add heartbeat
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 09 Nov 2024 19:17:21 -0700 |
parents | b8b12fd8be22 |
children | e2b7f6393dab |
line wrap: on
line diff
--- a/src/lib/User.luan Wed Nov 06 23:05:45 2024 -0700 +++ b/src/lib/User.luan Sat Nov 09 19:17:21 2024 -0700 @@ -17,6 +17,7 @@ local Db = require "site:/lib/Db.luan" local run_in_transaction = Db.run_in_transaction or error() local Chat = require "site:/lib/Chat.luan" +local chat_search = Chat.search or error() local Logging = require "luan:logging/Logging.luan" local logger = Logging.logger "User" @@ -52,7 +53,7 @@ function user.delete() run_in_transaction( function() local id = user.id - local chats = Chat.search("chat_user_ids:"..id) + local chats = chat_search("chat_user_ids:"..id) for _, chat in ipairs(chats) do chat.delete() end @@ -68,6 +69,16 @@ Http.request.cookies.password = user.password or error() end + function user.last_update() + local chats = chat_search( "chat_user_ids:"..user.id, "chat_updated desc", 1 ) + local n = #chats + if n == 0 then + return 0 + elseif n == 1 then + return chats[1].updated + else error() end + end + return user end