Mercurial > prosody-modules
comparison mod_mam_muc/mod_mam_muc.lua @ 3036:f7ebf8fcd602
mod_mam_muc: Remove support for Prosody trunk/0.11
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 02 Apr 2018 16:20:36 +0200 |
parents | 39994c6bb314 |
children | 264eab9d501c |
comparison
equal
deleted
inserted
replaced
3035:60ca0d03f3e3 | 3036:f7ebf8fcd602 |
---|---|
6 if module:get_host_type() ~= "component" then | 6 if module:get_host_type() ~= "component" then |
7 module:log("error", "mod_%s should be loaded only on a MUC component, not normal hosts", module.name); | 7 module:log("error", "mod_%s should be loaded only on a MUC component, not normal hosts", module.name); |
8 return; | 8 return; |
9 end | 9 end |
10 | 10 |
11 local xmlns_mam = "urn:xmpp:mam:2"; | 11 -- Note: Can't implement urn:xmpp:mam:2 because we catch messages after |
12 -- they have already been broadcast, so they can no longer be modified. | |
13 | |
14 local xmlns_mam = "urn:xmpp:mam:1"; | |
12 local xmlns_delay = "urn:xmpp:delay"; | 15 local xmlns_delay = "urn:xmpp:delay"; |
13 local xmlns_forward = "urn:xmpp:forward:0"; | 16 local xmlns_forward = "urn:xmpp:forward:0"; |
14 local xmlns_st_id = "urn:xmpp:sid:0"; | 17 local xmlns_st_id = "urn:xmpp:sid:0"; |
15 local xmlns_muc_user = "http://jabber.org/protocol/muc#user"; | 18 local xmlns_muc_user = "http://jabber.org/protocol/muc#user"; |
16 local muc_form_enable = "muc#roomconfig_enablearchiving" | 19 local muc_form_enable = "muc#roomconfig_enablearchiving" |
24 local it = require"util.iterators"; | 27 local it = require"util.iterators"; |
25 | 28 |
26 -- Support both old and new MUC code | 29 -- Support both old and new MUC code |
27 local mod_muc = module:depends"muc"; | 30 local mod_muc = module:depends"muc"; |
28 local rooms = rawget(mod_muc, "rooms"); | 31 local rooms = rawget(mod_muc, "rooms"); |
29 local each_room = rawget(mod_muc, "each_room") or function() return it.values(rooms); end; | 32 if not rooms then |
30 local new_muc = not rooms; | 33 module:log("warn", "mod_mam_muc is compatible with Prosody up to 0.10.x, use mod_muc_mam with later versions"); |
31 if new_muc then | 34 module:depends("muc_mam"); |
32 rooms = module:shared"muc/rooms"; | 35 return; |
33 else | 36 end |
34 -- COMPAT: We don't (currently?) support injecting stanza-id | 37 local each_room = function() return it.values(rooms); end; |
35 -- on Prosody 0.10 and prior, which is required by mam:2 | 38 local get_room_from_jid = function (jid) return rooms[jid]; end |
36 xmlns_mam = "urn:xmpp:mam:1"; | |
37 end | |
38 local get_room_from_jid = rawget(mod_muc, "get_room_from_jid") or | |
39 function (jid) | |
40 return rooms[jid]; | |
41 end | |
42 | 39 |
43 local is_stanza = st.is_stanza; | 40 local is_stanza = st.is_stanza; |
44 local tostring = tostring; | 41 local tostring = tostring; |
45 local time_now = os.time; | 42 local time_now = os.time; |
46 local m_min = math.min; | 43 local m_min = math.min; |
84 end | 81 end |
85 | 82 |
86 local send_history, save_to_history; | 83 local send_history, save_to_history; |
87 | 84 |
88 -- Override history methods for all rooms. | 85 -- Override history methods for all rooms. |
89 if not new_muc then -- 0.10 or older | 86 do -- 0.10 or older |
90 module:hook("muc-room-created", function (event) | 87 module:hook("muc-room-created", function (event) |
91 local room = event.room; | 88 local room = event.room; |
92 if archiving_enabled(room) then | 89 if archiving_enabled(room) then |
93 room.send_history = send_history; | 90 room.send_history = send_history; |
94 room.save_to_history = save_to_history; | 91 room.save_to_history = save_to_history; |
375 to = to; -- `to` is required to calculate the character count for `maxchars` | 372 to = to; -- `to` is required to calculate the character count for `maxchars` |
376 maxchars = maxchars, maxstanzas = maxstanzas, since = since; | 373 maxchars = maxchars, maxstanzas = maxstanzas, since = since; |
377 next_stanza = function() end; -- events should define this iterator | 374 next_stanza = function() end; -- events should define this iterator |
378 }; | 375 }; |
379 | 376 |
380 module:fire_event("muc-get-history", event); | |
381 | |
382 for msg in event.next_stanza, event do | 377 for msg in event.next_stanza, event do |
383 self:_route_stanza(msg); | 378 self:_route_stanza(msg); |
384 end | 379 end |
385 end | 380 end |
386 | 381 |
418 local with = stanza.name | 413 local with = stanza.name |
419 if stanza.attr.type then | 414 if stanza.attr.type then |
420 with = with .. "<" .. stanza.attr.type | 415 with = with .. "<" .. stanza.attr.type |
421 end | 416 end |
422 | 417 |
423 local id = archive:append(room_node, nil, stored_stanza, time_now(), with); | 418 archive:append(room_node, nil, stored_stanza, time_now(), with); |
424 | |
425 if id then | |
426 stanza:add_direct_child(st.stanza("stanza-id", { xmlns = xmlns_st_id, by = self.jid, id = id })); | |
427 end | |
428 end | |
429 | |
430 module:hook("muc-broadcast-message", function (event) | |
431 local room, stanza = event.room, event.stanza; | |
432 if stanza:get_child("body") then | |
433 save_to_history(room, stanza); | |
434 end | |
435 end); | |
436 | |
437 if module:get_option_boolean("muc_log_presences", true) then | |
438 module:hook("muc-occupant-joined", function (event) | |
439 save_to_history(event.room, st.stanza("presence", { from = event.nick })); | |
440 end); | |
441 module:hook("muc-occupant-left", function (event) | |
442 save_to_history(event.room, st.stanza("presence", { type = "unavailable", from = event.nick })); | |
443 end); | |
444 end | 419 end |
445 | 420 |
446 if not archive.delete then | 421 if not archive.delete then |
447 module:log("warn", "Storage driver %s does not support deletion", archive._provided_by); | 422 module:log("warn", "Storage driver %s does not support deletion", archive._provided_by); |
448 module:log("warn", "Archived message will persist after a room has been destroyed"); | 423 module:log("warn", "Archived message will persist after a room has been destroyed"); |