Mercurial > prosody-modules
annotate mod_archive/mod_archive.lua @ 193:18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
author | shinysky<shinysky1986(AT)gmail.com> |
---|---|
date | Mon, 05 Jul 2010 14:27:39 +0800 |
parents | 5e8ea3733dc6 |
children | 4d9ed6374a1f |
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"; |
157
86c28405c5da
initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff
changeset
|
15 |
86c28405c5da
initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff
changeset
|
16 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
|
17 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
|
18 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
|
19 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
|
20 module:add_feature("urn:xmpp:archive:pref"); |
157
86c28405c5da
initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff
changeset
|
21 |
165
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
22 ------------------------------------------------------------ |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
23 -- Utils |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
24 ------------------------------------------------------------ |
182
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
25 local function load_prefs(node, host) |
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
26 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
|
27 end |
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
28 |
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
29 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
|
30 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
|
31 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
32 |
193
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
33 local function os_time() |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
34 -- 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
|
35 return datetime.datetime(); |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
36 end |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
37 |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
38 local function date_parse(s) |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
39 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
|
40 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
|
41 end |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
42 |
182
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
43 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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 if data then |
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
49 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
|
50 local collection = st.deserialize(v); |
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
51 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
|
52 -- TODO figure out secs |
193
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
53 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
|
54 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
|
55 collection.attr["version"] = tostring(ver); |
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
56 data[k] = collection; |
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
57 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
|
58 return; |
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
59 end |
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
60 end |
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 -- 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
|
63 local utc = os_time(); |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
64 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
|
65 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
|
66 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
|
67 end |
62f47a93b5b7
mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents:
172
diff
changeset
|
68 |
187
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
69 local function save_result(collection) |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
70 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
|
71 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
|
72 save:add_child(chat); |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
73 return save; |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
74 end |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
75 |
165
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
76 ------------------------------------------------------------ |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
77 -- Preferences |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
78 ------------------------------------------------------------ |
157
86c28405c5da
initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff
changeset
|
79 local function preferences_handler(event) |
165
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
80 local origin, stanza = event.origin, event.stanza; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
81 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
|
82 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
|
83 if stanza.attr.type == "get" then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
84 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
|
85 if data then |
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
86 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
|
87 else |
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
88 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
|
89 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
|
90 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
|
91 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
|
92 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
|
93 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
|
94 origin.send(reply); |
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
95 end |
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
96 elseif stanza.attr.type == "set" then |
165
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
97 local node, host = origin.username, origin.host; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
98 local data = load_prefs(node, host); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
99 if not data then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
100 data = st.stanza('pref', {xmlns='urn:xmpp:archive'}); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
101 data:tag('default', {otr='concede', save='false'}):up(); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
102 data:tag('method', {type='auto', use='concede'}):up(); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
103 data:tag('method', {type='local', use='concede'}):up(); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
104 data:tag('method', {type='manual', use='concede'}):up(); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
105 data:tag('auto', {save='false'}):up(); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
106 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
107 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
|
108 if not elem then return false end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
109 -- "default" | "item" | "session" | "method" |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
110 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
|
111 if elem.name == "default" then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
112 local setting = data:child_with_name(elem.name) |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
113 for k, v in pairs(elem.attr) do |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
114 setting.attr[k] = v; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
115 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
116 -- setting.attr["unset"] = nil |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
117 elseif elem.name == "item" then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
118 local found = false; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
119 for child in data:children() do |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
120 -- TODO bare JID or full JID? |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
121 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
|
122 for k, v in pairs(elem.attr) do |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
123 child.attr[k] = v; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
124 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
125 found = true; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
126 break; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
127 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
128 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
129 if not found then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
130 data:tag(elem.name, elem.attr):up(); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
131 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
132 elseif elem.name == "session" then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
133 local found = false; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
134 for child in data:children() do |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
135 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
|
136 for k, v in pairs(elem.attr) do |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
137 child.attr[k] = v; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
138 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
139 found = true; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
140 break; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
141 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
142 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
143 if not found then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
144 data:tag(elem.name, elem.attr):up(); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
145 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
146 elseif elem.name == "method" then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
147 local newpref = stanza.tags[1]; -- iq:pref |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
148 for _, e in ipairs(newpref.tags) do |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
149 -- if e.name ~= "method" then continue end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
150 local found = false; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
151 for child in data:children() do |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
152 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
|
153 child.attr["use"] = e.attr["use"]; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
154 found = true; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
155 break; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
156 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
157 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
158 if not found then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
159 data:tag(e.name, e.attr):up(); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
160 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
161 end |
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 store_prefs(data, node, host); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
164 origin.send(st.reply(stanza)); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
165 local user = bare_sessions[node.."@"..host]; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
166 local push = st.iq({type="set"}); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
167 push = push:tag('pref', {xmlns='urn:xmpp:archive'}); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
168 if elem.name == "method" then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
169 for child in data:children() do |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
170 if child.name == "method" then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
171 push:add_child(child); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
172 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
173 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
174 else |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
175 push:add_child(elem); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
176 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
177 push = push:up(); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
178 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
|
179 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
|
180 push.attr.to = res.full_jid; |
165
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
181 res.send(push); |
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 end |
159
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
184 end |
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
185 return true; |
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
186 end |
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
187 |
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
188 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
|
189 -- 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
|
190 -- or use pcall() to catch exceptions? |
165
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
191 local origin, stanza = event.origin, event.stanza; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
192 if stanza.attr.type ~= "set" then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
193 return false; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
194 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
195 local elem = stanza.tags[1].tags[1]; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
196 if not elem or elem.name ~= "item" then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
197 return false; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
198 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
199 local node, host = origin.username, origin.host; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
200 local data = load_prefs(node, host); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
201 if not data then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
202 return false; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
203 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
204 for i, child in ipairs(data) do |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
205 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
|
206 table.remove(data, i) |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
207 break; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
208 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
209 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
210 store_prefs(data, node, host); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
211 origin.send(st.reply(stanza)); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
212 return true; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
213 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
214 |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
215 local function sessionremove_handler(event) |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
216 local origin, stanza = event.origin, event.stanza; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
217 if stanza.attr.type ~= "set" then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
218 return false; |
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 local elem = stanza.tags[1].tags[1]; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
221 if not elem or elem.name ~= "session" then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
222 return false; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
223 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
224 local node, host = origin.username, origin.host; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
225 local data = load_prefs(node, host); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
226 if not data then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
227 return false; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
228 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
229 for i, child in ipairs(data) do |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
230 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
|
231 table.remove(data, i) |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
232 break; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
233 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
234 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
235 store_prefs(data, node, host); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
236 origin.send(st.reply(stanza)); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
237 return true; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
238 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
239 |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
240 local function auto_handler(event) |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
241 -- 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
|
242 local origin, stanza = event.origin, event.stanza; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
243 if stanza.attr.type ~= "set" then |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
244 return false; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
245 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
246 local elem = stanza.tags[1]; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
247 local node, host = origin.username, origin.host; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
248 local data = load_prefs(node, host); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
249 if not data 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 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
|
253 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
|
254 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
|
255 end |
165
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
256 store_prefs(data, node, host); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
257 origin.send(st.reply(stanza)); |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
258 return true; |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
259 end |
fd8d76daad97
mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents:
159
diff
changeset
|
260 |
193
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
261 ------------------------------------------------------------ |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
262 -- Manual Archiving |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
263 ------------------------------------------------------------ |
159
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
264 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
|
265 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
|
266 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
|
267 return false; |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
268 end |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
269 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
|
270 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
|
271 return false; |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
272 end |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
273 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
|
274 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
|
275 if data then |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
276 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
|
277 local collection = st.deserialize(v); |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
278 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
|
279 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
|
280 -- 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
|
281 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
|
282 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
|
283 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
|
284 collection:add_child(newchild); |
193
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
285 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
|
286 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
|
287 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
|
288 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
|
289 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
|
290 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
|
291 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
|
292 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
|
293 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
|
294 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
|
295 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
|
296 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
|
297 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
|
298 end |
187
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
299 end |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
300 end |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
301 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
|
302 collection.attr["version"] = tostring(ver); |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
303 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
|
304 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
|
305 data[k] = collection; |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
306 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
|
307 return true; |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
308 end |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
309 end |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
310 end |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
311 -- not found, create new collection |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
312 elem.attr["version"] = "0"; |
670c99e96c52
mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents:
182
diff
changeset
|
313 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
|
314 -- 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
|
315 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
|
316 -- TODO unsuccessful reply |
157
86c28405c5da
initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff
changeset
|
317 return true; |
86c28405c5da
initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff
changeset
|
318 end |
86c28405c5da
initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff
changeset
|
319 |
178
62f47a93b5b7
mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents:
172
diff
changeset
|
320 ------------------------------------------------------------ |
193
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
321 -- Archive Management |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
322 ------------------------------------------------------------ |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
323 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
|
324 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
|
325 end |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
326 |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
327 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
|
328 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
|
329 end |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
330 |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
331 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
|
332 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
|
333 end |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
334 |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
335 local function list_handler(event) |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
336 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
|
337 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
|
338 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
|
339 local elem = stanza.tags[1]; |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
340 local resset = {} |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
341 if data then |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
342 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
|
343 local collection = st.deserialize(v); |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
344 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
|
345 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
|
346 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
|
347 if res then |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
348 table.insert(resset, collection); |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
349 end |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
350 end |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
351 end |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
352 local reply = st.reply(stanza):tag('list', {xmlns='urn:xmpp:archive'}); |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
353 if table.getn(resset) > 0 then |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
354 local max = tonumber(elem.tags[1].tags[1]:get_text()); |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
355 -- Assuming result set is sorted. |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
356 for i, c in ipairs(resset) do |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
357 if i <= max then |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
358 local chat = st.stanza('chat', c.attr); |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
359 reply:add_child(chat); |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
360 else break; end |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
361 end |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
362 end |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
363 origin.send(reply); |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
364 return true; |
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 |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
367 local function retrieve_handler(event) |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
368 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
|
369 return true; |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
370 end |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
371 |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
372 local function remove_handler(event) |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
373 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
|
374 return true; |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
375 end |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
376 |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
377 ------------------------------------------------------------ |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
378 -- Replication |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
379 ------------------------------------------------------------ |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
380 local function modified_handler(event) |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
381 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
|
382 return true; |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
383 end |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
384 |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
385 ------------------------------------------------------------ |
178
62f47a93b5b7
mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents:
172
diff
changeset
|
386 -- 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
|
387 ------------------------------------------------------------ |
172
ac826882a8cf
mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents:
165
diff
changeset
|
388 local function msg_handler(data) |
182
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
389 -- 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
|
390 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
|
391 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
|
392 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
|
393 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
|
394 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
|
395 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
|
396 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
|
397 -- 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
|
398 if thread then |
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
399 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
|
400 -- 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
|
401 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
|
402 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
|
403 -- 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
|
404 if from_host == "localhost" then |
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
405 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
|
406 end |
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
407 if to_host == "localhost" then |
43d9e0944276
mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents:
178
diff
changeset
|
408 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
|
409 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
|
410 end |
62f47a93b5b7
mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents:
172
diff
changeset
|
411 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
|
412 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
|
413 end |
ac826882a8cf
mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents:
165
diff
changeset
|
414 |
193
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
415 -- Preferences |
157
86c28405c5da
initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff
changeset
|
416 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
|
417 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
|
418 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
|
419 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
|
420 -- Manual archiving |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
421 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
|
422 -- Archive management |
159
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
423 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
|
424 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
|
425 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
|
426 -- Replication |
159
9a37898f4f7c
mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents:
157
diff
changeset
|
427 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
|
428 |
172
ac826882a8cf
mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents:
165
diff
changeset
|
429 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
|
430 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
|
431 |
193
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
432 -- FIXME sort collections |
18a0e5c0bb62
mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents:
188
diff
changeset
|
433 |