annotate src/lib/Online.luan @ 73:a63faf49e1d7

last seen
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 08 Mar 2025 20:26:19 -0700
parents
children 7b339b1ccd11
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
73
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local ipairs = Luan.ipairs or error()
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local to_string = Luan.to_string or error()
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Time = require "luan:Time.luan"
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local time_now = Time.now or error()
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local Thread = require "luan:Thread.luan"
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local User = require "site:/lib/User.luan"
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local Online = {}
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 local glob = Thread.global_map("online")
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 function Online.set(user)
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 glob[user.id] = time_now()
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 end
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 function Online.get(user)
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 local online = {}
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 local ids = user.chatting_with_ids()
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 ids[#ids+1] = user.id
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 for _, user_id in ipairs(ids) do
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 online[to_string(user_id)] = glob[user_id]
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 end
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 return online
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 end
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28
a63faf49e1d7 last seen
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 return Online