annotate mod_archive_muc/mod_archive_muc.lua @ 343:845a59c99b4d

mod_muc_log_http: Fix iterator usage and indentation in loadTheme() (thanks tanget128)
author Matthew Wild <mwild1@gmail.com>
date Thu, 03 Mar 2011 15:27:39 +0000
parents 6202ce4d12d6
children 2c85635318a5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
237
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
1 -- Prosody IM
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
2 -- Copyright (C) 2010 Dai Zhiwei
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
3 --
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
4 -- This project is MIT/X11 licensed. Please see the
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
5 -- COPYING file in the source package for more information.
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
6 --
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
7
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
8 local st = require "util.stanza";
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
9 local dm = require "util.datamanager";
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
10 local jid = require "util.jid";
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
11 local datetime = require "util.datetime";
238
5343b3ebaffb mod_archive_muc: use usermanager to check if some user exists; use rostermanager to check if someone is in the roster; minor fixes.
shinysky<shinysky1986(AT)gmail.com>
parents: 237
diff changeset
12 local um = require "core.usermanager";
5343b3ebaffb mod_archive_muc: use usermanager to check if some user exists; use rostermanager to check if someone is in the roster; minor fixes.
shinysky<shinysky1986(AT)gmail.com>
parents: 237
diff changeset
13 local rom = require "core.rostermanager";
237
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
14
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
15 local PREFS_DIR = "archive_muc_prefs";
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
16 local ARCHIVE_DIR = "archive_muc";
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
17
243
6202ce4d12d6 mod_archive: added some config options.
shinysky<shinysky1986(AT)gmail.com>
parents: 240
diff changeset
18 local AUTO_MUC_ARCHIVING_ENABLED = module:get_option_boolean("auto_muc_archiving_enabled", true);
237
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
19
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
20 module:add_feature("urn:xmpp:archive#preferences");
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
21 module:add_feature("urn:xmpp:archive#management");
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
22
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
23 ------------------------------------------------------------
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
24 -- Utils
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
25 ------------------------------------------------------------
240
ef0b580f434d mod_archive_muc: clean up '\n ' in preference stanza
shinysky<shinysky1986(AT)gmail.com>
parents: 238
diff changeset
26 local function trim(s)
ef0b580f434d mod_archive_muc: clean up '\n ' in preference stanza
shinysky<shinysky1986(AT)gmail.com>
parents: 238
diff changeset
27 return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
ef0b580f434d mod_archive_muc: clean up '\n ' in preference stanza
shinysky<shinysky1986(AT)gmail.com>
parents: 238
diff changeset
28 end
ef0b580f434d mod_archive_muc: clean up '\n ' in preference stanza
shinysky<shinysky1986(AT)gmail.com>
parents: 238
diff changeset
29
ef0b580f434d mod_archive_muc: clean up '\n ' in preference stanza
shinysky<shinysky1986(AT)gmail.com>
parents: 238
diff changeset
30 local function clean_up(t)
ef0b580f434d mod_archive_muc: clean up '\n ' in preference stanza
shinysky<shinysky1986(AT)gmail.com>
parents: 238
diff changeset
31 for i = #t, 1, -1 do
ef0b580f434d mod_archive_muc: clean up '\n ' in preference stanza
shinysky<shinysky1986(AT)gmail.com>
parents: 238
diff changeset
32 if type(t[i]) == 'table' then
ef0b580f434d mod_archive_muc: clean up '\n ' in preference stanza
shinysky<shinysky1986(AT)gmail.com>
parents: 238
diff changeset
33 clean_up(t[i]);
ef0b580f434d mod_archive_muc: clean up '\n ' in preference stanza
shinysky<shinysky1986(AT)gmail.com>
parents: 238
diff changeset
34 elseif type(t[i]) == 'string' and trim(t[i]) == '' then
ef0b580f434d mod_archive_muc: clean up '\n ' in preference stanza
shinysky<shinysky1986(AT)gmail.com>
parents: 238
diff changeset
35 table.remove(t, i);
ef0b580f434d mod_archive_muc: clean up '\n ' in preference stanza
shinysky<shinysky1986(AT)gmail.com>
parents: 238
diff changeset
36 end
ef0b580f434d mod_archive_muc: clean up '\n ' in preference stanza
shinysky<shinysky1986(AT)gmail.com>
parents: 238
diff changeset
37 end
ef0b580f434d mod_archive_muc: clean up '\n ' in preference stanza
shinysky<shinysky1986(AT)gmail.com>
parents: 238
diff changeset
38 end
ef0b580f434d mod_archive_muc: clean up '\n ' in preference stanza
shinysky<shinysky1986(AT)gmail.com>
parents: 238
diff changeset
39
237
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
40 local function load_prefs(node, host)
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
41 return st.deserialize(dm.load(node, host, PREFS_DIR));
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
42 end
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
43
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
44 local function store_prefs(data, node, host)
240
ef0b580f434d mod_archive_muc: clean up '\n ' in preference stanza
shinysky<shinysky1986(AT)gmail.com>
parents: 238
diff changeset
45 clean_up(data);
237
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
46 dm.store(node, host, PREFS_DIR, st.preserialize(data));
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
47 end
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
48
238
5343b3ebaffb mod_archive_muc: use usermanager to check if some user exists; use rostermanager to check if someone is in the roster; minor fixes.
shinysky<shinysky1986(AT)gmail.com>
parents: 237
diff changeset
49 local date_time = datetime.datetime;
237
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
50
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
51 local function match_jid(rule, id)
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
52 return not rule or jid.compare(id, rule);
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
53 end
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
54
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
55 local function is_earlier(start, coll_start)
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
56 return not start or start <= coll_start;
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
57 end
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
58
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
59 local function is_later(endtime, coll_start)
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
60 return not endtime or endtime >= coll_start;
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
61 end
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
62
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
63 ------------------------------------------------------------
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
64 -- Preferences
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
65 ------------------------------------------------------------
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
66 local function preferences_handler(event)
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
67 local origin, stanza = event.origin, event.stanza;
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
68 module:log("debug", "-- Enter muc preferences_handler()");
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
69 module:log("debug", "-- muc pref:\n%s", tostring(stanza));
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
70 if stanza.attr.type == "get" then
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
71 local data = load_prefs(origin.username, origin.host);
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
72 if data then
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
73 origin.send(st.reply(stanza):add_child(data));
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
74 else
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
75 origin.send(st.reply(stanza));
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
76 end
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
77 elseif stanza.attr.type == "set" then
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
78 local node, host = origin.username, origin.host;
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
79 if stanza.tags[1] and stanza.tags[1].name == 'prefs' then
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
80 store_prefs(stanza.tags[1], node, host);
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
81 origin.send(st.reply(stanza));
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
82 local user = bare_sessions[node.."@"..host];
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
83 local push = st.iq({type="set"});
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
84 push:add_child(stanza.tags[1]);
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
85 for _, res in pairs(user and user.sessions or NULL) do -- broadcast to all resources
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
86 if res.presence then -- to resource
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
87 push.attr.to = res.full_jid;
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
88 res.send(push);
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
89 end
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
90 end
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
91 end
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
92 end
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
93 return true;
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
94 end
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
95
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
96 ------------------------------------------------------------
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
97 -- Archive Management
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
98 ------------------------------------------------------------
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
99 local function management_handler(event)
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
100 module:log("debug", "-- Enter muc management_handler()");
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
101 local origin, stanza = event.origin, event.stanza;
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
102 local node, host = origin.username, origin.host;
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
103 local data = dm.list_load(node, host, ARCHIVE_DIR);
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
104 local elem = stanza.tags[1];
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
105 local resset = {}
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
106 if data then
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
107 for i = #data, 1, -1 do
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
108 local forwarded = st.deserialize(data[i]);
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
109 local res = (match_jid(elem.attr["with"], forwarded.tags[2].attr.from)
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
110 or match_jid(elem.attr["with"], forwarded.tags[2].attr.to))
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
111 and is_earlier(elem.attr["start"], forwarded.tags[1].attr["stamp"])
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
112 and is_later(elem.attr["end"], forwarded.tags[1].attr["stamp"]);
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
113 if res then
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
114 table.insert(resset, forwarded);
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
115 end
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
116 end
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
117 for i = #resset, 1, -1 do
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
118 local res = st.message({to = stanza.attr.from, id=st.new_id()});
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
119 res:add_child(resset[i]);
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
120 origin.send(res);
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
121 end
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
122 end
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
123 origin.send(st.reply(stanza));
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
124 return true;
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
125 end
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
126
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
127 ------------------------------------------------------------
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
128 -- Message Handler
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
129 ------------------------------------------------------------
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
130 local function is_in(list, jid)
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
131 for _,v in ipairs(list) do
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
132 if match_jid(v:get_text(), jid) then -- JID Matching
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
133 return true;
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
134 end
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
135 end
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
136 return false;
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
137 end
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
138
238
5343b3ebaffb mod_archive_muc: use usermanager to check if some user exists; use rostermanager to check if someone is in the roster; minor fixes.
shinysky<shinysky1986(AT)gmail.com>
parents: 237
diff changeset
139 local function is_in_roster(node, host, id)
5343b3ebaffb mod_archive_muc: use usermanager to check if some user exists; use rostermanager to check if someone is in the roster; minor fixes.
shinysky<shinysky1986(AT)gmail.com>
parents: 237
diff changeset
140 return rom.is_contact_subscribed(node, host, jid.bare(id));
237
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
141 end
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
142
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
143 local function apply_pref(node, host, jid)
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
144 local pref = load_prefs(node, host);
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
145 if not pref then
243
6202ce4d12d6 mod_archive: added some config options.
shinysky<shinysky1986(AT)gmail.com>
parents: 240
diff changeset
146 return AUTO_MUC_ARCHIVING_ENABLED;
237
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
147 end
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
148 local always = pref:child_with_name('always');
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
149 if always and is_in(always, jid) then
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
150 return true;
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
151 end
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
152 local never = pref:child_with_name('never');
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
153 if never and is_in(never, jid) then
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
154 return false;
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
155 end
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
156 local default = pref.attr['default'];
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
157 if default == 'roster' then
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
158 return is_in_roster(node, host, jid);
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
159 elseif default == 'always' then
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
160 return true;
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
161 elseif default == 'never' then
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
162 return false;
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
163 end
243
6202ce4d12d6 mod_archive: added some config options.
shinysky<shinysky1986(AT)gmail.com>
parents: 240
diff changeset
164 return AUTO_MUC_ARCHIVING_ENABLED;
237
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
165 end
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
166
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
167 local function store_msg(msg, node, host)
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
168 local forwarded = st.stanza('forwarded', {xmlns='urn:xmpp:forward:tmp'});
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
169 forwarded:tag('delay', {xmlns='urn:xmpp:delay',stamp=date_time()}):up();
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
170 forwarded:add_child(msg);
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
171 dm.list_append(node, host, ARCHIVE_DIR, st.preserialize(forwarded));
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
172 end
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
173
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
174 local function msg_handler(data)
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
175 module:log("debug", "-- Enter muc msg_handler()");
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
176 local origin, stanza = data.origin, data.stanza;
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
177 local body = stanza:child_with_name("body");
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
178 if body then
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
179 local from_node, from_host = jid.split(stanza.attr.from);
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
180 local to_node, to_host = jid.split(stanza.attr.to);
238
5343b3ebaffb mod_archive_muc: use usermanager to check if some user exists; use rostermanager to check if someone is in the roster; minor fixes.
shinysky<shinysky1986(AT)gmail.com>
parents: 237
diff changeset
181 if um.user_exists(from_node, from_host) and apply_pref(from_node, from_host, stanza.attr.to) then
237
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
182 store_msg(stanza, from_node, from_host);
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
183 end
238
5343b3ebaffb mod_archive_muc: use usermanager to check if some user exists; use rostermanager to check if someone is in the roster; minor fixes.
shinysky<shinysky1986(AT)gmail.com>
parents: 237
diff changeset
184 if um.user_exists(to_node, to_host) and apply_pref(to_node, to_host, stanza.attr.from) then
237
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
185 store_msg(stanza, to_node, to_host);
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
186 end
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
187 end
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
188
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
189 return nil;
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
190 end
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
191
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
192 -- Preferences
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
193 module:hook("iq/self/urn:xmpp:archive#preferences:prefs", preferences_handler);
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
194 -- Archive management
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
195 module:hook("iq/self/urn:xmpp:archive#management:query", management_handler);
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
196
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
197 module:hook("message/bare", msg_handler, 20);
d900be0dee3e mod_archive: minor fix;
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
198