Comparison

mod_archive/mod_archive.lua @ 239:2659ee3e8d56

mod_archive: use usermanager to check if some user exists
author shinysky<shinysky1986(AT)gmail.com>
date Tue, 10 Aug 2010 09:26:52 +0800
parent 237:d900be0dee3e
child 243:6202ce4d12d6
comparison
equal deleted inserted replaced
238:5343b3ebaffb 239:2659ee3e8d56
7 7
8 local st = require "util.stanza"; 8 local st = require "util.stanza";
9 local dm = require "util.datamanager"; 9 local dm = require "util.datamanager";
10 local jid = require "util.jid"; 10 local jid = require "util.jid";
11 local datetime = require "util.datetime"; 11 local datetime = require "util.datetime";
12 local um = require "core.usermanager";
12 13
13 local PREFS_DIR = "archive_prefs"; 14 local PREFS_DIR = "archive_prefs";
14 local ARCHIVE_DIR = "archive"; 15 local ARCHIVE_DIR = "archive";
15 local xmlns_rsm = "http://jabber.org/protocol/rsm"; 16 local xmlns_rsm = "http://jabber.org/protocol/rsm";
16 local DEFAULT_MAX = 100; 17 local DEFAULT_MAX = 100;
17 18
18 local FORCE_ARCHIVING = false; 19 local FORCE_ARCHIVING = false;
19 local AUTO_ARCHIVING_ENABLED = true; 20 local AUTO_ARCHIVING_ENABLED = true;
20
21 local HOST = 'localhost';
22 21
23 module:add_feature("urn:xmpp:archive"); 22 module:add_feature("urn:xmpp:archive");
24 module:add_feature("urn:xmpp:archive:auto"); 23 module:add_feature("urn:xmpp:archive:auto");
25 module:add_feature("urn:xmpp:archive:manage"); 24 module:add_feature("urn:xmpp:archive:manage");
26 module:add_feature("urn:xmpp:archive:manual"); 25 module:add_feature("urn:xmpp:archive:manual");
40 39
41 local function os_date() 40 local function os_date()
42 return os.date("!*t"); 41 return os.date("!*t");
43 end 42 end
44 43
45 local function date_time(localtime) 44 local date_time = datetime.datetime;
46 return datetime.datetime(localtime);
47 end
48 45
49 local function date_format(s) 46 local function date_format(s)
50 return os.date("%Y-%m-%dT%H:%M:%SZ", s); 47 return os.date("%Y-%m-%dT%H:%M:%SZ", s);
51 end 48 end
52 49
58 local function list_reverse(list) 55 local function list_reverse(list)
59 local t, n = {}, #list 56 local t, n = {}, #list
60 for i = 1, n do t[i] = list[n-i+1] end -- reverse 57 for i = 1, n do t[i] = list[n-i+1] end -- reverse
61 for i = 1, n do list[i] = t[i] end -- copy back 58 for i = 1, n do list[i] = t[i] end -- copy back
62 end 59 end
63
64 -- local function list_push(node, host, collection)
65 -- local data = dm.list_load(node, host, ARCHIVE_DIR);
66 -- if data then
67 -- table.insert(data, 1, collection);
68 -- dm.list_store(node, host, ARCHIVE_DIR, st.preserialize(data));
69 -- else
70 -- dm.list_append(node, host, ARCHIVE_DIR, st.preserialize(collection));
71 -- end
72 -- end
73 60
74 local function list_insert(node, host, collection) 61 local function list_insert(node, host, collection)
75 local data = dm.list_load(node, host, ARCHIVE_DIR); 62 local data = dm.list_load(node, host, ARCHIVE_DIR);
76 if data then 63 if data then
77 local s, e = 1, #data; 64 local s, e = 1, #data;
771 local body = stanza:child_with_name("body"); 758 local body = stanza:child_with_name("body");
772 local thread = stanza:child_with_name("thread"); 759 local thread = stanza:child_with_name("thread");
773 if body then 760 if body then
774 local from_node, from_host = jid.split(stanza.attr.from); 761 local from_node, from_host = jid.split(stanza.attr.from);
775 local to_node, to_host = jid.split(stanza.attr.to); 762 local to_node, to_host = jid.split(stanza.attr.to);
776 -- FIXME only archive messages of users on this host 763 if um.user_exists(from_node, from_host) and apply_pref(from_node, from_host, stanza.attr.to, thread) then
777 if from_host == HOST and apply_pref(from_node, from_host, stanza.attr.to, thread) then
778 store_msg(stanza, from_node, from_host, true); 764 store_msg(stanza, from_node, from_host, true);
779 end 765 end
780 if to_host == HOST and apply_pref(to_node, to_host, stanza.attr.from, thread) then 766 if um.user_exists(to_node, to_host) and apply_pref(to_node, to_host, stanza.attr.from, thread) then
781 store_msg(stanza, to_node, to_host, false); 767 store_msg(stanza, to_node, to_host, false);
782 end 768 end
783 end 769 end
784 770
785 return nil; 771 return nil;