aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/muc
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2018-09-03 12:18:13 +0100
committerMatthew Wild <mwild1@gmail.com>2018-09-03 12:18:13 +0100
commit0c65168705b947c340c2a37a4a529dadeb44a3a2 (patch)
tree74c9aa8c124ebe2a9e980e84a46de4d3e89dc274 /plugins/muc
parentfb2fdc660bc596f09c860d3876bf4d4c23344fb6 (diff)
downloadprosody-0c65168705b947c340c2a37a4a529dadeb44a3a2.tar.gz
prosody-0c65168705b947c340c2a37a4a529dadeb44a3a2.zip
MUC: Add support for storing additional data with MUC affiliations
XEP-0045 registration provides examples of registering a nickname and various other details. This also allows modules to store arbitrary private data about an affiliated entity.
Diffstat (limited to 'plugins/muc')
-rw-r--r--plugins/muc/mod_muc.lua4
-rw-r--r--plugins/muc/muc.lib.lua15
2 files changed, 16 insertions, 3 deletions
diff --git a/plugins/muc/mod_muc.lua b/plugins/muc/mod_muc.lua
index b8e7b3a2..f0cd185e 100644
--- a/plugins/muc/mod_muc.lua
+++ b/plugins/muc/mod_muc.lua
@@ -107,9 +107,9 @@ do -- Monkey patch to make server admins room owners
end
local _set_affiliation = room_mt.set_affiliation;
- function room_mt:set_affiliation(actor, jid, affiliation, reason)
+ function room_mt:set_affiliation(actor, jid, affiliation, reason, data)
if affiliation ~= "owner" and is_admin(jid) then return nil, "modify", "not-acceptable"; end
- return _set_affiliation(self, actor, jid, affiliation, reason);
+ return _set_affiliation(self, actor, jid, affiliation, reason, data);
end
end
diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua
index 2d643219..f943ae7c 100644
--- a/plugins/muc/muc.lib.lua
+++ b/plugins/muc/muc.lib.lua
@@ -1198,7 +1198,8 @@ function room_mt:each_affiliation(with_affiliation)
end
end
-function room_mt:set_affiliation(actor, jid, affiliation, reason)
+function room_mt:set_affiliation(actor, jid, affiliation, reason, data)
+ module:log("debug", "data is %s", tostring(data));
if not actor then return nil, "modify", "not-acceptable"; end;
local node, host, resource = jid_split(jid);
@@ -1240,6 +1241,13 @@ function room_mt:set_affiliation(actor, jid, affiliation, reason)
-- Set in 'database'
self._affiliations[jid] = affiliation;
+ if not affiliation or data == false or (data ~= nil and next(data) == nil) then
+ module:log("debug", "Clearing affiliation data for %s", jid);
+ self._affiliation_data[jid] = nil;
+ elseif data then
+ module:log("debug", "Updating affiliation data for %s", jid);
+ self._affiliation_data[jid] = data;
+ end
-- Update roles
local role = self:get_default_role(affiliation);
@@ -1297,6 +1305,7 @@ function room_mt:set_affiliation(actor, jid, affiliation, reason)
affiliation = affiliation or "none";
reason = reason;
previous_affiliation = target_affiliation;
+ data = data and data or nil; -- coerce false to nil
in_room = next(occupants_updated) ~= nil;
});
@@ -1369,6 +1378,7 @@ function _M.new_room(jid, config)
_occupants = {};
_data = config or {};
_affiliations = {};
+ _affiliation_data = {};
}, room_mt);
end
@@ -1389,6 +1399,7 @@ function room_mt:freeze(live)
jid = self.jid;
_data = self._data;
_affiliations = self._affiliations;
+ _affiliation_data = self._affiliation_data;
};
end
if live then
@@ -1426,6 +1437,8 @@ function _M.restore_room(frozen, state)
local occupants = {};
local room_name, room_host = jid_split(room_jid);
+ room._affiliation_data = frozen._affiliation_data;
+
if frozen.jid and frozen._affiliations then
room._affiliations = frozen._affiliations;
else