Mercurial > prosody-modules
comparison mod_archive/mod_archive.lua @ 209:254c13e049f7
mod_archive: added a 'access' attribute to the chat element, representing the time last accessed.
| author | shinysky<shinysky1986(AT)gmail.com> |
|---|---|
| date | Tue, 13 Jul 2010 23:24:49 +0800 |
| parents | 27b8a7482149 |
| children | 2d63d50d9713 |
comparison
equal
deleted
inserted
replaced
| 208:214cb85cdfbf | 209:254c13e049f7 |
|---|---|
| 53 if collection.attr["thread"] == thread:get_text() then | 53 if collection.attr["thread"] == thread:get_text() then |
| 54 -- TODO figure out secs | 54 -- TODO figure out secs |
| 55 collection:tag(tag, {secs='1', utc=os_time()}):add_child(body); | 55 collection:tag(tag, {secs='1', utc=os_time()}):add_child(body); |
| 56 local ver = tonumber(collection.attr["version"]) + 1; | 56 local ver = tonumber(collection.attr["version"]) + 1; |
| 57 collection.attr["version"] = tostring(ver); | 57 collection.attr["version"] = tostring(ver); |
| 58 collection.attr["access"] = os_time(); | |
| 58 data[k] = collection; | 59 data[k] = collection; |
| 59 dm.list_store(node, host, ARCHIVE_DIR, st.preserialize(data)); | 60 dm.list_store(node, host, ARCHIVE_DIR, st.preserialize(data)); |
| 60 return; | 61 return; |
| 61 end | 62 end |
| 62 end | 63 end |
| 63 end | 64 end |
| 64 -- not found, create new collection | 65 -- not found, create new collection |
| 65 local utc = os_time(); | 66 local utc = os_time(); |
| 66 local collection = st.stanza('chat', {with = isfrom and msg.attr.to or msg.attr.from, start=utc, thread=thread:get_text(), version='0'}); | 67 local collection = st.stanza('chat', {with = isfrom and msg.attr.to or msg.attr.from, start=utc, thread=thread:get_text(), version='0', access=utc}); |
| 67 collection:tag(tag, {secs='0', utc=utc}):add_child(body); | 68 collection:tag(tag, {secs='0', utc=utc}):add_child(body); |
| 68 dm.list_append(node, host, ARCHIVE_DIR, st.preserialize(collection)); | 69 dm.list_append(node, host, ARCHIVE_DIR, st.preserialize(collection)); |
| 69 end | 70 end |
| 70 | 71 |
| 71 local function save_result(collection) | 72 local function save_result(collection) |
| 305 end | 306 end |
| 306 end | 307 end |
| 307 local ver = tonumber(collection.attr["version"]) + 1; | 308 local ver = tonumber(collection.attr["version"]) + 1; |
| 308 collection.attr["version"] = tostring(ver); | 309 collection.attr["version"] = tostring(ver); |
| 309 collection.attr["subject"] = elem.attr["subject"]; | 310 collection.attr["subject"] = elem.attr["subject"]; |
| 311 collection.attr["access"] = os_time(); | |
| 310 origin.send(st.reply(stanza):add_child(save_result(collection))); | 312 origin.send(st.reply(stanza):add_child(save_result(collection))); |
| 311 data[k] = collection; | 313 data[k] = collection; |
| 312 dm.list_store(node, host, ARCHIVE_DIR, st.preserialize(data)); | 314 dm.list_store(node, host, ARCHIVE_DIR, st.preserialize(data)); |
| 313 return true; | 315 return true; |
| 314 end | 316 end |
| 315 end | 317 end |
| 316 end | 318 end |
| 317 -- not found, create new collection | 319 -- not found, create new collection |
| 318 elem.attr["version"] = "0"; | 320 elem.attr["version"] = "0"; |
| 321 elem.attr["access"] = os_time(); | |
| 319 origin.send(st.reply(stanza):add_child(save_result(elem))); | 322 origin.send(st.reply(stanza):add_child(save_result(elem))); |
| 320 -- TODO check if elem is valid(?) | 323 -- TODO check if elem is valid(?) |
| 321 dm.list_append(node, host, ARCHIVE_DIR, st.preserialize(elem)); | 324 dm.list_append(node, host, ARCHIVE_DIR, st.preserialize(elem)); |
| 322 -- TODO unsuccessful reply | 325 -- TODO unsuccessful reply |
| 323 return true; | 326 return true; |
| 354 local elem = stanza.tags[1]; | 357 local elem = stanza.tags[1]; |
| 355 local resset = {} | 358 local resset = {} |
| 356 if data then | 359 if data then |
| 357 for k, v in ipairs(data) do | 360 for k, v in ipairs(data) do |
| 358 local collection = st.deserialize(v); | 361 local collection = st.deserialize(v); |
| 359 local res = filter_with(elem.attr["with"], collection.attr["with"]); | 362 if collection[1] then -- has children(not deleted) |
| 360 res = res and filter_start(elem.attr["start"], collection.attr["start"]); | 363 local res = filter_with(elem.attr["with"], collection.attr["with"]); |
| 361 res = res and filter_end(elem.attr["end"], collection.attr["start"]); | 364 res = res and filter_start(elem.attr["start"], collection.attr["start"]); |
| 362 if res then | 365 res = res and filter_end(elem.attr["end"], collection.attr["start"]); |
| 363 table.insert(resset, collection); | 366 if res then |
| 367 table.insert(resset, collection); | |
| 368 end | |
| 364 end | 369 end |
| 365 end | 370 end |
| 366 end | 371 end |
| 367 local reply = st.reply(stanza):tag('list', {xmlns='urn:xmpp:archive'}); | 372 local reply = st.reply(stanza):tag('list', {xmlns='urn:xmpp:archive'}); |
| 368 local count = table.getn(resset); | 373 local count = table.getn(resset); |
| 426 local elem = stanza.tags[1]; | 431 local elem = stanza.tags[1]; |
| 427 local collection = nil; | 432 local collection = nil; |
| 428 if data then | 433 if data then |
| 429 for k, v in ipairs(data) do | 434 for k, v in ipairs(data) do |
| 430 local c = st.deserialize(v); | 435 local c = st.deserialize(v); |
| 431 if c.attr["with"] == elem.attr["with"] | 436 if c[1] -- not deleted |
| 437 and c.attr["with"] == elem.attr["with"] | |
| 432 and c.attr["start"] == elem.attr["start"] then | 438 and c.attr["start"] == elem.attr["start"] then |
| 433 collection = c; | 439 collection = c; |
| 434 break; | 440 break; |
| 435 end | 441 end |
| 436 end | 442 end |
| 508 if data then | 514 if data then |
| 509 local count = table.getn(data); | 515 local count = table.getn(data); |
| 510 local found = false; | 516 local found = false; |
| 511 for i = count, 1, -1 do | 517 for i = count, 1, -1 do |
| 512 local collection = st.deserialize(data[i]); | 518 local collection = st.deserialize(data[i]); |
| 513 local res = filter_with(elem.attr["with"], collection.attr["with"]); | 519 if collection[1] then -- has children(not deleted) |
| 514 res = res and filter_start(elem.attr["start"], collection.attr["start"]); | 520 local res = filter_with(elem.attr["with"], collection.attr["with"]); |
| 515 res = res and filter_end(elem.attr["end"], collection.attr["start"]); | 521 res = res and filter_start(elem.attr["start"], collection.attr["start"]); |
| 516 if res then | 522 res = res and filter_end(elem.attr["end"], collection.attr["start"]); |
| 517 module:log("debug", "-- removing:\n%s", tostring(collection)); | 523 if res then |
| 518 table.remove(data, i); | 524 -- table.remove(data, i); |
| 519 found = true; | 525 local temp = st.stanza('chat', collection.attr); |
| 526 temp.attr["access"] = os_time(); | |
| 527 data[i] = temp; | |
| 528 found = true; | |
| 529 end | |
| 520 end | 530 end |
| 521 end | 531 end |
| 522 if found then | 532 if found then |
| 523 dm.list_store(node, host, ARCHIVE_DIR, st.preserialize(data)); | 533 dm.list_store(node, host, ARCHIVE_DIR, st.preserialize(data)); |
| 524 else | 534 else |
