Mercurial Hosting > chat
diff src/heartbeat.js.luan @ 73:a63faf49e1d7
last seen
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 08 Mar 2025 20:26:19 -0700 |
parents | 42b741a1d5c6 |
children | 377bdda60f0b |
line wrap: on
line diff
--- a/src/heartbeat.js.luan Sat Mar 08 17:29:57 2025 -0700 +++ b/src/heartbeat.js.luan Sat Mar 08 20:26:19 2025 -0700 @@ -2,6 +2,8 @@ local error = Luan.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" @@ -9,28 +11,33 @@ local User = require "site:/lib/User.luan" local current_user = User.current or error() local Shared = require "site:/lib/Shared.luan" -local http_push_to_users = Shared.http_push_to_users or error() +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 Logging = require "luan:logging/Logging.luan" local logger = Logging.logger "heartbeat.js" return function() local user = current_user() or error() - local user_ids = user.chatting_with_ids() - local js = "setOnline("..user.id..")" - http_push_to_users( user_ids, js ) + 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() - local now = time_now() - if now - user_last_update < 10000 or last_update >= user_last_update then - -- logger.info "ok" + if time_now() - user_last_update > 70000 and last_update < user_last_update then + logger.info "update" +%> + location = '/'; +<% return end - logger.info "update" - Io.stdout = Http.response.text_writer() + + local online = get_online(user) %> - location = '/'; + online = <%=json_string(online,compressed)%>; + showOnline(); <% end