Mercurial > prosody-modules
comparison mod_lastlog2/mod_lastlog2.lua @ 5774:7b722955c59b
mod_lastlog2: Expose API to query the last active time of a user
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Wed, 06 Dec 2023 12:12:37 +0000 |
| parents | ecc6ad057383 |
| children | 5239ed05bd71 |
comparison
equal
deleted
inserted
replaced
| 5773:3a7349aa95c7 | 5774:7b722955c59b |
|---|---|
| 45 }); | 45 }); |
| 46 end | 46 end |
| 47 end); | 47 end); |
| 48 end | 48 end |
| 49 | 49 |
| 50 do | |
| 51 local user_sessions = prosody.hosts[module.host].sessions; | |
| 52 local kv_store = module:open_store(); | |
| 53 function get_last_active(username) --luacheck: ignore 131/get_last_active | |
| 54 if user_sessions[username] then | |
| 55 return os.time(); -- Currently connected | |
| 56 else | |
| 57 local last_activity = kv_store:get(username); | |
| 58 if not last_activity then return nil; end | |
| 59 local latest = math.max(last_activity.login or 0, last_activity.logout or 0); | |
| 60 if latest == 0 then | |
| 61 return nil; -- Never logged in | |
| 62 end | |
| 63 return latest; | |
| 64 end | |
| 65 end | |
| 66 end | |
| 67 | |
| 50 function module.command(arg) | 68 function module.command(arg) |
| 51 if not arg[1] or arg[1] == "--help" then | 69 if not arg[1] or arg[1] == "--help" then |
| 52 require"util.prosodyctl".show_usage([[mod_lastlog <user@host>]], [[Show when user last logged in or out]]); | 70 require"util.prosodyctl".show_usage([[mod_lastlog <user@host>]], [[Show when user last logged in or out]]); |
| 53 return 1; | 71 return 1; |
| 54 end | 72 end |
