Software /
code /
prosody-modules
Comparison
mod_mam/mod_mam.lua @ 799:53917d98d411
mod_mam: Change storage format to store bare JID + resource.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 16 Aug 2012 21:31:46 +0200 |
parent | 798:2b8ceb4d1a73 |
child | 800:966993356d2b |
comparison
equal
deleted
inserted
replaced
798:2b8ceb4d1a73 | 799:53917d98d411 |
---|---|
133 return true | 133 return true |
134 end | 134 end |
135 qstart, qend = vstart, vend; | 135 qstart, qend = vstart, vend; |
136 end | 136 end |
137 | 137 |
138 local qres; | |
138 if qwith then -- Validate the 'with' jid | 139 if qwith then -- Validate the 'with' jid |
139 local pwith = qwith and jid_prep(qwith); | 140 local pwith = qwith and jid_prep(qwith); |
140 if pwith and not qwith then -- it failed prepping | 141 if pwith and not qwith then -- it failed prepping |
141 origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid JID")) | 142 origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid JID")) |
142 return true | 143 return true |
143 end | 144 end |
144 qwith = pwith; | 145 local _, _, resource = jid_split(qwith); |
146 qwith = jid_bare(pwith); | |
147 qres = resource; | |
145 end | 148 end |
146 | 149 |
147 -- Load all the data! | 150 -- Load all the data! |
148 local data, err = dm_list_load(origin.username, origin.host, archive_store); | 151 local data, err = dm_list_load(origin.username, origin.host, archive_store); |
149 if not data then | 152 if not data then |
164 local start = qset and qset.index or 1; | 167 local start = qset and qset.index or 1; |
165 | 168 |
166 module:log("debug", "Loaded %d items, about to filter", #data); | 169 module:log("debug", "Loaded %d items, about to filter", #data); |
167 for i=start,#data do | 170 for i=start,#data do |
168 local item = data[i]; | 171 local item = data[i]; |
169 local when, with, with_bare = item.when, item.with, item.with_bare; | 172 local when, with, resource = item.when, item.with, item.resource; |
170 local id = item.id; | 173 local id = item.id; |
171 --module:log("debug", "id is %s", id); | 174 --module:log("debug", "id is %s", id); |
172 | 175 |
173 -- RSM pre-send-checking | 176 -- RSM pre-send-checking |
174 if qset then | 177 if qset then |
179 end | 182 end |
180 end | 183 end |
181 | 184 |
182 --module:log("debug", "message with %s at %s", with, when or "???"); | 185 --module:log("debug", "message with %s at %s", with, when or "???"); |
183 -- Apply query filter | 186 -- Apply query filter |
184 if (not qwith or ((qwith == with) or (qwith == with_bare))) | 187 if (not qwith or ((qwith == with) and (not qres or qres == resource))) |
185 and (not qstart or when >= qstart) | 188 and (not qstart or when >= qstart) |
186 and (not qend or when <= qend) | 189 and (not qend or when <= qend) |
187 and (not qset or qset_matches) then | 190 and (not qset or qset_matches) then |
188 local fwd_st = st.message{ to = origin.full_jid } | 191 local fwd_st = st.message{ to = origin.full_jid } |
189 :tag("result", { xmlns = xmlns_mam, queryid = qid, id = id }):up() | 192 :tag("result", { xmlns = xmlns_mam, queryid = qid, id = id }):up() |
279 end | 282 end |
280 | 283 |
281 local store_user, store_host = jid_split(c2s and orig_from or orig_to); | 284 local store_user, store_host = jid_split(c2s and orig_from or orig_to); |
282 local target_jid = c2s and orig_to or orig_from; | 285 local target_jid = c2s and orig_to or orig_from; |
283 local target_bare = jid_bare(target_jid); | 286 local target_bare = jid_bare(target_jid); |
287 local _, _, target_resource = jid_split(target_jid); | |
284 | 288 |
285 if shall_store(store_user, target_bare) then | 289 if shall_store(store_user, target_bare) then |
286 module:log("debug", "Archiving stanza: %s", stanza:top_tag()); | 290 module:log("debug", "Archiving stanza: %s", stanza:top_tag()); |
287 | 291 |
288 local id = uuid(); | 292 local id = uuid(); |
290 -- And stash it | 294 -- And stash it |
291 local ok, err = dm_list_append(store_user, store_host, archive_store, { | 295 local ok, err = dm_list_append(store_user, store_host, archive_store, { |
292 -- WARNING This format may change. | 296 -- WARNING This format may change. |
293 id = id, | 297 id = id, |
294 when = when, | 298 when = when, |
295 with = target_jid, | 299 with = target_bare, |
296 with_bare = target_bare, -- Optimization, to avoid loads of jid_bare() calls when filtering. | 300 resource = target_resource, |
297 stanza = st.preserialize(stanza) | 301 stanza = st.preserialize(stanza) |
298 }); | 302 }); |
299 --[[ This was dropped from the spec | 303 --[[ This was dropped from the spec |
300 if ok then | 304 if ok then |
301 stanza:tag("archived", { xmlns = xmlns_mam, by = host, id = id }):up(); | 305 stanza:tag("archived", { xmlns = xmlns_mam, by = host, id = id }):up(); |