10 |
10 |
11 local xmlns_mam = "urn:xmpp:mam:2"; |
11 local xmlns_mam = "urn:xmpp:mam:2"; |
12 local xmlns_delay = "urn:xmpp:delay"; |
12 local xmlns_delay = "urn:xmpp:delay"; |
13 local xmlns_forward = "urn:xmpp:forward:0"; |
13 local xmlns_forward = "urn:xmpp:forward:0"; |
14 local xmlns_st_id = "urn:xmpp:sid:0"; |
14 local xmlns_st_id = "urn:xmpp:sid:0"; |
|
15 local xmlns_muc_user = "http://jabber.org/protocol/muc#user"; |
15 local muc_form_enable = "muc#roomconfig_enablearchiving" |
16 local muc_form_enable = "muc#roomconfig_enablearchiving" |
16 |
17 |
17 local st = require "util.stanza"; |
18 local st = require "util.stanza"; |
18 local rsm = require "util.rsm"; |
19 local rsm = require "util.rsm"; |
19 local jid_bare = require "util.jid".bare; |
20 local jid_bare = require "util.jid".bare; |
247 local fwd_st = st.message(msg_reply_attr) |
248 local fwd_st = st.message(msg_reply_attr) |
248 :tag("result", { xmlns = xmlns_mam, queryid = qid, id = id }) |
249 :tag("result", { xmlns = xmlns_mam, queryid = qid, id = id }) |
249 :tag("forwarded", { xmlns = xmlns_forward }) |
250 :tag("forwarded", { xmlns = xmlns_forward }) |
250 :tag("delay", { xmlns = xmlns_delay, stamp = timestamp(when) }):up(); |
251 :tag("delay", { xmlns = xmlns_delay, stamp = timestamp(when) }):up(); |
251 |
252 |
|
253 if room:get_whois() ~= "anyone" then |
|
254 item:maptags(function (tag) |
|
255 if tag.name == "x" and tag.attr.xmlns == xmlns_muc_user then |
|
256 return nil; |
|
257 end |
|
258 return tag; |
|
259 end); |
|
260 end |
252 if not is_stanza(item) then |
261 if not is_stanza(item) then |
253 item = st.deserialize(item); |
262 item = st.deserialize(item); |
254 end |
263 end |
255 item.attr.xmlns = "jabber:client"; |
264 item.attr.xmlns = "jabber:client"; |
256 fwd_st:add_child(item); |
265 fwd_st:add_child(item); |
309 |
318 |
310 for id, item, when in data do |
319 for id, item, when in data do |
311 item.attr.to = to; |
320 item.attr.to = to; |
312 item:tag("delay", { xmlns = "urn:xmpp:delay", from = room_jid, stamp = timestamp(when) }):up(); -- XEP-0203 |
321 item:tag("delay", { xmlns = "urn:xmpp:delay", from = room_jid, stamp = timestamp(when) }):up(); -- XEP-0203 |
313 item:tag("stanza-id", { xmlns = xmlns_st_id, by = room_jid, id = id }):up(); |
322 item:tag("stanza-id", { xmlns = xmlns_st_id, by = room_jid, id = id }):up(); |
|
323 if room:get_whois() ~= "anyone" then |
|
324 item:maptags(function (tag) |
|
325 if tag.name == "x" and tag.attr.xmlns == xmlns_muc_user then |
|
326 return nil; |
|
327 end |
|
328 return tag; |
|
329 end); |
|
330 end |
314 if maxchars then |
331 if maxchars then |
315 local chars = #tostring(item); |
332 local chars = #tostring(item); |
316 if maxchars - chars < 0 then |
333 if maxchars - chars < 0 then |
317 break |
334 break |
318 end |
335 end |
368 stanza:maptags(function (tag) |
385 stanza:maptags(function (tag) |
369 if tag.name == "stanza-id" and tag.attr.xmlns == xmlns_st_id |
386 if tag.name == "stanza-id" and tag.attr.xmlns == xmlns_st_id |
370 and jid_prep(tag.attr.by) == self.jid then |
387 and jid_prep(tag.attr.by) == self.jid then |
371 return nil; |
388 return nil; |
372 end |
389 end |
|
390 if tag.name == "x" and tag.attr.xmlns == xmlns_muc_user then |
|
391 return nil; |
|
392 end |
373 return tag; |
393 return tag; |
374 end); |
394 end); |
|
395 |
|
396 local stored_stanza = stanza; |
|
397 |
|
398 if self:get_whois() == "anyone" then |
|
399 stored_stanza = st.clone(stanza); |
|
400 local actor = jid_bare(self._occupants[stanza.attr.from].jid); |
|
401 local affiliation = self:get_affiliation(actor) or "none"; |
|
402 local role = self:get_role(actor) or self:get_default_role(affiliation); |
|
403 stored_stanza:add_direct_child(st.stanza("x", { xmlns = xmlns_muc_user }) |
|
404 :tag("item", { affiliation = affiliation; role = role; jid = actor })); |
|
405 end |
375 |
406 |
376 -- Policy check |
407 -- Policy check |
377 if not archiving_enabled(self) then return end -- Don't log |
408 if not archiving_enabled(self) then return end -- Don't log |
378 |
409 |
379 -- And stash it |
410 -- And stash it |
380 local with = stanza.name |
411 local with = stanza.name |
381 if stanza.attr.type then |
412 if stanza.attr.type then |
382 with = with .. "<" .. stanza.attr.type |
413 with = with .. "<" .. stanza.attr.type |
383 end |
414 end |
384 |
415 |
385 local id = archive:append(room_node, nil, stanza, time_now(), with); |
416 local id = archive:append(room_node, nil, stored_stanza, time_now(), with); |
386 |
417 |
387 if id then |
418 if id then |
388 stanza:add_direct_child(st.stanza("stanza-id", { xmlns = xmlns_st_id, by = self.jid, id = id })); |
419 stanza:add_direct_child(st.stanza("stanza-id", { xmlns = xmlns_st_id, by = self.jid, id = id })); |
389 end |
420 end |
390 end |
421 end |