comparison src/heartbeat.js.luan @ 33:e2b7f6393dab

add online
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 10 Nov 2024 19:57:14 -0700
parents f4708943f29e
children 62d04ca486dd
comparison
equal deleted inserted replaced
32:0f40501b0b56 33:e2b7f6393dab
6 local time_now = Time.now or error() 6 local time_now = Time.now or error()
7 local Io = require "luan:Io.luan" 7 local Io = require "luan:Io.luan"
8 local Http = require "luan:http/Http.luan" 8 local Http = require "luan:http/Http.luan"
9 local User = require "site:/lib/User.luan" 9 local User = require "site:/lib/User.luan"
10 local current_user = User.current or error() 10 local current_user = User.current or error()
11 local Shared = require "site:/lib/Shared.luan"
12 local http_push_to_users = Shared.http_push_to_users or error()
11 local Logging = require "luan:logging/Logging.luan" 13 local Logging = require "luan:logging/Logging.luan"
12 local logger = Logging.logger "heartbeat.js" 14 local logger = Logging.logger "heartbeat.js"
13 15
14 16
15 return function() 17 return function()
18 local user = current_user() or error()
19 local user_ids = user.chatting_with_ids()
20 local js = "setOnline("..user.id..")"
21 http_push_to_users( user_ids, js )
22
16 local last_update = Http.request.parameters.last_update or error() 23 local last_update = Http.request.parameters.last_update or error()
17 last_update = to_number(last_update) or error() 24 last_update = to_number(last_update) or error()
18 local user = current_user() or error()
19 local user_last_update = user.last_update() 25 local user_last_update = user.last_update()
20 local now = time_now() 26 local now = time_now()
21 if now - user_last_update < 10000 or last_update >= user_last_update then 27 if now - user_last_update < 10000 or last_update >= user_last_update then
22 logger.info "ok" 28 -- logger.info "ok"
23 return 29 return
24 end 30 end
25 logger.info "update" 31 logger.info "update"
26 Io.stdout = Http.response.text_writer() 32 Io.stdout = Http.response.text_writer()
27 %> 33 %>