Mercurial Hosting > chat
view 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 |
line wrap: on
line source
local Luan = require "luan:Luan.luan" local error = Luan.error local ipairs = Luan.ipairs or error() local String = require "luan:String.luan" local to_number = String.to_number or error() local Parsers = require "luan:Parsers.luan" local json_string = Parsers.json_string or error() local Time = require "luan:Time.luan" local time_now = Time.now or error() local Io = require "luan:Io.luan" local Http = require "luan:http/Http.luan" local User = require "site:/lib/User.luan" local current_user = User.current or error() local get_user_by_id = User.get_by_id or error() local Shared = require "site:/lib/Shared.luan" local compressed = Shared.compressed or error() local Online = require "site:/lib/Online.luan" local set_online = Online.set or error() local get_online = Online.get or error() local Chat = require "site:/lib/Chat.luan" local get_chat_by_id = Chat.get_by_id or error() local Logging = require "luan:logging/Logging.luan" local logger = Logging.logger "heartbeat.js" return function() local user = current_user() or error() set_online(user) Io.stdout = Http.response.text_writer() local last_update = Http.request.parameters.last_update or error() last_update = to_number(last_update) or error(last_update) local user_last_update = user.last_update() if time_now() - user_last_update > 70000 and last_update < user_last_update then logger.info "update" %> location = '/'; <% return end local online = get_online(user) %> online = <%=json_string(online,compressed)%>; showOnline(); <% local chat = Http.request.parameters.chat if chat ~= nil then chat = get_chat_by_id(chat) or error() local my_user_id = user.id for _, user_id in ipairs(chat.user_ids) do if user_id == my_user_id then continue end local user = get_user_by_id(user_id) %> readUpTo(<%=user_id%>,<%=json_string(user.name_html())%>,<%=chat.unread(user)%>); <% end end end