Comparison

mod_archive/mod_archive.lua @ 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
parent 187:670c99e96c52
child 193:18a0e5c0bb62
comparison
equal deleted inserted replaced
187:670c99e96c52 188:5e8ea3733dc6
299 if collection.attr["with"] == elem.attr["with"] 299 if collection.attr["with"] == elem.attr["with"]
300 and collection.attr["start"] == elem.attr["start"] then 300 and collection.attr["start"] == elem.attr["start"] then
301 -- TODO check if there're duplicates 301 -- TODO check if there're duplicates
302 for newchild in elem:children() do 302 for newchild in elem:children() do
303 if type(newchild) == "table" then 303 if type(newchild) == "table" then
304 collection:add_child(newchild) 304 if newchild.name == "from" or newchild.name == "to" then
305 collection:add_child(newchild);
306 elseif newchild.name == "note" or newchild.name == "previous" or newchild.name == "next" or newchild.name == "x" then
307 local found = false;
308 for i, c in ipairs(collection) do
309 if c.name == newchild.name then
310 found = true;
311 collection[i] = newchild;
312 break;
313 end
314 end
315 if not found then
316 collection:add_child(newchild);
317 end
318 end
305 end 319 end
306 end 320 end
307 local ver = tonumber(collection.attr["version"]) + 1; 321 local ver = tonumber(collection.attr["version"]) + 1;
308 collection.attr["version"] = tostring(ver); 322 collection.attr["version"] = tostring(ver);
309 collection.attr["subject"] = elem.attr["subject"]; 323 collection.attr["subject"] = elem.attr["subject"];
315 end 329 end
316 end 330 end
317 -- not found, create new collection 331 -- not found, create new collection
318 elem.attr["version"] = "0"; 332 elem.attr["version"] = "0";
319 origin.send(st.reply(stanza):add_child(save_result(elem))); 333 origin.send(st.reply(stanza):add_child(save_result(elem)));
334 -- TODO check if elem is valid(?)
320 dm.list_append(node, host, ARCHIVE_DIR, st.preserialize(elem)); 335 dm.list_append(node, host, ARCHIVE_DIR, st.preserialize(elem));
321 -- TODO unsuccessful reply 336 -- TODO unsuccessful reply
322 return true; 337 return true;
323 end 338 end
324 339