diff options
Diffstat (limited to 'plugins/muc/mod_muc.lua')
-rw-r--r-- | plugins/muc/mod_muc.lua | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/plugins/muc/mod_muc.lua b/plugins/muc/mod_muc.lua index c61ac238..41c8a749 100644 --- a/plugins/muc/mod_muc.lua +++ b/plugins/muc/mod_muc.lua @@ -21,11 +21,50 @@ local deregister_component = require "core.componentmanager".deregister_componen local jid_split = require "util.jid".split; local st = require "util.stanza"; local uuid_gen = require "util.uuid".generate; +local datamanager = require "util.datamanager"; local rooms = {}; +local persistent_rooms = datamanager.load(nil, muc_host, "persistent") or {}; local component; + +local function room_route_stanza(room, stanza) core_post_stanza(component, stanza); end +local function room_save(room, forced) + local node = jid_split(room.jid); + persistent_rooms[room.jid] = room._data.persistent; + module:log("debug", "1, %s, %s", room.jid, tostring(room._data.persistent)); + if room._data.persistent then + module:log("debug", "2"); + local history = room._data.history; + room._data.history = nil; + local data = { + jid = room.jid; + _data = room._data; + _affiliations = room._affiliations; + }; + datamanager.store(node, muc_host, "config", data); + room._data.history = history; + elseif forced then + module:log("debug", "3"); + datamanager.store(node, muc_host, "config", nil); + end + module:log("debug", "4"); + if forced then datamanager.store(nil, muc_host, "persistent", persistent_rooms); end +end + +for jid in pairs(persistent_rooms) do + local node = jid_split(jid); + local data = datamanager.load(node, muc_host, "config") or {}; + local room = muc_new_room(jid); + room._data = data._data; + room._affiliations = data._affiliations; + room.route_stanza = room_route_stanza; + room.save = room_save; + rooms[jid] = room; +end + local host_room = muc_new_room(muc_host); -host_room.route_stanza = function(room, stanza) core_post_stanza(component, stanza); end; +host_room.route_stanza = room_route_stanza; +host_room.save = room_save; local function get_disco_info(stanza) return st.iq({type='result', id=stanza.attr.id, from=muc_host, to=stanza.attr.from}):query("http://jabber.org/protocol/disco#info") @@ -35,7 +74,9 @@ end local function get_disco_items(stanza) local reply = st.iq({type='result', id=stanza.attr.id, from=muc_host, to=stanza.attr.from}):query("http://jabber.org/protocol/disco#items"); for jid, room in pairs(rooms) do - reply:tag("item", {jid=jid, name=jid}):up(); + if not room._data.hidden then + reply:tag("item", {jid=jid, name=jid}):up(); + end end return reply; -- TODO cache disco reply end @@ -68,7 +109,8 @@ component = register_component(muc_host, function(origin, stanza) local room = rooms[bare]; if not room then room = muc_new_room(bare); - room.route_stanza = function(room, stanza) core_post_stanza(component, stanza); end; + room.route_stanza = room_route_stanza; + room.save = room_save; rooms[bare] = room; end room:handle_stanza(origin, stanza); @@ -95,7 +137,8 @@ module.restore = function(data) room._occupants = oldroom._occupants; room._data = oldroom._data; room._affiliations = oldroom._affiliations; - room.route_stanza = function(room, stanza) core_post_stanza(component, stanza); end; + room.route_stanza = room_route_stanza; + room.save = room_save; rooms[jid] = room; end prosody.hosts[module:get_host()].muc = { rooms = rooms }; |