Comparison

mod_mam/mod_mam.lua @ 672:8ae5317ba032

mod_mam: local tostring and some comments
author Kim Alvefur <zash@zash.se>
date Thu, 24 May 2012 22:37:14 +0200
parent 671:74efb2db00a6
child 673:9dcf98018644
comparison
equal deleted inserted replaced
671:74efb2db00a6 672:8ae5317ba032
17 local dm_store = require "util.datamanager".store; 17 local dm_store = require "util.datamanager".store;
18 local dm_list_load = require "util.datamanager".list_load; 18 local dm_list_load = require "util.datamanager".list_load;
19 local dm_list_append = require "util.datamanager".list_append; 19 local dm_list_append = require "util.datamanager".list_append;
20 local rm_load_roster = require "core.rostermanager".load_roster; 20 local rm_load_roster = require "core.rostermanager".load_roster;
21 21
22 local tostring = tostring;
22 local time_now = os.time; 23 local time_now = os.time;
23 local timestamp, timestamp_parse = require "util.datetime".datetime, require "util.datetime".parse; 24 local timestamp, timestamp_parse = require "util.datetime".datetime, require "util.datetime".parse;
24 local uuid = require "util.uuid".generate; 25 local uuid = require "util.uuid".generate;
25 local global_default_policy = module:get_option("default_archive_policy", false); 26 local global_default_policy = module:get_option("default_archive_policy", false);
26 -- TODO Should be possible to enforce it too 27 -- TODO Should be possible to enforce it too
27 28
29 -- For translating preference names from string to boolean and back
28 local default_attrs = { 30 local default_attrs = {
29 always = true, [true] = "always", 31 always = true, [true] = "always",
30 never = false, [false] = "never", 32 never = false, [false] = "never",
31 roster = "roster", 33 roster = "roster",
32 } 34 }
223 module:log("debug", "Archiving stanza: %s", stanza:top_tag()); 225 module:log("debug", "Archiving stanza: %s", stanza:top_tag());
224 226
225 local id = uuid(); 227 local id = uuid();
226 local when = time_now(); 228 local when = time_now();
227 -- And stash it 229 -- And stash it
228 dm_list_append(store_user, store_host, "archive2", { 230 local ok, err = dm_list_append(store_user, store_host, "archive2", {
229 -- WARNING This format may change. 231 -- WARNING This format may change.
230 id = id, 232 id = id,
231 when = when, -- This might be an UNIX timestamp. Probably. 233 when = when, -- This might be an UNIX timestamp. Probably.
232 timestamp = timestamp(when), -- Textual timestamp. But I'll assume that comparing numbers is faster and less annoying in case of timezones. 234 timestamp = timestamp(when), -- Textual timestamp. But I'll assume that comparing numbers is faster and less annoying in case of timezones.
233 with = target_jid, 235 with = target_jid,
234 with_bare = target_bare, -- Optimization, to avoid loads of jid_bare() calls when filtering. 236 with_bare = target_bare, -- Optimization, to avoid loads of jid_bare() calls when filtering.
235 stanza = st.preserialize(stanza) 237 stanza = st.preserialize(stanza)
236 }); 238 });
239 --[[ This was dropped from the spec
240 if ok then
241 stanza:tag("archived", { xmlns = xmlns_mam, by = host, id = id }):up();
242 end
243 --]]
237 else 244 else
238 module:log("debug", "Not archiving stanza: %s", stanza:top_tag()); 245 module:log("debug", "Not archiving stanza: %s", stanza:top_tag());
239 end 246 end
240 end 247 end
241 248