annotate mod_archive/mod_archive.lua @ 198:a3b5810de3e4

mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
author shinysky<shinysky1986(AT)gmail.com>
date Wed, 07 Jul 2010 22:07:36 +0800
parents a1c2677257da
children 27b8a7482149
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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";
157
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
16
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
17 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
18 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
19 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
20 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
21 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
22 module:add_feature("http://jabber.org/protocol/rsm");
157
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
23
165
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
24 ------------------------------------------------------------
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
25 -- Utils
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
26 ------------------------------------------------------------
182
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
27 local function load_prefs(node, host)
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
28 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
29 end
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
30
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
31 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
32 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
33 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
34
193
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
35 local function os_time()
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
36 -- return tostring(os.time(os.date('!*t')));
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
37 return datetime.datetime();
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
38 end
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
39
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
40 local function date_parse(s)
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
41 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
42 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
43 end
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
44
182
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
45 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
46 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
47 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
48 local data = dm.list_load(node, host, ARCHIVE_DIR);
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
49 local tag = (isfrom and "from") or "to";
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
50 if data then
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
51 for k, v in ipairs(data) do
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
52 local collection = st.deserialize(v);
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
53 if collection.attr["thread"] == thread:get_text() then
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
54 -- TODO figure out secs
193
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
55 collection:tag(tag, {secs='1', utc=os_time()}):add_child(body);
182
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
56 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
57 collection.attr["version"] = tostring(ver);
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
58 data[k] = collection;
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
59 dm.list_store(node, host, ARCHIVE_DIR, st.preserialize(data));
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
60 return;
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
61 end
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
62 end
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
63 end
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
64 -- not found, create new collection
193
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
65 local utc = os_time();
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
66 local collection = st.stanza('chat', {with = isfrom and msg.attr.to or msg.attr.from, start=utc, thread=thread:get_text(), version='0'});
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
67 collection:tag(tag, {secs='0', utc=utc}):add_child(body);
182
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
68 dm.list_append(node, host, ARCHIVE_DIR, st.preserialize(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
69 end
62f47a93b5b7 mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents: 172
diff changeset
70
187
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
71 local function save_result(collection)
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
72 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
73 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
74 save:add_child(chat);
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
75 return save;
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
76 end
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
77
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
78 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
79 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
80 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
81
165
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
82 ------------------------------------------------------------
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
83 -- Preferences
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
84 ------------------------------------------------------------
157
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
85 local function preferences_handler(event)
165
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
86 local origin, stanza = event.origin, event.stanza;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
87 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
88 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
89 if stanza.attr.type == "get" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
90 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
91 if data then
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
92 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
93 else
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
94 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
95 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
96 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
97 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
98 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
99 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
100 origin.send(reply);
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
101 end
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
102 elseif stanza.attr.type == "set" then
165
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
103 local node, host = origin.username, origin.host;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
104 local data = load_prefs(node, host);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
105 if not data then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
106 data = st.stanza('pref', {xmlns='urn:xmpp:archive'});
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
107 data:tag('default', {otr='concede', save='false'}):up();
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
108 data:tag('method', {type='auto', use='concede'}):up();
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
109 data:tag('method', {type='local', use='concede'}):up();
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
110 data:tag('method', {type='manual', use='concede'}):up();
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
111 data:tag('auto', {save='false'}):up();
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
112 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
113 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
114 if not elem then return false end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
115 -- "default" | "item" | "session" | "method"
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
116 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
117 if elem.name == "default" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
118 local setting = data:child_with_name(elem.name)
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
119 for k, v in pairs(elem.attr) do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
120 setting.attr[k] = v;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
121 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
122 -- setting.attr["unset"] = nil
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
123 elseif elem.name == "item" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
124 local found = false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
125 for child in data:children() do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
126 -- TODO bare JID or full JID?
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
127 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
128 for k, v in pairs(elem.attr) do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
129 child.attr[k] = v;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
130 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
131 found = true;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
132 break;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
133 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
134 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
135 if not found then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
136 data:tag(elem.name, elem.attr):up();
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
137 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
138 elseif elem.name == "session" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
139 local found = false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
140 for child in data:children() do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
141 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
142 for k, v in pairs(elem.attr) do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
143 child.attr[k] = v;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
144 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
145 found = true;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
146 break;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
147 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
148 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
149 if not found then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
150 data:tag(elem.name, elem.attr):up();
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
151 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
152 elseif elem.name == "method" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
153 local newpref = stanza.tags[1]; -- iq:pref
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
154 for _, e in ipairs(newpref.tags) do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
155 -- if e.name ~= "method" then continue end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
156 local found = false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
157 for child in data:children() do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
158 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
159 child.attr["use"] = e.attr["use"];
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
160 found = true;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
161 break;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
162 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
163 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
164 if not found then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
165 data:tag(e.name, e.attr):up();
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
166 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
167 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
168 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
169 store_prefs(data, node, host);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
170 origin.send(st.reply(stanza));
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
171 local user = bare_sessions[node.."@"..host];
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
172 local push = st.iq({type="set"});
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
173 push = push:tag('pref', {xmlns='urn:xmpp:archive'});
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
174 if elem.name == "method" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
175 for child in data:children() do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
176 if child.name == "method" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
177 push:add_child(child);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
178 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
179 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
180 else
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
181 push:add_child(elem);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
182 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
183 push = push:up();
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
184 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
185 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
186 push.attr.to = res.full_jid;
165
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
187 res.send(push);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
188 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
189 end
159
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
190 end
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
191 return true;
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
192 end
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
193
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
194 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
195 -- 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
196 -- or use pcall() to catch exceptions?
165
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
197 local origin, stanza = event.origin, event.stanza;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
198 if stanza.attr.type ~= "set" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
199 return false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
200 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
201 local elem = stanza.tags[1].tags[1];
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
202 if not elem or elem.name ~= "item" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
203 return false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
204 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
205 local node, host = origin.username, origin.host;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
206 local data = load_prefs(node, host);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
207 if not data then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
208 return false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
209 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
210 for i, child in ipairs(data) do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
211 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
212 table.remove(data, i)
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
213 break;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
214 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
215 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
216 store_prefs(data, node, host);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
217 origin.send(st.reply(stanza));
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
218 return true;
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
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
221 local function sessionremove_handler(event)
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
222 local origin, stanza = event.origin, event.stanza;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
223 if stanza.attr.type ~= "set" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
224 return false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
225 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
226 local elem = stanza.tags[1].tags[1];
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
227 if not elem or elem.name ~= "session" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
228 return false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
229 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
230 local node, host = origin.username, origin.host;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
231 local data = load_prefs(node, host);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
232 if not data then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
233 return false;
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 for i, child in ipairs(data) do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
236 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
237 table.remove(data, i)
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
238 break;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
239 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
240 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
241 store_prefs(data, node, host);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
242 origin.send(st.reply(stanza));
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
243 return true;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
244 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
245
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
246 local function auto_handler(event)
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
247 -- 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
248 local origin, stanza = event.origin, event.stanza;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
249 if stanza.attr.type ~= "set" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
250 return false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
251 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
252 local elem = stanza.tags[1];
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
253 local node, host = origin.username, origin.host;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
254 local data = load_prefs(node, host);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
255 if not data then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
256 return false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
257 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
258 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
259 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
260 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
261 end
165
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
262 store_prefs(data, node, host);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
263 origin.send(st.reply(stanza));
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
264 return true;
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
193
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
267 ------------------------------------------------------------
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
268 -- Manual Archiving
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
269 ------------------------------------------------------------
159
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
270 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
271 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
272 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
273 return false;
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
274 end
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
275 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
276 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
277 return false;
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
278 end
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
279 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
280 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
281 if data then
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
282 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
283 local collection = st.deserialize(v);
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
284 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
285 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
286 -- 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
287 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
288 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
289 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
290 collection:add_child(newchild);
193
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
291 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
292 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
293 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
294 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
295 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
296 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
297 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
298 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
299 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
300 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
301 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
302 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
303 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
304 end
187
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
305 end
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
306 end
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
307 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
308 collection.attr["version"] = tostring(ver);
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
309 collection.attr["subject"] = elem.attr["subject"];
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
310 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
311 data[k] = collection;
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
312 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
313 return true;
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
314 end
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
315 end
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
316 end
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
317 -- not found, create new collection
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
318 elem.attr["version"] = "0";
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
319 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
320 -- TODO check if elem is valid(?)
187
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
321 dm.list_append(node, host, ARCHIVE_DIR, st.preserialize(elem));
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
322 -- TODO unsuccessful reply
157
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
323 return true;
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
324 end
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
325
178
62f47a93b5b7 mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents: 172
diff changeset
326 ------------------------------------------------------------
193
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
327 -- Archive Management
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
328 ------------------------------------------------------------
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
329 local function filter_with(with, coll_with)
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
330 return not with or coll_with:find(with);
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
331 end
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
332
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
333 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
334 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
335 end
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
336
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
337 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
338 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
339 end
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
340
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
341 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
342 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
343 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
344 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
345 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
346 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
347 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
348 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
349
193
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
350 local function list_handler(event)
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
351 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
352 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
353 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
354 local elem = stanza.tags[1];
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
355 local resset = {}
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
356 if data then
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
357 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
358 local collection = st.deserialize(v);
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
359 local res = filter_with(elem.attr["with"], collection.attr["with"]);
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
360 res = res and filter_start(elem.attr["start"], collection.attr["start"]);
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
361 res = res and filter_end(elem.attr["end"], collection.attr["start"]);
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
362 if res then
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
363 table.insert(resset, collection);
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
364 end
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
365 end
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
366 end
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
367 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
368 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
369 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
370 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
371 if max then
198
a3b5810de3e4 mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 196
diff changeset
372 max = tonumber(max:get_text()) or 100;
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
373 else max = 100; 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
374 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
375 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
376 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
377 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
378 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
379 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
380 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
381 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
382 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
383 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
384 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
385 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
386 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
387 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
388 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
389 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
390 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
391 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
392 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
393 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
394 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
395 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
396 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
397 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
398 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
399 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
400 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
401 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
402 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
403 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
404 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
405 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
406 -- 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
407 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
408 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
409 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
410 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
411 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
412 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
413 :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
414 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
415 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
416 reply:add_child(set);
193
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
417 end
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
418 origin.send(reply);
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
419 return true;
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
420 end
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
421
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
422 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
423 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
424 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
425 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
426 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
427 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
428 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
429 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
430 local c = st.deserialize(v);
a3b5810de3e4 mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 196
diff changeset
431 if c.attr["with"] == elem.attr["with"]
a3b5810de3e4 mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 196
diff changeset
432 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
433 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
434 break;
a3b5810de3e4 mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 196
diff changeset
435 end
a3b5810de3e4 mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 196
diff changeset
436 end
a3b5810de3e4 mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 196
diff changeset
437 end
a3b5810de3e4 mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 196
diff changeset
438 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
439 -- 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
440 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
441 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
442 end
a3b5810de3e4 mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 196
diff changeset
443 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
444 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
445 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
446 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
447 end
a3b5810de3e4 mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 196
diff changeset
448 end
a3b5810de3e4 mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 196
diff changeset
449 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
450 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
451 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
452 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
453 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
454 if max then
a3b5810de3e4 mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 196
diff changeset
455 max = tonumber(max:get_text()) or 100;
a3b5810de3e4 mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 196
diff changeset
456 else max = 100; end
a3b5810de3e4 mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 196
diff changeset
457 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
458 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
459 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
460 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
461 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
462 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
463 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
464 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
465 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
466 end
a3b5810de3e4 mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 196
diff changeset
467 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
468 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
469 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
470 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
471 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
472 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
473 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
474 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
475 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
476 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
477 else
a3b5810de3e4 mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 196
diff changeset
478 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
479 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
480 end
a3b5810de3e4 mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 196
diff changeset
481 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
482 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
483 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
484 end
a3b5810de3e4 mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 196
diff changeset
485 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
486 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
487 -- 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
488 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
489 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
490 end
a3b5810de3e4 mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 196
diff changeset
491 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
492 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
493 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
494 :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
495 end
a3b5810de3e4 mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 196
diff changeset
496 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
497 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
498 end
a3b5810de3e4 mod_archive: XEP-0059 Result Set Management for Retrieving a Collection is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 196
diff changeset
499 origin.send(reply);
193
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
500 return true;
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
501 end
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
502
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
503 local function remove_handler(event)
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
504 module:log("debug", "-- stanza:\n%s", tostring(event.stanza));
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
505 return true;
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
506 end
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
507
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
508 ------------------------------------------------------------
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
509 -- Replication
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
510 ------------------------------------------------------------
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
511 local function modified_handler(event)
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
512 module:log("debug", "-- stanza:\n%s", tostring(event.stanza));
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
513 return true;
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
514 end
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
515
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
516 ------------------------------------------------------------
178
62f47a93b5b7 mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents: 172
diff changeset
517 -- 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
518 ------------------------------------------------------------
172
ac826882a8cf mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents: 165
diff changeset
519 local function msg_handler(data)
182
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
520 -- TODO if not auto_archive_enabled then return nil;
172
ac826882a8cf mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents: 165
diff changeset
521 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
522 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
523 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
524 local thread = stanza:child_with_name("thread");
172
ac826882a8cf mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents: 165
diff changeset
525 module:log("debug", "-- msg:\n%s", tostring(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
526 if body then
62f47a93b5b7 mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents: 172
diff changeset
527 module:log("debug", "-- msg body:\n%s", tostring(body));
182
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
528 -- TODO mapping messages and conversations to collections if no thread
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
529 if thread then
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
530 module:log("debug", "-- msg thread:\n%s", tostring(thread));
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
531 -- module:log("debug", "-- msg body text:\n%s", body:get_text());
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
532 local from_node, from_host = jid.split(stanza.attr.from);
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
533 local to_node, to_host = jid.split(stanza.attr.to);
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
534 -- FIXME only archive messages of users on this host
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
535 if from_host == "localhost" then
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
536 store_msg(stanza, from_node, from_host, true);
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
537 end
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
538 if to_host == "localhost" then
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
539 store_msg(stanza, to_node, to_host, false);
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
540 end
178
62f47a93b5b7 mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents: 172
diff changeset
541 end
62f47a93b5b7 mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents: 172
diff changeset
542 end
172
ac826882a8cf mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents: 165
diff changeset
543 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
544 end
ac826882a8cf mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents: 165
diff changeset
545
193
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
546 -- Preferences
157
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
547 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
548 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
549 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
550 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
551 -- Manual archiving
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
552 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
553 -- Archive management
159
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
554 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
555 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
556 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
557 -- Replication
159
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
558 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
559
172
ac826882a8cf mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents: 165
diff changeset
560 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
561 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
562
193
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
563 -- 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
564 -- TODO exactmatch