Mercurial > prosody-modules
annotate mod_archive/mod_archive.lua @ 226:7fe326037070
mod_archive: exit for loop as soon as possible.
author | shinysky<shinysky1986(AT)gmail.com> |
---|---|
date | Thu, 29 Jul 2010 17:05:23 +0800 |
parents | 95d4d53f09a1 |
children | 56103bdb068c |
rev | line source |
---|---|
157
86c28405c5da
initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff
changeset
|
1 -- Prosody IM |
159
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
2 -- Copyright (C) 2010 Dai Zhiwei |
157
86c28405c5da
initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff
changeset
|
3 -- |
86c28405c5da
initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff
changeset
|
4 -- This project is MIT/X11 licensed. Please see the |
86c28405c5da
initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff
changeset
|
5 -- COPYING file in the source package for more information. |
86c28405c5da
initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff
changeset
|
6 -- |
86c28405c5da
initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff
changeset
|
7 |
86c28405c5da
initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff
changeset
|
8 local st = require "util.stanza"; |
165
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
9 local dm = require "util.datamanager"; |
178
62f47a93b5b7
mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents:
172
diff
changeset
|
10 local jid = require "util.jid"; |
193
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
11 local datetime = require "util.datetime"; |
165
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
12 |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
13 local PREFS_DIR = "archive_prefs"; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
14 local ARCHIVE_DIR = "archive"; |
198
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
15 local xmlns_rsm = "http://jabber.org/protocol/rsm"; |
210
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
16 local DEFAULT_MAX = 100; |
157
86c28405c5da
initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff
changeset
|
17 |
221
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
18 local FORCE_ARCHIVING = false; |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
19 local AUTO_ARCHIVING_ENABLED = true; |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
20 |
222
6e6a08b0531a
mod_archive: minor fix.
shinysky<shinysky1986(AT)gmail.com>
parents:
221
diff
changeset
|
21 local HOST = 'localhost'; |
6e6a08b0531a
mod_archive: minor fix.
shinysky<shinysky1986(AT)gmail.com>
parents:
221
diff
changeset
|
22 |
157
86c28405c5da
initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff
changeset
|
23 module:add_feature("urn:xmpp:archive"); |
159
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
24 module:add_feature("urn:xmpp:archive:auto"); |
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
25 module:add_feature("urn:xmpp:archive:manage"); |
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
26 module:add_feature("urn:xmpp:archive:manual"); |
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
27 module:add_feature("urn:xmpp:archive:pref"); |
195
4d9ed6374a1f
mod_archive: XEP-0059: Result Set Management - Limiting the Number of Items; Paging Forwards Through a Result Set; Getting the Item Count
shinysky<shinysky1986(AT)gmail.com>
parents:
193
diff
changeset
|
28 module:add_feature("http://jabber.org/protocol/rsm"); |
157
86c28405c5da
initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff
changeset
|
29 |
165
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
30 ------------------------------------------------------------ |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
31 -- Utils |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
32 ------------------------------------------------------------ |
182
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
33 local function load_prefs(node, host) |
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
34 return st.deserialize(dm.load(node, host, PREFS_DIR)); |
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
35 end |
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
36 |
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
37 local function store_prefs(data, node, host) |
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
38 dm.store(node, host, PREFS_DIR, st.preserialize(data)); |
165
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
39 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
40 |
225
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
41 local function os_date() |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
42 return os.date("!*t"); |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
43 end |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
44 |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
45 local function date_time(t) |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
46 return datetime.datetime(t); |
193
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
47 end |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
48 |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
49 local function date_parse(s) |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
50 local year, month, day, hour, min, sec = s:match("(....)-?(..)-?(..)T(..):(..):(..)Z"); |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
51 return os.time({year=year, month=month, day=day, hour=hour, min=min, sec=sec}); |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
52 end |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
53 |
225
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
54 -- local function list_push(node, host, collection) |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
55 -- local data = dm.list_load(node, host, ARCHIVE_DIR); |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
56 -- if data then |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
57 -- table.insert(data, collection, 1); |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
58 -- dm.list_store(node, host, ARCHIVE_DIR, st.preserialize(data)); |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
59 -- else |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
60 -- dm.list_append(node, host, ARCHIVE_DIR, st.preserialize(collection)); |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
61 -- end |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
62 -- end |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
63 |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
64 local function list_insert(node, host, collection) |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
65 local data = dm.list_load(node, host, ARCHIVE_DIR); |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
66 if data then |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
67 local s, e = 1, #data; |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
68 while true do |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
69 local c = st.deserialize(data[s]); |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
70 if collection.attr["start"] >= c.attr["start"] then |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
71 table.insert(data, collection, s); |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
72 break; |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
73 end |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
74 c = st.deserialize(data[e]); |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
75 if collection.attr["start"] <= c.attr["start"] then |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
76 table.insert(data, collection, e+1); |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
77 break; |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
78 end |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
79 local m = math.floor((s + e) / 2); |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
80 c = st.deserialize(data[m]); |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
81 if collection.attr["start"] > c.attr["start"] then |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
82 e = m - 1; |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
83 elseif collection.attr["start"] < c.attr["start"] then |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
84 s = m + 1; |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
85 else |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
86 table.insert(data, collection, m); |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
87 break; |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
88 end |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
89 end |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
90 dm.list_store(node, host, ARCHIVE_DIR, st.preserialize(data)); |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
91 else |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
92 dm.list_append(node, host, ARCHIVE_DIR, st.preserialize(collection)); |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
93 end |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
94 end |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
95 |
182
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
96 local function store_msg(msg, node, host, isfrom) |
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
97 local body = msg:child_with_name("body"); |
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
98 local thread = msg:child_with_name("thread"); |
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
99 local data = dm.list_load(node, host, ARCHIVE_DIR); |
225
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
100 local tag = isfrom and "from" or "to"; |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
101 local with = isfrom and msg.attr.to or msg.attr.from; |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
102 local utc = os_date(); |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
103 local utc_secs = os.time(utc); |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
104 local utc_datetime = date_time(utc); |
182
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
105 if data then |
225
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
106 -- TODO assuming the collection list are in REVERSE chronological order |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
107 for k, v in ipairs(data) do |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
108 local collection = st.deserialize(v); |
226
7fe326037070
mod_archive: exit for loop as soon as possible.
shinysky<shinysky1986(AT)gmail.com>
parents:
225
diff
changeset
|
109 local do_save = function() |
225
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
110 local dt = 1; |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
111 for i = #collection, 1, -1 do |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
112 local s = collection[i].attr["utc_secs"]; |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
113 if s then |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
114 dt = os.difftime(utc_secs, tonumber(s)); |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
115 break; |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
116 end |
223
de71a52fc63a
mod_archive: Mapping an message to some collection based on timestamp
shinysky<shinysky1986(AT)gmail.com>
parents:
222
diff
changeset
|
117 end |
225
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
118 collection:tag(tag, {secs=dt, utc_secs=utc_secs}):add_child(body); |
182
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
119 local ver = tonumber(collection.attr["version"]) + 1; |
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
120 collection.attr["version"] = tostring(ver); |
225
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
121 collection.attr["access"] = utc_datetime; |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
122 data[k] = collection; |
182
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
123 dm.list_store(node, host, ARCHIVE_DIR, st.preserialize(data)); |
226
7fe326037070
mod_archive: exit for loop as soon as possible.
shinysky<shinysky1986(AT)gmail.com>
parents:
225
diff
changeset
|
124 end |
7fe326037070
mod_archive: exit for loop as soon as possible.
shinysky<shinysky1986(AT)gmail.com>
parents:
225
diff
changeset
|
125 if thread then |
7fe326037070
mod_archive: exit for loop as soon as possible.
shinysky<shinysky1986(AT)gmail.com>
parents:
225
diff
changeset
|
126 if collection.attr["thread"] == thread:get_text() then |
7fe326037070
mod_archive: exit for loop as soon as possible.
shinysky<shinysky1986(AT)gmail.com>
parents:
225
diff
changeset
|
127 do_save(); |
7fe326037070
mod_archive: exit for loop as soon as possible.
shinysky<shinysky1986(AT)gmail.com>
parents:
225
diff
changeset
|
128 return; |
7fe326037070
mod_archive: exit for loop as soon as possible.
shinysky<shinysky1986(AT)gmail.com>
parents:
225
diff
changeset
|
129 end |
7fe326037070
mod_archive: exit for loop as soon as possible.
shinysky<shinysky1986(AT)gmail.com>
parents:
225
diff
changeset
|
130 else |
7fe326037070
mod_archive: exit for loop as soon as possible.
shinysky<shinysky1986(AT)gmail.com>
parents:
225
diff
changeset
|
131 local dt = os.difftime(utc_secs, date_parse(collection.attr["start"])); |
7fe326037070
mod_archive: exit for loop as soon as possible.
shinysky<shinysky1986(AT)gmail.com>
parents:
225
diff
changeset
|
132 if dt >= 14400 then break end |
7fe326037070
mod_archive: exit for loop as soon as possible.
shinysky<shinysky1986(AT)gmail.com>
parents:
225
diff
changeset
|
133 if collection.attr["with"] == with then |
7fe326037070
mod_archive: exit for loop as soon as possible.
shinysky<shinysky1986(AT)gmail.com>
parents:
225
diff
changeset
|
134 do_save(); |
7fe326037070
mod_archive: exit for loop as soon as possible.
shinysky<shinysky1986(AT)gmail.com>
parents:
225
diff
changeset
|
135 return; |
7fe326037070
mod_archive: exit for loop as soon as possible.
shinysky<shinysky1986(AT)gmail.com>
parents:
225
diff
changeset
|
136 end |
182
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
137 end |
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
138 end |
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
139 end |
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
140 -- not found, create new collection |
225
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
141 local collection = st.stanza('chat', {with=with, start=utc_datetime, thread=thread and thread:get_text() or nil, version='0', access=utc_datetime}); |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
142 collection:tag(tag, {secs='0', utc_secs=utc_secs}):add_child(body); |
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
143 list_insert(node, host, collection); |
178
62f47a93b5b7
mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents:
172
diff
changeset
|
144 end |
62f47a93b5b7
mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents:
172
diff
changeset
|
145 |
187
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
146 local function save_result(collection) |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
147 local save = st.stanza('save', {xmlns='urn:xmpp:archive'}); |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
148 local chat = st.stanza('chat', collection.attr); |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
149 save:add_child(chat); |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
150 return save; |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
151 end |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
152 |
195
4d9ed6374a1f
mod_archive: XEP-0059: Result Set Management - Limiting the Number of Items; Paging Forwards Through a Result Set; Getting the Item Count
shinysky<shinysky1986(AT)gmail.com>
parents:
193
diff
changeset
|
153 local function gen_uid(c) |
4d9ed6374a1f
mod_archive: XEP-0059: Result Set Management - Limiting the Number of Items; Paging Forwards Through a Result Set; Getting the Item Count
shinysky<shinysky1986(AT)gmail.com>
parents:
193
diff
changeset
|
154 return c.attr["start"] .. c.attr["with"]; |
4d9ed6374a1f
mod_archive: XEP-0059: Result Set Management - Limiting the Number of Items; Paging Forwards Through a Result Set; Getting the Item Count
shinysky<shinysky1986(AT)gmail.com>
parents:
193
diff
changeset
|
155 end |
4d9ed6374a1f
mod_archive: XEP-0059: Result Set Management - Limiting the Number of Items; Paging Forwards Through a Result Set; Getting the Item Count
shinysky<shinysky1986(AT)gmail.com>
parents:
193
diff
changeset
|
156 |
221
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
157 local function tobool(s) |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
158 if not s then return nil; end |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
159 s = s:lower(); |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
160 if s == 'true' or s == '1' then |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
161 return true; |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
162 elseif s == 'false' or s == '0' then |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
163 return false; |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
164 else |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
165 return nil; |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
166 end |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
167 end |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
168 |
165
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
169 ------------------------------------------------------------ |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
170 -- Preferences |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
171 ------------------------------------------------------------ |
157
86c28405c5da
initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff
changeset
|
172 local function preferences_handler(event) |
165
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
173 local origin, stanza = event.origin, event.stanza; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
174 module:log("debug", "-- Enter preferences_handler()"); |
159
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
175 module:log("debug", "-- pref:\n%s", tostring(stanza)); |
165
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
176 if stanza.attr.type == "get" then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
177 local data = load_prefs(origin.username, origin.host); |
159
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
178 if data then |
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
179 origin.send(st.reply(stanza):add_child(data)); |
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
180 else |
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
181 local reply = st.reply(stanza):tag('pref', {xmlns='urn:xmpp:archive'}); |
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
182 reply:tag('default', {otr='concede', save='false', unset='true'}):up(); |
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
183 reply:tag('method', {type='auto', use='concede'}):up(); |
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
184 reply:tag('method', {type='local', use='concede'}):up(); |
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
185 reply:tag('method', {type='manual', use='concede'}):up(); |
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
186 reply:tag('auto', {save='false'}):up(); |
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
187 origin.send(reply); |
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
188 end |
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
189 elseif stanza.attr.type == "set" then |
165
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
190 local node, host = origin.username, origin.host; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
191 local data = load_prefs(node, host); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
192 if not data then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
193 data = st.stanza('pref', {xmlns='urn:xmpp:archive'}); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
194 data:tag('default', {otr='concede', save='false'}):up(); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
195 data:tag('method', {type='auto', use='concede'}):up(); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
196 data:tag('method', {type='local', use='concede'}):up(); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
197 data:tag('method', {type='manual', use='concede'}):up(); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
198 data:tag('auto', {save='false'}):up(); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
199 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
200 local elem = stanza.tags[1].tags[1]; -- iq:pref:xxx |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
201 if not elem then return false end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
202 -- "default" | "item" | "session" | "method" |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
203 elem.attr["xmlns"] = nil; -- TODO why there is an extra xmlns attr? |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
204 if elem.name == "default" then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
205 local setting = data:child_with_name(elem.name) |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
206 for k, v in pairs(elem.attr) do |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
207 setting.attr[k] = v; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
208 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
209 -- setting.attr["unset"] = nil |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
210 elseif elem.name == "item" then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
211 local found = false; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
212 for child in data:children() do |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
213 if child.name == elem.name and child.attr["jid"] == elem.attr["jid"] then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
214 for k, v in pairs(elem.attr) do |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
215 child.attr[k] = v; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
216 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
217 found = true; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
218 break; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
219 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
220 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
221 if not found then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
222 data:tag(elem.name, elem.attr):up(); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
223 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
224 elseif elem.name == "session" then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
225 local found = false; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
226 for child in data:children() do |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
227 if child.name == elem.name and child.attr["thread"] == elem.attr["thread"] then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
228 for k, v in pairs(elem.attr) do |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
229 child.attr[k] = v; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
230 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
231 found = true; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
232 break; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
233 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
234 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
235 if not found then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
236 data:tag(elem.name, elem.attr):up(); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
237 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
238 elseif elem.name == "method" then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
239 local newpref = stanza.tags[1]; -- iq:pref |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
240 for _, e in ipairs(newpref.tags) do |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
241 -- if e.name ~= "method" then continue end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
242 local found = false; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
243 for child in data:children() do |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
244 if child.name == "method" and child.attr["type"] == e.attr["type"] then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
245 child.attr["use"] = e.attr["use"]; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
246 found = true; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
247 break; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
248 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
249 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
250 if not found then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
251 data:tag(e.name, e.attr):up(); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
252 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
253 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
254 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
255 store_prefs(data, node, host); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
256 origin.send(st.reply(stanza)); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
257 local user = bare_sessions[node.."@"..host]; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
258 local push = st.iq({type="set"}); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
259 push = push:tag('pref', {xmlns='urn:xmpp:archive'}); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
260 if elem.name == "method" then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
261 for child in data:children() do |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
262 if child.name == "method" then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
263 push:add_child(child); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
264 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
265 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
266 else |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
267 push:add_child(elem); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
268 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
269 push = push:up(); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
270 for _, res in pairs(user and user.sessions or NULL) do -- broadcast to all resources |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
271 if res.presence then -- to resource |
172
ac826882a8cf
mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents:
165
diff
changeset
|
272 push.attr.to = res.full_jid; |
165
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
273 res.send(push); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
274 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
275 end |
159
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
276 end |
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
277 return true; |
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
278 end |
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
279 |
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
280 local function itemremove_handler(event) |
193
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
281 -- TODO use 'assert' to check incoming stanza? |
187
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
282 -- or use pcall() to catch exceptions? |
165
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
283 local origin, stanza = event.origin, event.stanza; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
284 if stanza.attr.type ~= "set" then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
285 return false; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
286 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
287 local elem = stanza.tags[1].tags[1]; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
288 if not elem or elem.name ~= "item" then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
289 return false; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
290 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
291 local node, host = origin.username, origin.host; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
292 local data = load_prefs(node, host); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
293 if not data then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
294 return false; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
295 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
296 for i, child in ipairs(data) do |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
297 if child.name == "item" and child.attr["jid"] == elem.attr["jid"] then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
298 table.remove(data, i) |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
299 break; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
300 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
301 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
302 store_prefs(data, node, host); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
303 origin.send(st.reply(stanza)); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
304 return true; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
305 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
306 |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
307 local function sessionremove_handler(event) |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
308 local origin, stanza = event.origin, event.stanza; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
309 if stanza.attr.type ~= "set" then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
310 return false; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
311 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
312 local elem = stanza.tags[1].tags[1]; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
313 if not elem or elem.name ~= "session" then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
314 return false; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
315 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
316 local node, host = origin.username, origin.host; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
317 local data = load_prefs(node, host); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
318 if not data then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
319 return false; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
320 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
321 for i, child in ipairs(data) do |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
322 if child.name == "session" and child.attr["thread"] == elem.attr["thread"] then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
323 table.remove(data, i) |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
324 break; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
325 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
326 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
327 store_prefs(data, node, host); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
328 origin.send(st.reply(stanza)); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
329 return true; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
330 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
331 |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
332 local function auto_handler(event) |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
333 -- event.origin.send(st.error_reply(event.stanza, "cancel", "feature-not-implemented")); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
334 local origin, stanza = event.origin, event.stanza; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
335 if stanza.attr.type ~= "set" then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
336 return false; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
337 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
338 local elem = stanza.tags[1]; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
339 local node, host = origin.username, origin.host; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
340 local data = load_prefs(node, host); |
226
7fe326037070
mod_archive: exit for loop as soon as possible.
shinysky<shinysky1986(AT)gmail.com>
parents:
225
diff
changeset
|
341 if not data then -- TODO create new pref? |
165
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
342 return false; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
343 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
344 local setting = data:child_with_name(elem.name) |
172
ac826882a8cf
mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents:
165
diff
changeset
|
345 for k, v in pairs(elem.attr) do |
ac826882a8cf
mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents:
165
diff
changeset
|
346 setting.attr[k] = v; |
ac826882a8cf
mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents:
165
diff
changeset
|
347 end |
165
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
348 store_prefs(data, node, host); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
349 origin.send(st.reply(stanza)); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
350 return true; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
351 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
352 |
193
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
353 ------------------------------------------------------------ |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
354 -- Manual Archiving |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
355 ------------------------------------------------------------ |
159
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
356 local function save_handler(event) |
187
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
357 local origin, stanza = event.origin, event.stanza; |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
358 if stanza.attr.type ~= "set" then |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
359 return false; |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
360 end |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
361 local elem = stanza.tags[1].tags[1]; |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
362 if not elem or elem.name ~= "chat" then |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
363 return false; |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
364 end |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
365 local node, host = origin.username, origin.host; |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
366 local data = dm.list_load(node, host, ARCHIVE_DIR); |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
367 if data then |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
368 for k, v in ipairs(data) do |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
369 local collection = st.deserialize(v); |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
370 if collection.attr["with"] == elem.attr["with"] |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
371 and collection.attr["start"] == elem.attr["start"] then |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
372 -- TODO check if there're duplicates |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
373 for newchild in elem:children() do |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
374 if type(newchild) == "table" then |
188
5e8ea3733dc6
mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents:
187
diff
changeset
|
375 if newchild.name == "from" or newchild.name == "to" then |
5e8ea3733dc6
mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents:
187
diff
changeset
|
376 collection:add_child(newchild); |
193
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
377 elseif newchild.name == "note" or newchild.name == "previous" |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
378 or newchild.name == "next" or newchild.name == "x" then |
188
5e8ea3733dc6
mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents:
187
diff
changeset
|
379 local found = false; |
5e8ea3733dc6
mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents:
187
diff
changeset
|
380 for i, c in ipairs(collection) do |
5e8ea3733dc6
mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents:
187
diff
changeset
|
381 if c.name == newchild.name then |
5e8ea3733dc6
mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents:
187
diff
changeset
|
382 found = true; |
5e8ea3733dc6
mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents:
187
diff
changeset
|
383 collection[i] = newchild; |
5e8ea3733dc6
mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents:
187
diff
changeset
|
384 break; |
5e8ea3733dc6
mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents:
187
diff
changeset
|
385 end |
5e8ea3733dc6
mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents:
187
diff
changeset
|
386 end |
5e8ea3733dc6
mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents:
187
diff
changeset
|
387 if not found then |
5e8ea3733dc6
mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents:
187
diff
changeset
|
388 collection:add_child(newchild); |
5e8ea3733dc6
mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents:
187
diff
changeset
|
389 end |
5e8ea3733dc6
mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents:
187
diff
changeset
|
390 end |
187
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
391 end |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
392 end |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
393 local ver = tonumber(collection.attr["version"]) + 1; |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
394 collection.attr["version"] = tostring(ver); |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
395 collection.attr["subject"] = elem.attr["subject"]; |
225
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
396 collection.attr["access"] = date_time(); |
187
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
397 origin.send(st.reply(stanza):add_child(save_result(collection))); |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
398 data[k] = collection; |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
399 dm.list_store(node, host, ARCHIVE_DIR, st.preserialize(data)); |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
400 return true; |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
401 end |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
402 end |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
403 end |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
404 -- not found, create new collection |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
405 elem.attr["version"] = "0"; |
225
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
406 elem.attr["access"] = date_time(); |
187
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
407 origin.send(st.reply(stanza):add_child(save_result(elem))); |
188
5e8ea3733dc6
mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents:
187
diff
changeset
|
408 -- TODO check if elem is valid(?) |
225
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
409 list_insert(node, host, elem); |
187
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
410 -- TODO unsuccessful reply |
157
86c28405c5da
initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff
changeset
|
411 return true; |
86c28405c5da
initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff
changeset
|
412 end |
86c28405c5da
initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff
changeset
|
413 |
178
62f47a93b5b7
mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents:
172
diff
changeset
|
414 ------------------------------------------------------------ |
193
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
415 -- Archive Management |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
416 ------------------------------------------------------------ |
223
de71a52fc63a
mod_archive: Mapping an message to some collection based on timestamp
shinysky<shinysky1986(AT)gmail.com>
parents:
222
diff
changeset
|
417 local function filter_jid(rule, jid) |
de71a52fc63a
mod_archive: Mapping an message to some collection based on timestamp
shinysky<shinysky1986(AT)gmail.com>
parents:
222
diff
changeset
|
418 return not rule or jid.compare(jid, rule); |
193
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
419 end |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
420 |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
421 local function filter_start(start, coll_start) |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
422 return not start or start <= coll_start; |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
423 end |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
424 |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
425 local function filter_end(endtime, coll_start) |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
426 return not endtime or endtime >= coll_start; |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
427 end |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
428 |
196
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
429 local function find_coll(resset, uid) |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
430 for i, c in ipairs(resset) do |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
431 if gen_uid(c) == uid then |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
432 return i; |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
433 end |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
434 end |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
435 return nil; |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
436 end |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
437 |
193
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
438 local function list_handler(event) |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
439 local origin, stanza = event.origin, event.stanza; |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
440 local node, host = origin.username, origin.host; |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
441 local data = dm.list_load(node, host, ARCHIVE_DIR); |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
442 local elem = stanza.tags[1]; |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
443 local resset = {} |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
444 if data then |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
445 for k, v in ipairs(data) do |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
446 local collection = st.deserialize(v); |
209
254c13e049f7
mod_archive: added a 'access' attribute to the chat element, representing the time last accessed.
shinysky<shinysky1986(AT)gmail.com>
parents:
199
diff
changeset
|
447 if collection[1] then -- has children(not deleted) |
223
de71a52fc63a
mod_archive: Mapping an message to some collection based on timestamp
shinysky<shinysky1986(AT)gmail.com>
parents:
222
diff
changeset
|
448 local res = filter_jid(elem.attr["with"], collection.attr["with"]); |
209
254c13e049f7
mod_archive: added a 'access' attribute to the chat element, representing the time last accessed.
shinysky<shinysky1986(AT)gmail.com>
parents:
199
diff
changeset
|
449 res = res and filter_start(elem.attr["start"], collection.attr["start"]); |
254c13e049f7
mod_archive: added a 'access' attribute to the chat element, representing the time last accessed.
shinysky<shinysky1986(AT)gmail.com>
parents:
199
diff
changeset
|
450 res = res and filter_end(elem.attr["end"], collection.attr["start"]); |
254c13e049f7
mod_archive: added a 'access' attribute to the chat element, representing the time last accessed.
shinysky<shinysky1986(AT)gmail.com>
parents:
199
diff
changeset
|
451 if res then |
254c13e049f7
mod_archive: added a 'access' attribute to the chat element, representing the time last accessed.
shinysky<shinysky1986(AT)gmail.com>
parents:
199
diff
changeset
|
452 table.insert(resset, collection); |
254c13e049f7
mod_archive: added a 'access' attribute to the chat element, representing the time last accessed.
shinysky<shinysky1986(AT)gmail.com>
parents:
199
diff
changeset
|
453 end |
193
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
454 end |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
455 end |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
456 end |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
457 local reply = st.reply(stanza):tag('list', {xmlns='urn:xmpp:archive'}); |
196
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
458 local count = table.getn(resset); |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
459 if count > 0 then |
195
4d9ed6374a1f
mod_archive: XEP-0059: Result Set Management - Limiting the Number of Items; Paging Forwards Through a Result Set; Getting the Item Count
shinysky<shinysky1986(AT)gmail.com>
parents:
193
diff
changeset
|
460 local max = elem.tags[1]:child_with_name("max"); |
4d9ed6374a1f
mod_archive: XEP-0059: Result Set Management - Limiting the Number of Items; Paging Forwards Through a Result Set; Getting the Item Count
shinysky<shinysky1986(AT)gmail.com>
parents:
193
diff
changeset
|
461 if max then |
210
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
462 max = tonumber(max:get_text()) or DEFAULT_MAX; |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
463 else max = DEFAULT_MAX; end |
195
4d9ed6374a1f
mod_archive: XEP-0059: Result Set Management - Limiting the Number of Items; Paging Forwards Through a Result Set; Getting the Item Count
shinysky<shinysky1986(AT)gmail.com>
parents:
193
diff
changeset
|
464 local after = elem.tags[1]:child_with_name("after"); |
196
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
465 local before = elem.tags[1]:child_with_name("before"); |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
466 local index = elem.tags[1]:child_with_name("index"); |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
467 local s, e = 1, 1+max; |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
468 if after then |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
469 after = after:get_text(); |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
470 s = find_coll(resset, after); |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
471 if not s then -- not found |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
472 origin.send(st.error_reply(stanza, "cancel", "item-not-found")); |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
473 return true; |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
474 end |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
475 s = s + 1; |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
476 e = s + max; |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
477 elseif before then |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
478 before = before:get_text(); |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
479 if not before or before == '' then -- the last page |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
480 e = count + 1; |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
481 s = e - max; |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
482 else |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
483 e = find_coll(resset, before); |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
484 if not e then -- not found |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
485 origin.send(st.error_reply(stanza, "cancel", "item-not-found")); |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
486 return true; |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
487 end |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
488 s = e - max; |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
489 end |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
490 elseif index then |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
491 s = tonumber(index:get_text()) + 1; -- 0-based |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
492 e = s + max; |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
493 end |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
494 if s < 1 then s = 1; end |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
495 if e > count + 1 then e = count + 1; end |
193
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
496 -- Assuming result set is sorted. |
196
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
497 for i = s, e-1 do |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
498 reply:add_child(st.stanza('chat', resset[i].attr)); |
193
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
499 end |
198
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
500 local set = st.stanza('set', {xmlns = xmlns_rsm}); |
196
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
501 if s <= e-1 then |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
502 set:tag('first', {index=s-1}):text(gen_uid(resset[s])):up() |
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
503 :tag('last'):text(gen_uid(resset[e-1])):up(); |
195
4d9ed6374a1f
mod_archive: XEP-0059: Result Set Management - Limiting the Number of Items; Paging Forwards Through a Result Set; Getting the Item Count
shinysky<shinysky1986(AT)gmail.com>
parents:
193
diff
changeset
|
504 end |
196
a1c2677257da
mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
195
diff
changeset
|
505 set:tag('count'):text(tostring(count)):up(); |
195
4d9ed6374a1f
mod_archive: XEP-0059: Result Set Management - Limiting the Number of Items; Paging Forwards Through a Result Set; Getting the Item Count
shinysky<shinysky1986(AT)gmail.com>
parents:
193
diff
changeset
|
506 reply:add_child(set); |
193
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
507 end |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
508 origin.send(reply); |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
509 return true; |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
510 end |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
511 |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
512 local function retrieve_handler(event) |
198
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
513 local origin, stanza = event.origin, event.stanza; |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
514 local node, host = origin.username, origin.host; |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
515 local data = dm.list_load(node, host, ARCHIVE_DIR); |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
516 local elem = stanza.tags[1]; |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
517 local collection = nil; |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
518 if data then |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
519 for k, v in ipairs(data) do |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
520 local c = st.deserialize(v); |
209
254c13e049f7
mod_archive: added a 'access' attribute to the chat element, representing the time last accessed.
shinysky<shinysky1986(AT)gmail.com>
parents:
199
diff
changeset
|
521 if c[1] -- not deleted |
254c13e049f7
mod_archive: added a 'access' attribute to the chat element, representing the time last accessed.
shinysky<shinysky1986(AT)gmail.com>
parents:
199
diff
changeset
|
522 and c.attr["with"] == elem.attr["with"] |
198
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
523 and c.attr["start"] == elem.attr["start"] then |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
524 collection = c; |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
525 break; |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
526 end |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
527 end |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
528 end |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
529 if not collection then |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
530 -- TODO code=404 |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
531 origin.send(st.error_reply(stanza, "cancel", "item-not-found")); |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
532 return true; |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
533 end |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
534 local resset = {} |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
535 for i, e in ipairs(collection) do |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
536 if e.name == "from" or e.name == "to" then |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
537 table.insert(resset, e); |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
538 end |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
539 end |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
540 collection.attr['xmlns'] = 'urn:xmpp:archive'; |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
541 local reply = st.reply(stanza):tag('chat', collection.attr); |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
542 local count = table.getn(resset); |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
543 if count > 0 then |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
544 local max = elem.tags[1]:child_with_name("max"); |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
545 if max then |
210
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
546 max = tonumber(max:get_text()) or DEFAULT_MAX; |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
547 else max = DEFAULT_MAX; end |
198
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
548 local after = elem.tags[1]:child_with_name("after"); |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
549 local before = elem.tags[1]:child_with_name("before"); |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
550 local index = elem.tags[1]:child_with_name("index"); |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
551 local s, e = 1, 1+max; |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
552 if after then |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
553 after = tonumber(after:get_text()); |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
554 if not after or after < 1 or after > count then -- not found |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
555 origin.send(st.error_reply(stanza, "cancel", "item-not-found")); |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
556 return true; |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
557 end |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
558 s = after + 1; |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
559 e = s + max; |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
560 elseif before then |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
561 before = tonumber(before:get_text()); |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
562 if not before then -- the last page |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
563 e = count + 1; |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
564 s = e - max; |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
565 elseif before < 1 or before > count then |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
566 origin.send(st.error_reply(stanza, "cancel", "item-not-found")); |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
567 return true; |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
568 else |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
569 e = before; |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
570 s = e - max; |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
571 end |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
572 elseif index then |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
573 s = tonumber(index:get_text()) + 1; -- 0-based |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
574 e = s + max; |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
575 end |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
576 if s < 1 then s = 1; end |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
577 if e > count + 1 then e = count + 1; end |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
578 -- Assuming result set is sorted. |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
579 for i = s, e-1 do |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
580 reply:add_child(resset[i]); |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
581 end |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
582 local set = st.stanza('set', {xmlns = xmlns_rsm}); |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
583 if s <= e-1 then |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
584 set:tag('first', {index=s-1}):text(tostring(s)):up() |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
585 :tag('last'):text(tostring(e-1)):up(); |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
586 end |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
587 set:tag('count'):text(tostring(count)):up(); |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
588 reply:add_child(set); |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
589 end |
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
590 origin.send(reply); |
193
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
591 return true; |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
592 end |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
593 |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
594 local function remove_handler(event) |
199
27b8a7482149
mod_archive: '7.3 Removing a Collection' is DONE, so '7. Archive Management' is DONE.
shinysky<shinysky1986(AT)gmail.com>
parents:
198
diff
changeset
|
595 local origin, stanza = event.origin, event.stanza; |
27b8a7482149
mod_archive: '7.3 Removing a Collection' is DONE, so '7. Archive Management' is DONE.
shinysky<shinysky1986(AT)gmail.com>
parents:
198
diff
changeset
|
596 local node, host = origin.username, origin.host; |
27b8a7482149
mod_archive: '7.3 Removing a Collection' is DONE, so '7. Archive Management' is DONE.
shinysky<shinysky1986(AT)gmail.com>
parents:
198
diff
changeset
|
597 local data = dm.list_load(node, host, ARCHIVE_DIR); |
27b8a7482149
mod_archive: '7.3 Removing a Collection' is DONE, so '7. Archive Management' is DONE.
shinysky<shinysky1986(AT)gmail.com>
parents:
198
diff
changeset
|
598 local elem = stanza.tags[1]; |
27b8a7482149
mod_archive: '7.3 Removing a Collection' is DONE, so '7. Archive Management' is DONE.
shinysky<shinysky1986(AT)gmail.com>
parents:
198
diff
changeset
|
599 if data then |
27b8a7482149
mod_archive: '7.3 Removing a Collection' is DONE, so '7. Archive Management' is DONE.
shinysky<shinysky1986(AT)gmail.com>
parents:
198
diff
changeset
|
600 local count = table.getn(data); |
27b8a7482149
mod_archive: '7.3 Removing a Collection' is DONE, so '7. Archive Management' is DONE.
shinysky<shinysky1986(AT)gmail.com>
parents:
198
diff
changeset
|
601 local found = false; |
27b8a7482149
mod_archive: '7.3 Removing a Collection' is DONE, so '7. Archive Management' is DONE.
shinysky<shinysky1986(AT)gmail.com>
parents:
198
diff
changeset
|
602 for i = count, 1, -1 do |
27b8a7482149
mod_archive: '7.3 Removing a Collection' is DONE, so '7. Archive Management' is DONE.
shinysky<shinysky1986(AT)gmail.com>
parents:
198
diff
changeset
|
603 local collection = st.deserialize(data[i]); |
209
254c13e049f7
mod_archive: added a 'access' attribute to the chat element, representing the time last accessed.
shinysky<shinysky1986(AT)gmail.com>
parents:
199
diff
changeset
|
604 if collection[1] then -- has children(not deleted) |
223
de71a52fc63a
mod_archive: Mapping an message to some collection based on timestamp
shinysky<shinysky1986(AT)gmail.com>
parents:
222
diff
changeset
|
605 local res = filter_jid(elem.attr["with"], collection.attr["with"]); |
209
254c13e049f7
mod_archive: added a 'access' attribute to the chat element, representing the time last accessed.
shinysky<shinysky1986(AT)gmail.com>
parents:
199
diff
changeset
|
606 res = res and filter_start(elem.attr["start"], collection.attr["start"]); |
254c13e049f7
mod_archive: added a 'access' attribute to the chat element, representing the time last accessed.
shinysky<shinysky1986(AT)gmail.com>
parents:
199
diff
changeset
|
607 res = res and filter_end(elem.attr["end"], collection.attr["start"]); |
254c13e049f7
mod_archive: added a 'access' attribute to the chat element, representing the time last accessed.
shinysky<shinysky1986(AT)gmail.com>
parents:
199
diff
changeset
|
608 if res then |
254c13e049f7
mod_archive: added a 'access' attribute to the chat element, representing the time last accessed.
shinysky<shinysky1986(AT)gmail.com>
parents:
199
diff
changeset
|
609 -- table.remove(data, i); |
254c13e049f7
mod_archive: added a 'access' attribute to the chat element, representing the time last accessed.
shinysky<shinysky1986(AT)gmail.com>
parents:
199
diff
changeset
|
610 local temp = st.stanza('chat', collection.attr); |
225
95d4d53f09a1
mod_archive: keep collections in REVERSE chronological order(not tested).
shinysky<shinysky1986(AT)gmail.com>
parents:
224
diff
changeset
|
611 temp.attr["access"] = date_time(); |
209
254c13e049f7
mod_archive: added a 'access' attribute to the chat element, representing the time last accessed.
shinysky<shinysky1986(AT)gmail.com>
parents:
199
diff
changeset
|
612 data[i] = temp; |
254c13e049f7
mod_archive: added a 'access' attribute to the chat element, representing the time last accessed.
shinysky<shinysky1986(AT)gmail.com>
parents:
199
diff
changeset
|
613 found = true; |
254c13e049f7
mod_archive: added a 'access' attribute to the chat element, representing the time last accessed.
shinysky<shinysky1986(AT)gmail.com>
parents:
199
diff
changeset
|
614 end |
199
27b8a7482149
mod_archive: '7.3 Removing a Collection' is DONE, so '7. Archive Management' is DONE.
shinysky<shinysky1986(AT)gmail.com>
parents:
198
diff
changeset
|
615 end |
27b8a7482149
mod_archive: '7.3 Removing a Collection' is DONE, so '7. Archive Management' is DONE.
shinysky<shinysky1986(AT)gmail.com>
parents:
198
diff
changeset
|
616 end |
27b8a7482149
mod_archive: '7.3 Removing a Collection' is DONE, so '7. Archive Management' is DONE.
shinysky<shinysky1986(AT)gmail.com>
parents:
198
diff
changeset
|
617 if found then |
27b8a7482149
mod_archive: '7.3 Removing a Collection' is DONE, so '7. Archive Management' is DONE.
shinysky<shinysky1986(AT)gmail.com>
parents:
198
diff
changeset
|
618 dm.list_store(node, host, ARCHIVE_DIR, st.preserialize(data)); |
27b8a7482149
mod_archive: '7.3 Removing a Collection' is DONE, so '7. Archive Management' is DONE.
shinysky<shinysky1986(AT)gmail.com>
parents:
198
diff
changeset
|
619 else |
27b8a7482149
mod_archive: '7.3 Removing a Collection' is DONE, so '7. Archive Management' is DONE.
shinysky<shinysky1986(AT)gmail.com>
parents:
198
diff
changeset
|
620 origin.send(st.error_reply(stanza, "cancel", "item-not-found")); |
27b8a7482149
mod_archive: '7.3 Removing a Collection' is DONE, so '7. Archive Management' is DONE.
shinysky<shinysky1986(AT)gmail.com>
parents:
198
diff
changeset
|
621 return true; |
27b8a7482149
mod_archive: '7.3 Removing a Collection' is DONE, so '7. Archive Management' is DONE.
shinysky<shinysky1986(AT)gmail.com>
parents:
198
diff
changeset
|
622 end |
27b8a7482149
mod_archive: '7.3 Removing a Collection' is DONE, so '7. Archive Management' is DONE.
shinysky<shinysky1986(AT)gmail.com>
parents:
198
diff
changeset
|
623 end |
27b8a7482149
mod_archive: '7.3 Removing a Collection' is DONE, so '7. Archive Management' is DONE.
shinysky<shinysky1986(AT)gmail.com>
parents:
198
diff
changeset
|
624 origin.send(st.reply(stanza)); |
193
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
625 return true; |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
626 end |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
627 |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
628 ------------------------------------------------------------ |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
629 -- Replication |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
630 ------------------------------------------------------------ |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
631 local function modified_handler(event) |
210
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
632 local origin, stanza = event.origin, event.stanza; |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
633 local node, host = origin.username, origin.host; |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
634 local data = dm.list_load(node, host, ARCHIVE_DIR); |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
635 local elem = stanza.tags[1]; |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
636 local resset = {} |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
637 if data then |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
638 for k, v in ipairs(data) do |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
639 local collection = st.deserialize(v); |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
640 local res = filter_start(elem.attr["start"], collection.attr["access"]); |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
641 if res then |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
642 table.insert(resset, collection); |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
643 end |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
644 end |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
645 end |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
646 local reply = st.reply(stanza):tag('modified', {xmlns='urn:xmpp:archive'}); |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
647 local count = table.getn(resset); |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
648 if count > 0 then |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
649 local max = elem.tags[1]:child_with_name("max"); |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
650 if max then |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
651 max = tonumber(max:get_text()) or DEFAULT_MAX; |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
652 else max = DEFAULT_MAX; end |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
653 local after = elem.tags[1]:child_with_name("after"); |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
654 local before = elem.tags[1]:child_with_name("before"); |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
655 local index = elem.tags[1]:child_with_name("index"); |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
656 local s, e = 1, 1+max; |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
657 if after then |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
658 after = after:get_text(); |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
659 s = find_coll(resset, after); |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
660 if not s then -- not found |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
661 origin.send(st.error_reply(stanza, "cancel", "item-not-found")); |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
662 return true; |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
663 end |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
664 s = s + 1; |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
665 e = s + max; |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
666 elseif before then |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
667 before = before:get_text(); |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
668 if not before or before == '' then -- the last page |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
669 e = count + 1; |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
670 s = e - max; |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
671 else |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
672 e = find_coll(resset, before); |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
673 if not e then -- not found |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
674 origin.send(st.error_reply(stanza, "cancel", "item-not-found")); |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
675 return true; |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
676 end |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
677 s = e - max; |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
678 end |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
679 elseif index then |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
680 s = tonumber(index:get_text()) + 1; -- 0-based |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
681 e = s + max; |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
682 end |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
683 if s < 1 then s = 1; end |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
684 if e > count + 1 then e = count + 1; end |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
685 -- Assuming result set is sorted. |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
686 for i = s, e-1 do |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
687 if resset[i][1] then |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
688 reply:add_child(st.stanza('changed', resset[i].attr)); |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
689 else |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
690 reply:add_child(st.stanza('removed', resset[i].attr)); |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
691 end |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
692 end |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
693 local set = st.stanza('set', {xmlns = xmlns_rsm}); |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
694 if s <= e-1 then |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
695 set:tag('first', {index=s-1}):text(gen_uid(resset[s])):up() |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
696 :tag('last'):text(gen_uid(resset[e-1])):up(); |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
697 end |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
698 set:tag('count'):text(tostring(count)):up(); |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
699 reply:add_child(set); |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
700 end |
2d63d50d9713
mod_archive: Replication is done!
shinysky<shinysky1986(AT)gmail.com>
parents:
209
diff
changeset
|
701 origin.send(reply); |
193
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
702 return true; |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
703 end |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
704 |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
705 ------------------------------------------------------------ |
178
62f47a93b5b7
mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents:
172
diff
changeset
|
706 -- Message Handler |
62f47a93b5b7
mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents:
172
diff
changeset
|
707 ------------------------------------------------------------ |
221
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
708 local function find_pref(pref, name, k, v, exactmatch) |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
709 for i, child in ipairs(pref) do |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
710 if child.name == name then |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
711 if k and v then |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
712 if exactmatch and child.attr[k] == v then |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
713 return child; |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
714 elseif not exactmatch then |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
715 if tobool(child.attr['exactmatch']) then |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
716 if child.attr[k] == v then |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
717 return child; |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
718 end |
223
de71a52fc63a
mod_archive: Mapping an message to some collection based on timestamp
shinysky<shinysky1986(AT)gmail.com>
parents:
222
diff
changeset
|
719 elseif filter_jid(child.attr[k], v) then |
221
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
720 return child; |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
721 end |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
722 end |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
723 else |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
724 return child; |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
725 end |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
726 end |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
727 end |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
728 return nil; |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
729 end |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
730 |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
731 local function apply_pref(node, host, jid, thread) |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
732 if FORCE_ARCHIVING then return true; end |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
733 |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
734 local pref = load_prefs(node, host); |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
735 if not pref then |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
736 return AUTO_ARCHIVING_ENABLED; |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
737 end |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
738 local auto = pref:child_with_name('auto'); |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
739 if not tobool(auto.attr['save']) then |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
740 return false; |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
741 end |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
742 if thread then |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
743 local child = find_pref(pref, 'session', 'thread', thread, true); |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
744 if child then |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
745 return tobool(child.attr['save']) ~= false; |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
746 end |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
747 end |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
748 local child = find_pref(pref, 'item', 'jid', jid, false); -- JID Matching |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
749 if child then |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
750 return tobool(child.attr['save']) ~= false; |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
751 end |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
752 local default = pref:child_with_name('default'); |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
753 if default then |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
754 return tobool(default.attr['save']) ~= false; |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
755 end |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
756 return AUTO_ARCHIVING_ENABLED; |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
757 end |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
758 |
172
ac826882a8cf
mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents:
165
diff
changeset
|
759 local function msg_handler(data) |
ac826882a8cf
mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents:
165
diff
changeset
|
760 module:log("debug", "-- Enter msg_handler()"); |
ac826882a8cf
mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents:
165
diff
changeset
|
761 local origin, stanza = data.origin, data.stanza; |
178
62f47a93b5b7
mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents:
172
diff
changeset
|
762 local body = stanza:child_with_name("body"); |
182
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
763 local thread = stanza:child_with_name("thread"); |
178
62f47a93b5b7
mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents:
172
diff
changeset
|
764 if body then |
221
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
765 local from_node, from_host = jid.split(stanza.attr.from); |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
766 local to_node, to_host = jid.split(stanza.attr.to); |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
767 -- FIXME only archive messages of users on this host |
222
6e6a08b0531a
mod_archive: minor fix.
shinysky<shinysky1986(AT)gmail.com>
parents:
221
diff
changeset
|
768 if from_host == HOST and apply_pref(from_node, from_host, stanza.attr.to, thread) then |
221
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
769 store_msg(stanza, from_node, from_host, true); |
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
770 end |
222
6e6a08b0531a
mod_archive: minor fix.
shinysky<shinysky1986(AT)gmail.com>
parents:
221
diff
changeset
|
771 if to_host == HOST and apply_pref(to_node, to_host, stanza.attr.from, thread) then |
221
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
772 store_msg(stanza, to_node, to_host, false); |
178
62f47a93b5b7
mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents:
172
diff
changeset
|
773 end |
62f47a93b5b7
mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents:
172
diff
changeset
|
774 end |
221
1861290055c0
mod_archive: interpret preferences when do auto archiving.
shinysky<shinysky1986(AT)gmail.com>
parents:
210
diff
changeset
|
775 |
172
ac826882a8cf
mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents:
165
diff
changeset
|
776 return nil; |
ac826882a8cf
mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents:
165
diff
changeset
|
777 end |
ac826882a8cf
mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents:
165
diff
changeset
|
778 |
193
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
779 -- Preferences |
157
86c28405c5da
initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff
changeset
|
780 module:hook("iq/self/urn:xmpp:archive:pref", preferences_handler); |
165
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
781 module:hook("iq/self/urn:xmpp:archive:itemremove", itemremove_handler); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
782 module:hook("iq/self/urn:xmpp:archive:sessionremove", sessionremove_handler); |
159
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
783 module:hook("iq/self/urn:xmpp:archive:auto", auto_handler); |
193
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
784 -- Manual archiving |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
785 module:hook("iq/self/urn:xmpp:archive:save", save_handler); |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
786 -- Archive management |
159
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
787 module:hook("iq/self/urn:xmpp:archive:list", list_handler); |
193
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
788 module:hook("iq/self/urn:xmpp:archive:retrieve", retrieve_handler); |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
789 module:hook("iq/self/urn:xmpp:archive:remove", remove_handler); |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
790 -- Replication |
159
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
791 module:hook("iq/self/urn:xmpp:archive:modified", modified_handler); |
157
86c28405c5da
initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff
changeset
|
792 |
172
ac826882a8cf
mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents:
165
diff
changeset
|
793 module:hook("message/full", msg_handler, 10); |
ac826882a8cf
mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents:
165
diff
changeset
|
794 module:hook("message/bare", msg_handler, 10); |
ac826882a8cf
mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents:
165
diff
changeset
|
795 |
193
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
796 -- FIXME sort collections |
198
a3b5810de3e4
mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents:
196
diff
changeset
|
797 -- TODO exactmatch |
199
27b8a7482149
mod_archive: '7.3 Removing a Collection' is DONE, so '7. Archive Management' is DONE.
shinysky<shinysky1986(AT)gmail.com>
parents:
198
diff
changeset
|
798 -- TODO <item/> JID match |
27b8a7482149
mod_archive: '7.3 Removing a Collection' is DONE, so '7. Archive Management' is DONE.
shinysky<shinysky1986(AT)gmail.com>
parents:
198
diff
changeset
|
799 -- TODO 'open attr' in removing a collection |