Diff

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
parent 752:9bbd99f2057a
parent 737:e4ea03b060ed
line wrap: on
line diff
--- a/mod_archive/mod_archive.lua	Mon Jun 11 22:32:45 2012 +0200
+++ b/mod_archive/mod_archive.lua	Fri Jul 27 14:29:59 2012 +0100
@@ -37,16 +37,8 @@
     dm.store(node, host, PREFS_DIR, st.preserialize(data));
 end
 
-local function os_date()
-    return os.date("!*t");
-end
-
 local date_time = datetime.datetime;
 
-local function date_format(s)
-	return os.date("%Y-%m-%dT%H:%M:%SZ", s);
-end
-
 local function date_parse(s)
 	local year, month, day, hour, min, sec = s:match("(....)-?(..)-?(..)T(..):(..):(..)Z");
 	return os.time({year=year, month=month, day=day, hour=hour, min=min, sec=sec});
@@ -95,10 +87,9 @@
     local thread = msg:child_with_name("thread");
 	local data = dm.list_load(node, host, ARCHIVE_DIR);
     local tag = isfrom and "from" or "to";
-    local with = isfrom and msg.attr.to or msg.attr.from;
-    local utc = os_date();
-    local utc_secs = os.time(utc);
-    local utc_datetime = date_format(utc_secs);
+    local with = isfrom and msg.attr.from or msg.attr.to;
+    local utc_datetime = date_time();
+    local utc_secs = date_parse(utc_datetime);
     if data then
         -- The collection list are in REVERSE chronological order 
         for k, v in ipairs(data) do
@@ -761,25 +752,29 @@
     return AUTO_ARCHIVING_ENABLED;
 end
 
-local function msg_handler(data)
+local function msg_handler(data, local_jid, other_jid, isfrom)
     module:log("debug", "-- Enter msg_handler()");
     local origin, stanza = data.origin, data.stanza;
     local body = stanza:child_with_name("body");
     local thread = stanza:child_with_name("thread");
     if body then
-        local from_node, from_host = jid.split(stanza.attr.from);
-        local to_node, to_host = jid.split(stanza.attr.to);
-        if hosts[from_host] and um.user_exists(from_node, from_host) and apply_pref(from_node, from_host, stanza.attr.to, thread) then
-            store_msg(stanza, from_node, from_host, true);
-        end
-        if hosts[to_host] and um.user_exists(to_node, to_host) and apply_pref(to_node, to_host, stanza.attr.from, thread) then
-            store_msg(stanza, to_node, to_host, false);
+        local local_node, local_host = jid.split(local_jid);
+        if hosts[local_host] and um.user_exists(local_node, local_host) and apply_pref(local_node, local_host, other_jid, thread) then
+            store_msg(stanza, local_node, local_host, isfrom);
         end
     end
 
     return nil;
 end
 
+local function message_handler(data)
+    msg_handler(data, data.stanza.attr.to,  data.stanza.attr.from, true)
+end
+
+local function premessage_handler(data)
+    msg_handler(data, data.stanza.attr.from,  data.stanza.attr.to, false)
+end
+
 -- Preferences
 module:hook("iq/self/urn:xmpp:archive:pref", preferences_handler);
 module:hook("iq/self/urn:xmpp:archive:itemremove", itemremove_handler);
@@ -794,10 +789,10 @@
 -- Replication
 module:hook("iq/self/urn:xmpp:archive:modified", modified_handler);
 
-module:hook("message/full", msg_handler, 10);
-module:hook("message/bare", msg_handler, 10);
-module:hook("pre-message/full", msg_handler, 10);
-module:hook("pre-message/bare", msg_handler, 10);
+module:hook("message/full", message_handler, 10);
+module:hook("message/bare", message_handler, 10);
+module:hook("pre-message/full", premessage_handler, 10);
+module:hook("pre-message/bare", premessage_handler, 10);
 
 -- TODO exactmatch
 -- TODO <item/> JID match