30
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
75
|
3 local ipairs = Luan.ipairs or error()
|
30
|
4 local String = require "luan:String.luan"
|
|
5 local to_number = String.to_number or error()
|
73
|
6 local Parsers = require "luan:Parsers.luan"
|
|
7 local json_string = Parsers.json_string or error()
|
30
|
8 local Time = require "luan:Time.luan"
|
|
9 local time_now = Time.now or error()
|
|
10 local Io = require "luan:Io.luan"
|
|
11 local Http = require "luan:http/Http.luan"
|
|
12 local User = require "site:/lib/User.luan"
|
|
13 local current_user = User.current or error()
|
75
|
14 local get_user_by_id = User.get_by_id or error()
|
33
|
15 local Shared = require "site:/lib/Shared.luan"
|
73
|
16 local compressed = Shared.compressed or error()
|
|
17 local Online = require "site:/lib/Online.luan"
|
|
18 local set_online = Online.set or error()
|
|
19 local get_online = Online.get or error()
|
75
|
20 local Chat = require "site:/lib/Chat.luan"
|
|
21 local get_chat_by_id = Chat.get_by_id or error()
|
30
|
22 local Logging = require "luan:logging/Logging.luan"
|
|
23 local logger = Logging.logger "heartbeat.js"
|
|
24
|
|
25
|
|
26 return function()
|
33
|
27 local user = current_user() or error()
|
73
|
28 set_online(user)
|
|
29 Io.stdout = Http.response.text_writer()
|
33
|
30
|
30
|
31 local last_update = Http.request.parameters.last_update or error()
|
46
|
32 last_update = to_number(last_update) or error(last_update)
|
30
|
33 local user_last_update = user.last_update()
|
73
|
34 if time_now() - user_last_update > 70000 and last_update < user_last_update then
|
|
35 logger.info "update"
|
|
36 %>
|
|
37 location = '/';
|
|
38 <%
|
30
|
39 return
|
|
40 end
|
73
|
41
|
|
42 local online = get_online(user)
|
30
|
43 %>
|
73
|
44 online = <%=json_string(online,compressed)%>;
|
|
45 showOnline();
|
30
|
46 <%
|
75
|
47 local chat = Http.request.parameters.chat
|
|
48 if chat ~= nil then
|
|
49 chat = get_chat_by_id(chat) or error()
|
|
50 local my_user_id = user.id
|
|
51 for _, user_id in ipairs(chat.user_ids) do
|
|
52 if user_id == my_user_id then continue end
|
|
53 local user = get_user_by_id(user_id)
|
|
54 %>
|
|
55 readUpTo(<%=user_id%>,<%=json_string(user.name_html())%>,<%=chat.unread(user)%>);
|
|
56 <%
|
|
57 end
|
|
58 end
|
30
|
59 end
|