comparison mod_archive/mod_archive.lua @ 753:9d5731af2c27

Merge with Oliver Gerlich
author Matthew Wild <mwild1@gmail.com>
date Fri, 27 Jul 2012 14:29:59 +0100
parents 9bbd99f2057a e4ea03b060ed
children
comparison
equal deleted inserted replaced
752:9bbd99f2057a 753:9d5731af2c27
35 35
36 local function store_prefs(data, node, host) 36 local function store_prefs(data, node, host)
37 dm.store(node, host, PREFS_DIR, st.preserialize(data)); 37 dm.store(node, host, PREFS_DIR, st.preserialize(data));
38 end 38 end
39 39
40 local function os_date()
41 return os.date("!*t");
42 end
43
44 local date_time = datetime.datetime; 40 local date_time = datetime.datetime;
45
46 local function date_format(s)
47 return os.date("%Y-%m-%dT%H:%M:%SZ", s);
48 end
49 41
50 local function date_parse(s) 42 local function date_parse(s)
51 local year, month, day, hour, min, sec = s:match("(....)-?(..)-?(..)T(..):(..):(..)Z"); 43 local year, month, day, hour, min, sec = s:match("(....)-?(..)-?(..)T(..):(..):(..)Z");
52 return os.time({year=year, month=month, day=day, hour=hour, min=min, sec=sec}); 44 return os.time({year=year, month=month, day=day, hour=hour, min=min, sec=sec});
53 end 45 end
93 local function store_msg(msg, node, host, isfrom) 85 local function store_msg(msg, node, host, isfrom)
94 local body = msg:child_with_name("body"); 86 local body = msg:child_with_name("body");
95 local thread = msg:child_with_name("thread"); 87 local thread = msg:child_with_name("thread");
96 local data = dm.list_load(node, host, ARCHIVE_DIR); 88 local data = dm.list_load(node, host, ARCHIVE_DIR);
97 local tag = isfrom and "from" or "to"; 89 local tag = isfrom and "from" or "to";
98 local with = isfrom and msg.attr.to or msg.attr.from; 90 local with = isfrom and msg.attr.from or msg.attr.to;
99 local utc = os_date(); 91 local utc_datetime = date_time();
100 local utc_secs = os.time(utc); 92 local utc_secs = date_parse(utc_datetime);
101 local utc_datetime = date_format(utc_secs);
102 if data then 93 if data then
103 -- The collection list are in REVERSE chronological order 94 -- The collection list are in REVERSE chronological order
104 for k, v in ipairs(data) do 95 for k, v in ipairs(data) do
105 local collection = st.deserialize(v); 96 local collection = st.deserialize(v);
106 local do_save = function() 97 local do_save = function()
759 return tobool(default.attr['save']) ~= false; 750 return tobool(default.attr['save']) ~= false;
760 end 751 end
761 return AUTO_ARCHIVING_ENABLED; 752 return AUTO_ARCHIVING_ENABLED;
762 end 753 end
763 754
764 local function msg_handler(data) 755 local function msg_handler(data, local_jid, other_jid, isfrom)
765 module:log("debug", "-- Enter msg_handler()"); 756 module:log("debug", "-- Enter msg_handler()");
766 local origin, stanza = data.origin, data.stanza; 757 local origin, stanza = data.origin, data.stanza;
767 local body = stanza:child_with_name("body"); 758 local body = stanza:child_with_name("body");
768 local thread = stanza:child_with_name("thread"); 759 local thread = stanza:child_with_name("thread");
769 if body then 760 if body then
770 local from_node, from_host = jid.split(stanza.attr.from); 761 local local_node, local_host = jid.split(local_jid);
771 local to_node, to_host = jid.split(stanza.attr.to); 762 if hosts[local_host] and um.user_exists(local_node, local_host) and apply_pref(local_node, local_host, other_jid, thread) then
772 if hosts[from_host] and um.user_exists(from_node, from_host) and apply_pref(from_node, from_host, stanza.attr.to, thread) then 763 store_msg(stanza, local_node, local_host, isfrom);
773 store_msg(stanza, from_node, from_host, true);
774 end
775 if hosts[to_host] and um.user_exists(to_node, to_host) and apply_pref(to_node, to_host, stanza.attr.from, thread) then
776 store_msg(stanza, to_node, to_host, false);
777 end 764 end
778 end 765 end
779 766
780 return nil; 767 return nil;
768 end
769
770 local function message_handler(data)
771 msg_handler(data, data.stanza.attr.to, data.stanza.attr.from, true)
772 end
773
774 local function premessage_handler(data)
775 msg_handler(data, data.stanza.attr.from, data.stanza.attr.to, false)
781 end 776 end
782 777
783 -- Preferences 778 -- Preferences
784 module:hook("iq/self/urn:xmpp:archive:pref", preferences_handler); 779 module:hook("iq/self/urn:xmpp:archive:pref", preferences_handler);
785 module:hook("iq/self/urn:xmpp:archive:itemremove", itemremove_handler); 780 module:hook("iq/self/urn:xmpp:archive:itemremove", itemremove_handler);
792 module:hook("iq/self/urn:xmpp:archive:retrieve", retrieve_handler); 787 module:hook("iq/self/urn:xmpp:archive:retrieve", retrieve_handler);
793 module:hook("iq/self/urn:xmpp:archive:remove", remove_handler); 788 module:hook("iq/self/urn:xmpp:archive:remove", remove_handler);
794 -- Replication 789 -- Replication
795 module:hook("iq/self/urn:xmpp:archive:modified", modified_handler); 790 module:hook("iq/self/urn:xmpp:archive:modified", modified_handler);
796 791
797 module:hook("message/full", msg_handler, 10); 792 module:hook("message/full", message_handler, 10);
798 module:hook("message/bare", msg_handler, 10); 793 module:hook("message/bare", message_handler, 10);
799 module:hook("pre-message/full", msg_handler, 10); 794 module:hook("pre-message/full", premessage_handler, 10);
800 module:hook("pre-message/bare", msg_handler, 10); 795 module:hook("pre-message/bare", premessage_handler, 10);
801 796
802 -- TODO exactmatch 797 -- TODO exactmatch
803 -- TODO <item/> JID match 798 -- TODO <item/> JID match
804 -- TODO 'open attr' in removing a collection 799 -- TODO 'open attr' in removing a collection
805 -- TODO save = body/message/stream 800 -- TODO save = body/message/stream