aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/muc
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/muc')
-rw-r--r--plugins/muc/mod_muc.lua22
-rw-r--r--plugins/muc/muc.lib.lua35
2 files changed, 32 insertions, 25 deletions
diff --git a/plugins/muc/mod_muc.lua b/plugins/muc/mod_muc.lua
index 0df8b790..7861092c 100644
--- a/plugins/muc/mod_muc.lua
+++ b/plugins/muc/mod_muc.lua
@@ -28,13 +28,14 @@ local jid_split = require "util.jid".split;
local jid_bare = require "util.jid".bare;
local st = require "util.stanza";
local uuid_gen = require "util.uuid".generate;
-local datamanager = require "util.datamanager";
local um_is_admin = require "core.usermanager".is_admin;
-local hosts = hosts;
+local hosts = prosody.hosts;
rooms = {};
local rooms = rooms;
-local persistent_rooms = datamanager.load(nil, muc_host, "persistent") or {};
+local persistent_rooms_storage = module:open_store("persistent");
+local persistent_rooms = persistent_rooms_storage:get() or {};
+local room_configs = module:open_store("config");
-- Configurable options
muclib.set_max_history_length(module:get_option_number("max_history_messages"));
@@ -66,15 +67,15 @@ local function room_save(room, forced)
_data = room._data;
_affiliations = room._affiliations;
};
- datamanager.store(node, muc_host, "config", data);
+ room_configs:set(node, data);
room._data.history = history;
elseif forced then
- datamanager.store(node, muc_host, "config", nil);
+ room_configs:set(node, nil);
if not next(room._occupants) then -- Room empty
rooms[room.jid] = nil;
end
end
- if forced then datamanager.store(nil, muc_host, "persistent", persistent_rooms); end
+ if forced then persistent_rooms_storage:set(nil, persistent_rooms); end
end
function create_room(jid)
@@ -88,7 +89,7 @@ end
local persistent_errors = false;
for jid in pairs(persistent_rooms) do
local node = jid_split(jid);
- local data = datamanager.load(node, muc_host, "config");
+ local data = room_configs:get(node);
if data then
local room = create_room(jid);
room._data = data._data;
@@ -99,7 +100,7 @@ for jid in pairs(persistent_rooms) do
persistent_errors = true;
end
end
-if persistent_errors then datamanager.store(nil, muc_host, "persistent", persistent_rooms); end
+if persistent_errors then persistent_rooms_storage:set(nil, persistent_rooms); end
local host_room = muc_new_room(muc_host);
host_room.route_stanza = room_route_stanza;
@@ -126,9 +127,10 @@ local function handle_to_domain(event)
if type == "error" or type == "result" then return; end
if stanza.name == "iq" and type == "get" then
local xmlns = stanza.tags[1].attr.xmlns;
- if xmlns == "http://jabber.org/protocol/disco#info" then
+ local node = stanza.tags[1].attr.node;
+ if xmlns == "http://jabber.org/protocol/disco#info" and not node then
origin.send(get_disco_info(stanza));
- elseif xmlns == "http://jabber.org/protocol/disco#items" then
+ elseif xmlns == "http://jabber.org/protocol/disco#items" and not node then
origin.send(get_disco_items(stanza));
elseif xmlns == "http://jabber.org/protocol/muc#unique" then
origin.send(st.reply(stanza):tag("unique", {xmlns = xmlns}):text(uuid_gen())); -- FIXME Random UUIDs can theoretically have collisions
diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua
index 16a0238d..a5aba3c8 100644
--- a/plugins/muc/muc.lib.lua
+++ b/plugins/muc/muc.lib.lua
@@ -88,6 +88,10 @@ local function getText(stanza, path) return getUsingPath(stanza, path, true); en
local room_mt = {};
room_mt.__index = room_mt;
+function room_mt:__tostring()
+ return "MUC room ("..self.jid..")";
+end
+
function room_mt:get_default_role(affiliation)
if affiliation == "owner" or affiliation == "admin" then
return "moderator";
@@ -576,10 +580,9 @@ function room_mt:send_form(origin, stanza)
end
function room_mt:get_form_layout()
- local title = "Configuration for "..self.jid;
- return dataform.new({
- title = title,
- instructions = title,
+ local form = dataform.new({
+ title = "Configuration for "..self.jid,
+ instructions = "Complete and submit this form to configure the room.",
{
name = 'FORM_TYPE',
type = 'hidden',
@@ -649,6 +652,7 @@ function room_mt:get_form_layout()
value = tostring(self:get_historylength())
}
});
+ return module:fire_event("muc-config-form", { room = self, form = form }) or form;
end
local valid_whois = {
@@ -669,6 +673,10 @@ function room_mt:process_form(origin, stanza)
local dirty = false
+ local event = { room = self, fields = fields, changed = dirty };
+ module:fire_event("muc-config-submitted", event);
+ dirty = event.changed or dirty;
+
local name = fields['muc#roomconfig_roomname'];
if name ~= self:get_name() then
self:set_name(name);
@@ -765,13 +773,9 @@ function room_mt:handle_to_room(origin, stanza) -- presence changes and groupcha
local type = stanza.attr.type;
local xmlns = stanza.tags[1] and stanza.tags[1].attr.xmlns;
if stanza.name == "iq" then
- if xmlns == "http://jabber.org/protocol/disco#info" and type == "get" then
- if stanza.tags[1].attr.node then
- origin.send(st.error_reply(stanza, "cancel", "feature-not-implemented"));
- else
- origin.send(self:get_disco_info(stanza));
- end
- elseif xmlns == "http://jabber.org/protocol/disco#items" and type == "get" then
+ if xmlns == "http://jabber.org/protocol/disco#info" and type == "get" and not stanza.tags[1].attr.node then
+ origin.send(self:get_disco_info(stanza));
+ elseif xmlns == "http://jabber.org/protocol/disco#items" and type == "get" and not stanza.tags[1].attr.node then
origin.send(self:get_disco_items(stanza));
elseif xmlns == "http://jabber.org/protocol/muc#admin" then
local actor = stanza.attr.from;
@@ -896,7 +900,7 @@ function room_mt:handle_to_room(origin, stanza) -- presence changes and groupcha
origin.send(st.error_reply(stanza, "auth", "forbidden"));
end
else
- self:broadcast_message(stanza, self:get_historylength() > 0);
+ self:broadcast_message(stanza, self:get_historylength() > 0 and stanza:get_child("body"));
end
stanza.attr.from = from;
end
@@ -987,7 +991,7 @@ function room_mt:set_affiliation(actor, jid, affiliation, callback, reason)
return true;
end
if actor_affiliation ~= "owner" then
- if actor_affiliation ~= "admin" or target_affiliation == "owner" or target_affiliation == "admin" then
+ if affiliation == "owner" or affiliation == "admin" or actor_affiliation ~= "admin" or target_affiliation == "owner" or target_affiliation == "admin" then
return nil, "cancel", "not-allowed";
end
elseif target_affiliation == "owner" and jid_bare(actor) == jid then -- self change
@@ -1049,11 +1053,12 @@ function room_mt:get_role(nick)
return session and session.role or nil;
end
function room_mt:can_set_role(actor_jid, occupant_jid, role)
- local actor = self._occupants[self._jid_nick[actor_jid]];
local occupant = self._occupants[occupant_jid];
-
if not occupant or not actor then return nil, "modify", "not-acceptable"; end
+ if actor_jid == true then return true; end
+
+ local actor = self._occupants[self._jid_nick[actor_jid]];
if actor.role == "moderator" then
if occupant.affiliation ~= "owner" and occupant.affiliation ~= "admin" then
if actor.affiliation == "owner" or actor.affiliation == "admin" then