# HG changeset patch # User shinysky # Date 1277622264 -28800 # Node ID 5e8ea3733dc6958b156bf2dc9743006392596191 # Parent 670c99e96c52d5dad02887cc4e95ace64798c98a mod_archive: there can be only one note/previous/next/x element in a collection. diff -r 670c99e96c52 -r 5e8ea3733dc6 mod_archive/mod_archive.lua --- a/mod_archive/mod_archive.lua Sun Jun 27 14:03:56 2010 +0800 +++ b/mod_archive/mod_archive.lua Sun Jun 27 15:04:24 2010 +0800 @@ -301,7 +301,21 @@ -- TODO check if there're duplicates for newchild in elem:children() do if type(newchild) == "table" then - collection:add_child(newchild) + if newchild.name == "from" or newchild.name == "to" then + collection:add_child(newchild); + elseif newchild.name == "note" or newchild.name == "previous" or newchild.name == "next" or newchild.name == "x" then + local found = false; + for i, c in ipairs(collection) do + if c.name == newchild.name then + found = true; + collection[i] = newchild; + break; + end + end + if not found then + collection:add_child(newchild); + end + end end end local ver = tonumber(collection.attr["version"]) + 1; @@ -317,6 +331,7 @@ -- not found, create new collection elem.attr["version"] = "0"; origin.send(st.reply(stanza):add_child(save_result(elem))); + -- TODO check if elem is valid(?) dm.list_append(node, host, ARCHIVE_DIR, st.preserialize(elem)); -- TODO unsuccessful reply return true;