comparison 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
comparison
equal deleted inserted replaced
198:a3b5810de3e4 199:27b8a7482149
499 origin.send(reply); 499 origin.send(reply);
500 return true; 500 return true;
501 end 501 end
502 502
503 local function remove_handler(event) 503 local function remove_handler(event)
504 module:log("debug", "-- stanza:\n%s", tostring(event.stanza)); 504 local origin, stanza = event.origin, event.stanza;
505 local node, host = origin.username, origin.host;
506 local data = dm.list_load(node, host, ARCHIVE_DIR);
507 local elem = stanza.tags[1];
508 if data then
509 local count = table.getn(data);
510 local found = false;
511 for i = count, 1, -1 do
512 local collection = st.deserialize(data[i]);
513 local res = filter_with(elem.attr["with"], collection.attr["with"]);
514 res = res and filter_start(elem.attr["start"], collection.attr["start"]);
515 res = res and filter_end(elem.attr["end"], collection.attr["start"]);
516 if res then
517 module:log("debug", "-- removing:\n%s", tostring(collection));
518 table.remove(data, i);
519 found = true;
520 end
521 end
522 if found then
523 dm.list_store(node, host, ARCHIVE_DIR, st.preserialize(data));
524 else
525 origin.send(st.error_reply(stanza, "cancel", "item-not-found"));
526 return true;
527 end
528 end
529 origin.send(st.reply(stanza));
505 return true; 530 return true;
506 end 531 end
507 532
508 ------------------------------------------------------------ 533 ------------------------------------------------------------
509 -- Replication 534 -- Replication
560 module:hook("message/full", msg_handler, 10); 585 module:hook("message/full", msg_handler, 10);
561 module:hook("message/bare", msg_handler, 10); 586 module:hook("message/bare", msg_handler, 10);
562 587
563 -- FIXME sort collections 588 -- FIXME sort collections
564 -- TODO exactmatch 589 -- TODO exactmatch
590 -- TODO <item/> JID match
591 -- TODO 'open attr' in removing a collection