comparison mod_archive/mod_archive.lua @ 228:56103bdb068c

mod_archive: refactor
author shinysky<shinysky1986(AT)gmail.com>
date Thu, 29 Jul 2010 17:12:55 +0800
parents 7fe326037070
children 0b9e8721b9c2
comparison
equal deleted inserted replaced
226:7fe326037070 228:56103bdb068c
412 end 412 end
413 413
414 ------------------------------------------------------------ 414 ------------------------------------------------------------
415 -- Archive Management 415 -- Archive Management
416 ------------------------------------------------------------ 416 ------------------------------------------------------------
417 local function filter_jid(rule, jid) 417 local function match_jid(rule, jid)
418 return not rule or jid.compare(jid, rule); 418 return not rule or jid.compare(jid, rule);
419 end 419 end
420 420
421 local function filter_start(start, coll_start) 421 local function is_earlier(start, coll_start)
422 return not start or start <= coll_start; 422 return not start or start <= coll_start;
423 end 423 end
424 424
425 local function filter_end(endtime, coll_start) 425 local function is_later(endtime, coll_start)
426 return not endtime or endtime >= coll_start; 426 return not endtime or endtime >= coll_start;
427 end 427 end
428 428
429 local function find_coll(resset, uid) 429 local function find_coll(resset, uid)
430 for i, c in ipairs(resset) do 430 for i, c in ipairs(resset) do
443 local resset = {} 443 local resset = {}
444 if data then 444 if data then
445 for k, v in ipairs(data) do 445 for k, v in ipairs(data) do
446 local collection = st.deserialize(v); 446 local collection = st.deserialize(v);
447 if collection[1] then -- has children(not deleted) 447 if collection[1] then -- has children(not deleted)
448 local res = filter_jid(elem.attr["with"], collection.attr["with"]); 448 local res = match_jid(elem.attr["with"], collection.attr["with"]);
449 res = res and filter_start(elem.attr["start"], collection.attr["start"]); 449 res = res and is_earlier(elem.attr["start"], collection.attr["start"]);
450 res = res and filter_end(elem.attr["end"], collection.attr["start"]); 450 res = res and is_later(elem.attr["end"], collection.attr["start"]);
451 if res then 451 if res then
452 table.insert(resset, collection); 452 table.insert(resset, collection);
453 end 453 end
454 end 454 end
455 end 455 end
600 local count = table.getn(data); 600 local count = table.getn(data);
601 local found = false; 601 local found = false;
602 for i = count, 1, -1 do 602 for i = count, 1, -1 do
603 local collection = st.deserialize(data[i]); 603 local collection = st.deserialize(data[i]);
604 if collection[1] then -- has children(not deleted) 604 if collection[1] then -- has children(not deleted)
605 local res = filter_jid(elem.attr["with"], collection.attr["with"]); 605 local res = match_jid(elem.attr["with"], collection.attr["with"]);
606 res = res and filter_start(elem.attr["start"], collection.attr["start"]); 606 res = res and is_earlier(elem.attr["start"], collection.attr["start"]);
607 res = res and filter_end(elem.attr["end"], collection.attr["start"]); 607 res = res and is_later(elem.attr["end"], collection.attr["start"]);
608 if res then 608 if res then
609 -- table.remove(data, i); 609 -- table.remove(data, i);
610 local temp = st.stanza('chat', collection.attr); 610 local temp = st.stanza('chat', collection.attr);
611 temp.attr["access"] = date_time(); 611 temp.attr["access"] = date_time();
612 data[i] = temp; 612 data[i] = temp;
635 local elem = stanza.tags[1]; 635 local elem = stanza.tags[1];
636 local resset = {} 636 local resset = {}
637 if data then 637 if data then
638 for k, v in ipairs(data) do 638 for k, v in ipairs(data) do
639 local collection = st.deserialize(v); 639 local collection = st.deserialize(v);
640 local res = filter_start(elem.attr["start"], collection.attr["access"]); 640 local res = is_earlier(elem.attr["start"], collection.attr["access"]);
641 if res then 641 if res then
642 table.insert(resset, collection); 642 table.insert(resset, collection);
643 end 643 end
644 end 644 end
645 end 645 end
714 elseif not exactmatch then 714 elseif not exactmatch then
715 if tobool(child.attr['exactmatch']) then 715 if tobool(child.attr['exactmatch']) then
716 if child.attr[k] == v then 716 if child.attr[k] == v then
717 return child; 717 return child;
718 end 718 end
719 elseif filter_jid(child.attr[k], v) then 719 elseif match_jid(child.attr[k], v) then
720 return child; 720 return child;
721 end 721 end
722 end 722 end
723 else 723 else
724 return child; 724 return child;