plugins/muc/mod_muc.lua
changeset 5500 eeea0eb2602a
parent 5376 ba9be0be4bbb
child 5577 8b09b0d068d4
equal deleted inserted replaced
5498:2a67235e1d4d 5500:eeea0eb2602a
    26 local muc_new_room = muclib.new_room;
    26 local muc_new_room = muclib.new_room;
    27 local jid_split = require "util.jid".split;
    27 local jid_split = require "util.jid".split;
    28 local jid_bare = require "util.jid".bare;
    28 local jid_bare = require "util.jid".bare;
    29 local st = require "util.stanza";
    29 local st = require "util.stanza";
    30 local uuid_gen = require "util.uuid".generate;
    30 local uuid_gen = require "util.uuid".generate;
    31 local datamanager = require "util.datamanager";
       
    32 local um_is_admin = require "core.usermanager".is_admin;
    31 local um_is_admin = require "core.usermanager".is_admin;
    33 local hosts = prosody.hosts;
    32 local hosts = prosody.hosts;
    34 
    33 
    35 rooms = {};
    34 rooms = {};
    36 local rooms = rooms;
    35 local rooms = rooms;
    37 local persistent_rooms = datamanager.load(nil, muc_host, "persistent") or {};
    36 local persistent_rooms_storage = module:open_store("persistent");
       
    37 local persistent_rooms = persistent_rooms_storage:get() or {};
       
    38 local room_configs = module:open_store("config");
    38 
    39 
    39 -- Configurable options
    40 -- Configurable options
    40 muclib.set_max_history_length(module:get_option_number("max_history_messages"));
    41 muclib.set_max_history_length(module:get_option_number("max_history_messages"));
    41 
    42 
    42 local function is_admin(jid)
    43 local function is_admin(jid)
    64 		local data = {
    65 		local data = {
    65 			jid = room.jid;
    66 			jid = room.jid;
    66 			_data = room._data;
    67 			_data = room._data;
    67 			_affiliations = room._affiliations;
    68 			_affiliations = room._affiliations;
    68 		};
    69 		};
    69 		datamanager.store(node, muc_host, "config", data);
    70 		room_configs:set(node, data);
    70 		room._data.history = history;
    71 		room._data.history = history;
    71 	elseif forced then
    72 	elseif forced then
    72 		datamanager.store(node, muc_host, "config", nil);
    73 		room_configs:set(node, nil);
    73 		if not next(room._occupants) then -- Room empty
    74 		if not next(room._occupants) then -- Room empty
    74 			rooms[room.jid] = nil;
    75 			rooms[room.jid] = nil;
    75 		end
    76 		end
    76 	end
    77 	end
    77 	if forced then datamanager.store(nil, muc_host, "persistent", persistent_rooms); end
    78 	if forced then persistent_rooms_storage:set(nil, persistent_rooms); end
    78 end
    79 end
    79 
    80 
    80 function create_room(jid)
    81 function create_room(jid)
    81 	local room = muc_new_room(jid);
    82 	local room = muc_new_room(jid);
    82 	room.route_stanza = room_route_stanza;
    83 	room.route_stanza = room_route_stanza;
    86 end
    87 end
    87 
    88 
    88 local persistent_errors = false;
    89 local persistent_errors = false;
    89 for jid in pairs(persistent_rooms) do
    90 for jid in pairs(persistent_rooms) do
    90 	local node = jid_split(jid);
    91 	local node = jid_split(jid);
    91 	local data = datamanager.load(node, muc_host, "config");
    92 	local data = room_configs:get(node);
    92 	if data then
    93 	if data then
    93 		local room = create_room(jid);
    94 		local room = create_room(jid);
    94 		room._data = data._data;
    95 		room._data = data._data;
    95 		room._affiliations = data._affiliations;
    96 		room._affiliations = data._affiliations;
    96 	else -- missing room data
    97 	else -- missing room data
    97 		persistent_rooms[jid] = nil;
    98 		persistent_rooms[jid] = nil;
    98 		module:log("error", "Missing data for room '%s', removing from persistent room list", jid);
    99 		module:log("error", "Missing data for room '%s', removing from persistent room list", jid);
    99 		persistent_errors = true;
   100 		persistent_errors = true;
   100 	end
   101 	end
   101 end
   102 end
   102 if persistent_errors then datamanager.store(nil, muc_host, "persistent", persistent_rooms); end
   103 if persistent_errors then persistent_rooms_storage:set(nil, persistent_rooms); end
   103 
   104 
   104 local host_room = muc_new_room(muc_host);
   105 local host_room = muc_new_room(muc_host);
   105 host_room.route_stanza = room_route_stanza;
   106 host_room.route_stanza = room_route_stanza;
   106 host_room.save = room_save;
   107 host_room.save = room_save;
   107 
   108