comparison mod_mam/mod_mam.lua @ 1698:55bc42c1d8c5

mod_mam: Semicolons!
author Kim Alvefur <zash@zash.se>
date Tue, 05 May 2015 15:36:57 +0200
parents cd87a2eba8f2
children 2ee9725c7fc6
comparison
equal deleted inserted replaced
1697:27aa58ed3e2e 1698:55bc42c1d8c5
37 37
38 local archive_store = "archive2"; 38 local archive_store = "archive2";
39 local archive = module:open_store(archive_store, "archive"); 39 local archive = module:open_store(archive_store, "archive");
40 if not archive or archive.name == "null" then 40 if not archive or archive.name == "null" then
41 module:log("error", "Could not open archive storage"); 41 module:log("error", "Could not open archive storage");
42 return 42 return;
43 elseif not archive.find then 43 elseif not archive.find then
44 module:log("error", "mod_%s does not support archiving, switch to mod_storage_sql2", archive._provided_by); 44 module:log("error", "mod_%s does not support archiving, switch to mod_storage_sql2", archive._provided_by);
45 return 45 return;
46 end 46 end
47 47
48 -- Handle prefs. 48 -- Handle prefs.
49 module:hook("iq/self/"..xmlns_mam..":prefs", function(event) 49 module:hook("iq/self/"..xmlns_mam..":prefs", function(event)
50 local origin, stanza = event.origin, event.stanza; 50 local origin, stanza = event.origin, event.stanza;
91 local form = query:get_child("x", "jabber:x:data"); 91 local form = query:get_child("x", "jabber:x:data");
92 if form then 92 if form then
93 local err; 93 local err;
94 form, err = query_form:data(form); 94 form, err = query_form:data(form);
95 if err then 95 if err then
96 origin.send(st.error_reply(stanza, "modify", "bad-request", select(2, next(err)))) 96 origin.send(st.error_reply(stanza, "modify", "bad-request", select(2, next(err))));
97 return true; 97 return true;
98 end 98 end
99 qwith, qstart, qend = form["with"], form["start"], form["end"]; 99 qwith, qstart, qend = form["with"], form["start"], form["end"];
100 qwith = qwith and jid_bare(qwith); -- dataforms does jidprep 100 qwith = qwith and jid_bare(qwith); -- dataforms does jidprep
101 end 101 end
102 102
103 if qstart or qend then -- Validate timestamps 103 if qstart or qend then -- Validate timestamps
104 local vstart, vend = (qstart and timestamp_parse(qstart)), (qend and timestamp_parse(qend)) 104 local vstart, vend = (qstart and timestamp_parse(qstart)), (qend and timestamp_parse(qend));
105 if (qstart and not vstart) or (qend and not vend) then 105 if (qstart and not vstart) or (qend and not vend) then
106 origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid timestamp")) 106 origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid timestamp"))
107 return true 107 return true;
108 end 108 end
109 qstart, qend = vstart, vend; 109 qstart, qend = vstart, vend;
110 end 110 end
111 111
112 module:log("debug", "Archive query, id %s with %s from %s until %s)", 112 module:log("debug", "Archive query, id %s with %s from %s until %s)",
134 origin.send(st.error_reply(stanza, "cancel", "internal-server-error", err)); 134 origin.send(st.error_reply(stanza, "cancel", "internal-server-error", err));
135 return true; 135 return true;
136 end 136 end
137 local total = err; 137 local total = err;
138 138
139 origin.send(st.reply(stanza)) 139 origin.send(st.reply(stanza));
140 local msg_reply_attr = { to = stanza.attr.from, from = stanza.attr.to }; 140 local msg_reply_attr = { to = stanza.attr.from, from = stanza.attr.to };
141 141
142 local results = {}; 142 local results = {};
143 143
144 -- Wrap it in stuff and deliver 144 -- Wrap it in stuff and deliver
196 196
197 local function shall_store(user, who) 197 local function shall_store(user, who)
198 -- TODO Cache this? 198 -- TODO Cache this?
199 local prefs = get_prefs(user); 199 local prefs = get_prefs(user);
200 local rule = prefs[who]; 200 local rule = prefs[who];
201 module:log("debug", "%s's rule for %s is %s", user, who, tostring(rule)) 201 module:log("debug", "%s's rule for %s is %s", user, who, tostring(rule));
202 if rule ~= nil then 202 if rule ~= nil then
203 return rule; 203 return rule;
204 else -- Below could be done by a metatable 204 else -- Below could be done by a metatable
205 local default = prefs[false]; 205 local default = prefs[false];
206 module:log("debug", "%s's default rule is %s", user, tostring(default)) 206 module:log("debug", "%s's default rule is %s", user, tostring(default));
207 if default == nil then 207 if default == nil then
208 default = global_default_policy; 208 default = global_default_policy;
209 module:log("debug", "Using global default rule, %s", tostring(default)) 209 module:log("debug", "Using global default rule, %s", tostring(default));
210 end 210 end
211 if default == "roster" then 211 if default == "roster" then
212 return has_in_roster(user, who); 212 return has_in_roster(user, who);
213 end 213 end
214 return default; 214 return default;