changeset 188:5e8ea3733dc6

mod_archive: there can be only one note/previous/next/x element in a collection.
author shinysky<shinysky1986(AT)gmail.com>
date Sun, 27 Jun 2010 15:04:24 +0800 (2010-06-27)
parents 670c99e96c52
children 16d367e3c04e
files mod_archive/mod_archive.lua
diffstat 1 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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;