30
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
|
3 local String = require "luan:String.luan"
|
|
4 local to_number = String.to_number or error()
|
|
5 local Time = require "luan:Time.luan"
|
|
6 local time_now = Time.now or error()
|
|
7 local Io = require "luan:Io.luan"
|
|
8 local Http = require "luan:http/Http.luan"
|
|
9 local User = require "site:/lib/User.luan"
|
|
10 local current_user = User.current or error()
|
33
|
11 local Shared = require "site:/lib/Shared.luan"
|
|
12 local http_push_to_users = Shared.http_push_to_users or error()
|
30
|
13 local Logging = require "luan:logging/Logging.luan"
|
|
14 local logger = Logging.logger "heartbeat.js"
|
|
15
|
|
16
|
|
17 return function()
|
33
|
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
|
30
|
23 local last_update = Http.request.parameters.last_update or error()
|
|
24 last_update = to_number(last_update) or error()
|
|
25 local user_last_update = user.last_update()
|
|
26 local now = time_now()
|
|
27 if now - user_last_update < 10000 or last_update >= user_last_update then
|
33
|
28 -- logger.info "ok"
|
30
|
29 return
|
|
30 end
|
|
31 logger.info "update"
|
|
32 Io.stdout = Http.response.text_writer()
|
|
33 %>
|
34
|
34 location = '/';
|
30
|
35 <%
|
|
36 end
|