Software /
code /
prosody-modules
Comparison
mod_mam_muc/mod_mam_muc.lua @ 1551:5127f4db9d39
mod_mam_muc: Try to use new MUC API for getting room objects (fixes queries to not yet initialized rooms)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 08 Nov 2014 16:41:31 +0100 |
parent | 1548:d3c847070618 |
child | 1571:eed7db9f3157 |
comparison
equal
deleted
inserted
replaced
1550:1b2823b41f7f | 1551:5127f4db9d39 |
---|---|
11 local st = require "util.stanza"; | 11 local st = require "util.stanza"; |
12 local rsm = module:require "mod_mam/rsm"; | 12 local rsm = module:require "mod_mam/rsm"; |
13 local jid_bare = require "util.jid".bare; | 13 local jid_bare = require "util.jid".bare; |
14 local jid_split = require "util.jid".split; | 14 local jid_split = require "util.jid".split; |
15 local dataform = require "util.dataforms".new; | 15 local dataform = require "util.dataforms".new; |
16 | 16 local it = require"util.iterators"; |
17 | |
18 -- Support both old and new MUC code | |
17 local mod_muc = module:depends"muc"; | 19 local mod_muc = module:depends"muc"; |
18 local room_mt = mod_muc.room_mt; | 20 local room_mt = mod_muc.room_mt; |
19 local rooms = rawget(mod_muc, "rooms"); | 21 local rooms = rawget(mod_muc, "rooms"); |
22 local each_room = rawget(mod_muc, "each_room") or function() return it.values(rooms); end; | |
20 local new_muc = not rooms; | 23 local new_muc = not rooms; |
21 if new_muc then | 24 if new_muc then |
22 rooms = module:shared"muc/rooms"; | 25 rooms = module:shared"muc/rooms"; |
23 end | 26 end |
27 local get_room_from_jid = rawget(mod_muc, "get_room_from_jid") or | |
28 function (jid) | |
29 return rooms[jid]; | |
30 end | |
24 | 31 |
25 local getmetatable = getmetatable; | 32 local getmetatable = getmetatable; |
26 local function is_stanza(x) | 33 local function is_stanza(x) |
27 return getmetatable(x) == st.stanza_mt; | 34 return getmetatable(x) == st.stanza_mt; |
28 end | 35 end |
69 room.save_to_history = save_to_history; | 76 room.save_to_history = save_to_history; |
70 end | 77 end |
71 end); | 78 end); |
72 | 79 |
73 function module.load() | 80 function module.load() |
74 for _, room in pairs(rooms) do | 81 for room in each_room() do |
75 if logging_enabled(room) then | 82 if logging_enabled(room) then |
76 room.send_history = send_history; | 83 room.send_history = send_history; |
77 room.save_to_history = save_to_history; | 84 room.save_to_history = save_to_history; |
78 end | 85 end |
79 end | 86 end |
80 end | 87 end |
81 function module.unload() | 88 function module.unload() |
82 for _, room in pairs(rooms) do | 89 for room in each_room() do |
83 if room.send_history == send_history then | 90 if room.send_history == send_history then |
84 room.send_history = nil; | 91 room.send_history = nil; |
85 room.save_to_history = nil; | 92 room.save_to_history = nil; |
86 end | 93 end |
87 end | 94 end |
142 local room = stanza.attr.to; | 149 local room = stanza.attr.to; |
143 local room_node = jid_split(room); | 150 local room_node = jid_split(room); |
144 local orig_from = stanza.attr.from; | 151 local orig_from = stanza.attr.from; |
145 local query = stanza.tags[1]; | 152 local query = stanza.tags[1]; |
146 | 153 |
147 local room_obj = rooms[room]; | 154 local room_obj = get_room_from_jid(room); |
148 if not room_obj then | 155 if not room_obj then |
149 return origin.send(st.error_reply(stanza, "cancel", "item-not-found")) | 156 return origin.send(st.error_reply(stanza, "cancel", "item-not-found")) |
150 end | 157 end |
151 local from = jid_bare(orig_from); | 158 local from = jid_bare(orig_from); |
152 | 159 |