annotate plugins/mod_account_activity.lua @ 14167:f149652cb5ff 13.0

mod_cloud_notify: Use correct stanza id when clearing table entries (mem leak) The memory leak fix in 041c7ff18f76 was insufficient, as the wrong stanza id was used to clear the table entries.
author Matthew Wild <mwild1@gmail.com>
date Tue, 19 May 2026 19:26:42 +0100
parents 0c81b8fede94
children 4f4c346e4f39 303069346d10
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13667
3052eae50c98 mod_account_activity: Fix required module names
Matthew Wild <mwild1@gmail.com>
parents: 13665
diff changeset
1 local jid = require "prosody.util.jid";
13665
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 local time = os.time;
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 local store = module:open_store(nil, "keyval+");
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 module:hook("authentication-success", function(event)
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 local session = event.session;
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 if session.username then
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 store:set_key(session.username, "timestamp", time());
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 end
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 end);
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 module:hook("resource-unbind", function(event)
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 local session = event.session;
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 if session.username then
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 store:set_key(session.username, "timestamp", time());
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 end
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 end);
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 local user_sessions = prosody.hosts[module.host].sessions;
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 function get_last_active(username) --luacheck: ignore 131/get_last_active
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 if user_sessions[username] then
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 return os.time(), true; -- Currently connected
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 else
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 local last_activity = store:get(username);
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 if not last_activity then return nil; end
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 return last_activity.timestamp;
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 end
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 end
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 module:add_item("shell-command", {
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 section = "user";
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 section_desc = "View user activity data";
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 name = "activity";
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 desc = "View the last recorded user activity for an account";
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 args = { { name = "jid"; type = "string" } };
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 host_selector = "jid";
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 handler = function(self, userjid) --luacheck: ignore 212/self
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 local username = jid.prepped_split(userjid);
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 local last_timestamp, is_online = get_last_active(username);
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 if not last_timestamp then
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 return true, "No activity";
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 end
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 return true, ("%s (%s)"):format(os.date("%Y-%m-%d %H:%M:%S", last_timestamp), (is_online and "online" or "offline"));
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 end;
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 });
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 module:add_item("shell-command", {
13668
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
50 section = "user";
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
51 section_desc = "View user activity data";
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
52 name = "list_inactive";
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
53 desc = "List inactive user accounts";
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
54 args = {
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
55 { name = "host"; type = "string" };
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
56 { name = "duration"; type = "string" };
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
57 };
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
58 host_selector = "host";
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
59 handler = function(self, host, duration) --luacheck: ignore 212/self
14165
0c81b8fede94 mod_account_activity: Don't traceback when called without options
Matthew Wild <mwild1@gmail.com>
parents: 14047
diff changeset
60 opts = opts or {};
0c81b8fede94 mod_account_activity: Don't traceback when called without options
Matthew Wild <mwild1@gmail.com>
parents: 14047
diff changeset
61
13668
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
62 local um = require "prosody.core.usermanager";
13682
0055c177a54c mod_account_activity: Fix error when no duration specified in shell command
Matthew Wild <mwild1@gmail.com>
parents: 13668
diff changeset
63 local duration_sec = require "prosody.util.human.io".parse_duration(duration or "");
13668
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
64 if not duration_sec then
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
65 return false, ("Invalid duration %q - try something like \"30d\""):format(duration);
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
66 end
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
67
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
68 local now = os.time();
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
69 local n_inactive, n_unknown = 0, 0;
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
70
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
71 for username in um.users(host) do
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
72 local last_active = store:get_key(username, "timestamp");
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
73 if not last_active then
14047
f463e101fbd9 mod_account_activity: Handle authentication provider returning no user info
Matthew Wild <mwild1@gmail.com>
parents: 13682
diff changeset
74 local user_info = um.get_account_info(username, host);
f463e101fbd9 mod_account_activity: Handle authentication provider returning no user info
Matthew Wild <mwild1@gmail.com>
parents: 13682
diff changeset
75 local created_at;
f463e101fbd9 mod_account_activity: Handle authentication provider returning no user info
Matthew Wild <mwild1@gmail.com>
parents: 13682
diff changeset
76 if user_info then
f463e101fbd9 mod_account_activity: Handle authentication provider returning no user info
Matthew Wild <mwild1@gmail.com>
parents: 13682
diff changeset
77 created_at = user_info.created;
f463e101fbd9 mod_account_activity: Handle authentication provider returning no user info
Matthew Wild <mwild1@gmail.com>
parents: 13682
diff changeset
78 if created_at and (now - created_at) > duration_sec then
f463e101fbd9 mod_account_activity: Handle authentication provider returning no user info
Matthew Wild <mwild1@gmail.com>
parents: 13682
diff changeset
79 self.session.print(username, "");
f463e101fbd9 mod_account_activity: Handle authentication provider returning no user info
Matthew Wild <mwild1@gmail.com>
parents: 13682
diff changeset
80 n_inactive = n_inactive + 1;
f463e101fbd9 mod_account_activity: Handle authentication provider returning no user info
Matthew Wild <mwild1@gmail.com>
parents: 13682
diff changeset
81 end
f463e101fbd9 mod_account_activity: Handle authentication provider returning no user info
Matthew Wild <mwild1@gmail.com>
parents: 13682
diff changeset
82 end
f463e101fbd9 mod_account_activity: Handle authentication provider returning no user info
Matthew Wild <mwild1@gmail.com>
parents: 13682
diff changeset
83 if not created_at then
13668
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
84 n_unknown = n_unknown + 1;
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
85 end
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
86 elseif (now - last_active) > duration_sec then
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
87 self.session.print(username, os.date("%Y-%m-%dT%T", last_active));
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
88 n_inactive = n_inactive + 1;
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
89 end
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
90 end
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
91
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
92 if n_unknown > 0 then
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
93 return true, ("%d accounts inactive since %s (%d unknown)"):format(n_inactive, os.date("%Y-%m-%dT%T", now - duration_sec), n_unknown);
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
94 end
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
95 return true, ("%d accounts inactive since %s"):format(n_inactive, os.date("%Y-%m-%dT%T", now - duration_sec));
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
96 end;
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
97 });
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
98
6be7de547a25 mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents: 13667
diff changeset
99 module:add_item("shell-command", {
13665
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
100 section = "migrate";
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
101 section_desc = "Perform data migrations";
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
102 name = "account_activity_lastlog2";
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
103 desc = "Migrate account activity information from mod_lastlog2";
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
104 args = { { name = "host"; type = "string" } };
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
105 host_selector = "host";
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
106 handler = function(self, host) --luacheck: ignore 212/host
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
107 local lastlog2 = module:open_store("lastlog2", "keyval+");
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
108 local n_updated, n_errors, n_skipped = 0, 0, 0;
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
109
13667
3052eae50c98 mod_account_activity: Fix required module names
Matthew Wild <mwild1@gmail.com>
parents: 13665
diff changeset
110 local async = require "prosody.util.async";
13665
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
111
13667
3052eae50c98 mod_account_activity: Fix required module names
Matthew Wild <mwild1@gmail.com>
parents: 13665
diff changeset
112 local p = require "prosody.util.promise".new(function (resolve)
13665
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
113 local async_runner = async.runner(function ()
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
114 local n = 0;
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
115 for username in lastlog2:items() do
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
116 n = n + 1;
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
117 if n % 100 == 0 then
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
118 self.session.print(("Processed %d..."):format(n));
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
119 async.sleep(0);
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
120 end
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
121 local lastlog2_data = lastlog2:get(username);
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
122 if lastlog2_data then
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
123 local current_data, err = store:get(username);
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
124 if not current_data then
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
125 if not err then
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
126 current_data = {};
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
127 else
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
128 n_errors = n_errors + 1;
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
129 end
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
130 end
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
131 if current_data then
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
132 local imported_timestamp = current_data.timestamp;
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
133 local latest;
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
134 for k, v in pairs(lastlog2_data) do
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
135 if k ~= "registered" and (not latest or v.timestamp > latest) then
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
136 latest = v.timestamp;
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
137 end
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
138 end
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
139 if latest and (not imported_timestamp or imported_timestamp < latest) then
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
140 local ok, err = store:set_key(username, "timestamp", latest);
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
141 if ok then
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
142 n_updated = n_updated + 1;
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
143 else
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
144 self.session.print(("WW: Failed to import %q: %s"):format(username, err));
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
145 n_errors = n_errors + 1;
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
146 end
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
147 else
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
148 n_skipped = n_skipped + 1;
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
149 end
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
150 end
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
151 end
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
152 end
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
153 return resolve(("%d accounts imported, %d errors, %d skipped"):format(n_updated, n_errors, n_skipped));
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
154 end);
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
155 async_runner:run(true);
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
156 end);
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
157 return p;
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
158 end;
30a91d819913 mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
159 });