Comparison

mod_mam/mod_mam.lua @ 1681:d20cfc5ba827

mod_mam: Always return true when a stanza event has been handled
author Kim Alvefur <zash@zash.se>
date Sun, 03 May 2015 13:20:04 +0200
parent 1678:9ee56cc1be2c
child 1682:6b2122630b92
comparison
equal deleted inserted replaced
1680:a9df1f7e273d 1681:d20cfc5ba827
50 local origin, stanza = event.origin, event.stanza; 50 local origin, stanza = event.origin, event.stanza;
51 local user = origin.username; 51 local user = origin.username;
52 if stanza.attr.type == "get" then 52 if stanza.attr.type == "get" then
53 local prefs = prefs_to_stanza(get_prefs(user)); 53 local prefs = prefs_to_stanza(get_prefs(user));
54 local reply = st.reply(stanza):add_child(prefs); 54 local reply = st.reply(stanza):add_child(prefs);
55 return origin.send(reply); 55 origin.send(reply);
56 else -- type == "set" 56 else -- type == "set"
57 local new_prefs = stanza:get_child("prefs", xmlns_mam); 57 local new_prefs = stanza:get_child("prefs", xmlns_mam);
58 local prefs = prefs_from_stanza(new_prefs); 58 local prefs = prefs_from_stanza(new_prefs);
59 local ok, err = set_prefs(user, prefs); 59 local ok, err = set_prefs(user, prefs);
60 if not ok then 60 if not ok then
61 return origin.send(st.error_reply(stanza, "cancel", "internal-server-error", "Error storing preferences: "..tostring(err))); 61 origin.send(st.error_reply(stanza, "cancel", "internal-server-error", "Error storing preferences: "..tostring(err)));
62 end 62 else
63 return origin.send(st.reply(stanza)); 63 origin.send(st.reply(stanza));
64 end 64 end
65 end
66 return true;
65 end); 67 end);
66 68
67 local query_form = dataform { 69 local query_form = dataform {
68 { name = "FORM_TYPE"; type = "hidden"; value = xmlns_mam; }; 70 { name = "FORM_TYPE"; type = "hidden"; value = xmlns_mam; };
69 { name = "with"; type = "jid-single"; }; 71 { name = "with"; type = "jid-single"; };
72 }; 74 };
73 75
74 -- Serve form 76 -- Serve form
75 module:hook("iq-get/self/"..xmlns_mam..":query", function(event) 77 module:hook("iq-get/self/"..xmlns_mam..":query", function(event)
76 local origin, stanza = event.origin, event.stanza; 78 local origin, stanza = event.origin, event.stanza;
77 return origin.send(st.reply(stanza):add_child(query_form:form())); 79 origin.send(st.reply(stanza):add_child(query_form:form()));
80 return true;
78 end); 81 end);
79 82
80 -- Handle archive queries 83 -- Handle archive queries
81 module:hook("iq-set/self/"..xmlns_mam..":query", function(event) 84 module:hook("iq-set/self/"..xmlns_mam..":query", function(event)
82 local origin, stanza = event.origin, event.stanza; 85 local origin, stanza = event.origin, event.stanza;
88 local form = query:get_child("x", "jabber:x:data"); 91 local form = query:get_child("x", "jabber:x:data");
89 if form then 92 if form then
90 local err; 93 local err;
91 form, err = query_form:data(form); 94 form, err = query_form:data(form);
92 if err then 95 if err then
93 return 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;
94 end 98 end
95 qwith, qstart, qend = form["with"], form["start"], form["end"]; 99 qwith, qstart, qend = form["with"], form["start"], form["end"];
96 qwith = qwith and jid_bare(qwith); -- dataforms does jidprep 100 qwith = qwith and jid_bare(qwith); -- dataforms does jidprep
97 end 101 end
98 102
125 reverse = reverse; 129 reverse = reverse;
126 total = true; 130 total = true;
127 }); 131 });
128 132
129 if not data then 133 if not data then
130 return 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;
131 end 136 end
132 local count = err; 137 local count = err;
133 138
134 origin.send(st.reply(stanza)) 139 origin.send(st.reply(stanza))
135 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 };
155 end 160 end
156 -- That's all folks! 161 -- That's all folks!
157 module:log("debug", "Archive query %s completed", tostring(qid)); 162 module:log("debug", "Archive query %s completed", tostring(qid));
158 163
159 if reverse then first, last = last, first; end 164 if reverse then first, last = last, first; end
160 return origin.send(st.message(msg_reply_attr) 165 origin.send(st.message(msg_reply_attr)
161 :tag("fin", { xmlns = xmlns_mam, queryid = qid }) 166 :tag("fin", { xmlns = xmlns_mam, queryid = qid })
162 :add_child(rsm.generate { 167 :add_child(rsm.generate {
163 first = first, last = last, count = count })); 168 first = first, last = last, count = count }));
169 return true;
164 end); 170 end);
165 171
166 local function has_in_roster(user, who) 172 local function has_in_roster(user, who)
167 local roster = rm_load_roster(user, host); 173 local roster = rm_load_roster(user, host);
168 module:log("debug", "%s has %s in roster? %s", user, who, roster[who] and "yes" or "no"); 174 module:log("debug", "%s has %s in roster? %s", user, who, roster[who] and "yes" or "no");