comparison src/heartbeat.js.luan @ 75:377bdda60f0b

read up to
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 09 Mar 2025 18:26:49 -0600
parents a63faf49e1d7
children 2158a5950fcd
comparison
equal deleted inserted replaced
74:1c0336a7380f 75:377bdda60f0b
1 local Luan = require "luan:Luan.luan" 1 local Luan = require "luan:Luan.luan"
2 local error = Luan.error 2 local error = Luan.error
3 local ipairs = Luan.ipairs or error()
3 local String = require "luan:String.luan" 4 local String = require "luan:String.luan"
4 local to_number = String.to_number or error() 5 local to_number = String.to_number or error()
5 local Parsers = require "luan:Parsers.luan" 6 local Parsers = require "luan:Parsers.luan"
6 local json_string = Parsers.json_string or error() 7 local json_string = Parsers.json_string or error()
7 local Time = require "luan:Time.luan" 8 local Time = require "luan:Time.luan"
8 local time_now = Time.now or error() 9 local time_now = Time.now or error()
9 local Io = require "luan:Io.luan" 10 local Io = require "luan:Io.luan"
10 local Http = require "luan:http/Http.luan" 11 local Http = require "luan:http/Http.luan"
11 local User = require "site:/lib/User.luan" 12 local User = require "site:/lib/User.luan"
12 local current_user = User.current or error() 13 local current_user = User.current or error()
14 local get_user_by_id = User.get_by_id or error()
13 local Shared = require "site:/lib/Shared.luan" 15 local Shared = require "site:/lib/Shared.luan"
14 local compressed = Shared.compressed or error() 16 local compressed = Shared.compressed or error()
15 local Online = require "site:/lib/Online.luan" 17 local Online = require "site:/lib/Online.luan"
16 local set_online = Online.set or error() 18 local set_online = Online.set or error()
17 local get_online = Online.get or error() 19 local get_online = Online.get or error()
20 local Chat = require "site:/lib/Chat.luan"
21 local get_chat_by_id = Chat.get_by_id or error()
18 local Logging = require "luan:logging/Logging.luan" 22 local Logging = require "luan:logging/Logging.luan"
19 local logger = Logging.logger "heartbeat.js" 23 local logger = Logging.logger "heartbeat.js"
20 24
21 25
22 return function() 26 return function()
38 local online = get_online(user) 42 local online = get_online(user)
39 %> 43 %>
40 online = <%=json_string(online,compressed)%>; 44 online = <%=json_string(online,compressed)%>;
41 showOnline(); 45 showOnline();
42 <% 46 <%
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
43 end 59 end