diff mod_archive/mod_archive.lua @ 199:27b8a7482149

mod_archive: '7.3 Removing a Collection' is DONE, so '7. Archive Management' is DONE.
author shinysky<shinysky1986(AT)gmail.com>
date Thu, 08 Jul 2010 13:46:04 +0800
parents a3b5810de3e4
children 254c13e049f7
line wrap: on
line diff
--- a/mod_archive/mod_archive.lua	Wed Jul 07 22:07:36 2010 +0800
+++ b/mod_archive/mod_archive.lua	Thu Jul 08 13:46:04 2010 +0800
@@ -501,7 +501,32 @@
 end
 
 local function remove_handler(event)
-    module:log("debug", "-- stanza:\n%s", tostring(event.stanza));
+    local origin, stanza = event.origin, event.stanza;
+    local node, host = origin.username, origin.host;
+	local data = dm.list_load(node, host, ARCHIVE_DIR);
+    local elem = stanza.tags[1];
+    if data then
+        local count = table.getn(data);
+        local found = false;
+        for i = count, 1, -1 do
+            local collection = st.deserialize(data[i]);
+            local res = filter_with(elem.attr["with"], collection.attr["with"]);
+            res = res and filter_start(elem.attr["start"], collection.attr["start"]);
+            res = res and filter_end(elem.attr["end"], collection.attr["start"]);
+            if res then
+                module:log("debug", "-- removing:\n%s", tostring(collection));
+                table.remove(data, i);
+                found = true;
+            end
+        end
+        if found then
+            dm.list_store(node, host, ARCHIVE_DIR, st.preserialize(data));
+        else
+            origin.send(st.error_reply(stanza, "cancel", "item-not-found"));
+            return true;
+        end
+    end
+    origin.send(st.reply(stanza));
     return true;
 end
 
@@ -562,3 +587,5 @@
 
 -- FIXME sort collections
 -- TODO exactmatch
+-- TODO <item/> JID match
+-- TODO 'open attr' in removing a collection