# HG changeset patch # User shinysky # Date 1278567964 -28800 # Node ID 27b8a7482149f534f7044b9f690e7aa3f5296baf # Parent a3b5810de3e44f784a84a3ab08d30b9430534b85 mod_archive: '7.3 Removing a Collection' is DONE, so '7. Archive Management' is DONE. diff -r a3b5810de3e4 -r 27b8a7482149 mod_archive/mod_archive.lua --- 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 JID match +-- TODO 'open attr' in removing a collection