view src/lib/Online.luan @ 88:7b339b1ccd11

add tools/users.html
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 13 Mar 2025 16:18:39 -0600
parents a63faf49e1d7
children
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local ipairs = Luan.ipairs or error()
local to_string = Luan.to_string or error()
local Time = require "luan:Time.luan"
local time_now = Time.now or error()
local Thread = require "luan:Thread.luan"
local User = require "site:/lib/User.luan"


local Online = {}

local glob = Thread.global_map("online")

function Online.set(user)
	glob[user.id] = time_now()
end

function Online.get(user)
	local online = {}
	local ids = user.chatting_with_ids()
	ids[#ids+1] = user.id
	for _, user_id in ipairs(ids) do
		online[to_string(user_id)] = glob[user_id]
	end
	return online
end

function Online.get_user(user)
	return glob[user.id]
end

return Online