Mercurial > prosody-hg
comparison plugins/muc/muc.lib.lua @ 9237:b86c2e135797
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.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Mon, 03 Sep 2018 12:18:13 +0100 |
| parents | 11a0b32fef24 |
| children | 0c1a1172d942 |
comparison
equal
deleted
inserted
replaced
| 9236:83375ec33619 | 9237:b86c2e135797 |
|---|---|
| 1196 return jid, affiliation; | 1196 return jid, affiliation; |
| 1197 end, self._affiliations, nil | 1197 end, self._affiliations, nil |
| 1198 end | 1198 end |
| 1199 end | 1199 end |
| 1200 | 1200 |
| 1201 function room_mt:set_affiliation(actor, jid, affiliation, reason) | 1201 function room_mt:set_affiliation(actor, jid, affiliation, reason, data) |
| 1202 module:log("debug", "data is %s", tostring(data)); | |
| 1202 if not actor then return nil, "modify", "not-acceptable"; end; | 1203 if not actor then return nil, "modify", "not-acceptable"; end; |
| 1203 | 1204 |
| 1204 local node, host, resource = jid_split(jid); | 1205 local node, host, resource = jid_split(jid); |
| 1205 if not host then return nil, "modify", "not-acceptable"; end | 1206 if not host then return nil, "modify", "not-acceptable"; end |
| 1206 jid = jid_join(node, host); -- Bare | 1207 jid = jid_join(node, host); -- Bare |
| 1238 end | 1239 end |
| 1239 end | 1240 end |
| 1240 | 1241 |
| 1241 -- Set in 'database' | 1242 -- Set in 'database' |
| 1242 self._affiliations[jid] = affiliation; | 1243 self._affiliations[jid] = affiliation; |
| 1244 if not affiliation or data == false or (data ~= nil and next(data) == nil) then | |
| 1245 module:log("debug", "Clearing affiliation data for %s", jid); | |
| 1246 self._affiliation_data[jid] = nil; | |
| 1247 elseif data then | |
| 1248 module:log("debug", "Updating affiliation data for %s", jid); | |
| 1249 self._affiliation_data[jid] = data; | |
| 1250 end | |
| 1243 | 1251 |
| 1244 -- Update roles | 1252 -- Update roles |
| 1245 local role = self:get_default_role(affiliation); | 1253 local role = self:get_default_role(affiliation); |
| 1246 local role_rank = valid_roles[role or "none"]; | 1254 local role_rank = valid_roles[role or "none"]; |
| 1247 local occupants_updated = {}; -- Filled with old roles | 1255 local occupants_updated = {}; -- Filled with old roles |
| 1295 actor = actor; | 1303 actor = actor; |
| 1296 jid = jid; | 1304 jid = jid; |
| 1297 affiliation = affiliation or "none"; | 1305 affiliation = affiliation or "none"; |
| 1298 reason = reason; | 1306 reason = reason; |
| 1299 previous_affiliation = target_affiliation; | 1307 previous_affiliation = target_affiliation; |
| 1308 data = data and data or nil; -- coerce false to nil | |
| 1300 in_room = next(occupants_updated) ~= nil; | 1309 in_room = next(occupants_updated) ~= nil; |
| 1301 }); | 1310 }); |
| 1302 | 1311 |
| 1303 return true; | 1312 return true; |
| 1304 end | 1313 end |
| 1367 jid = jid; | 1376 jid = jid; |
| 1368 _jid_nick = {}; | 1377 _jid_nick = {}; |
| 1369 _occupants = {}; | 1378 _occupants = {}; |
| 1370 _data = config or {}; | 1379 _data = config or {}; |
| 1371 _affiliations = {}; | 1380 _affiliations = {}; |
| 1381 _affiliation_data = {}; | |
| 1372 }, room_mt); | 1382 }, room_mt); |
| 1373 end | 1383 end |
| 1374 | 1384 |
| 1375 local new_format = module:get_option_boolean("new_muc_storage_format", false); | 1385 local new_format = module:get_option_boolean("new_muc_storage_format", false); |
| 1376 | 1386 |
| 1387 else | 1397 else |
| 1388 frozen = { | 1398 frozen = { |
| 1389 jid = self.jid; | 1399 jid = self.jid; |
| 1390 _data = self._data; | 1400 _data = self._data; |
| 1391 _affiliations = self._affiliations; | 1401 _affiliations = self._affiliations; |
| 1402 _affiliation_data = self._affiliation_data; | |
| 1392 }; | 1403 }; |
| 1393 end | 1404 end |
| 1394 if live then | 1405 if live then |
| 1395 state = {}; | 1406 state = {}; |
| 1396 for nick, occupant in self:each_occupant() do | 1407 for nick, occupant in self:each_occupant() do |
| 1423 }; | 1434 }; |
| 1424 end | 1435 end |
| 1425 | 1436 |
| 1426 local occupants = {}; | 1437 local occupants = {}; |
| 1427 local room_name, room_host = jid_split(room_jid); | 1438 local room_name, room_host = jid_split(room_jid); |
| 1439 | |
| 1440 room._affiliation_data = frozen._affiliation_data; | |
| 1428 | 1441 |
| 1429 if frozen.jid and frozen._affiliations then | 1442 if frozen.jid and frozen._affiliations then |
| 1430 room._affiliations = frozen._affiliations; | 1443 room._affiliations = frozen._affiliations; |
| 1431 else | 1444 else |
| 1432 for jid, data in pairs(frozen) do | 1445 for jid, data in pairs(frozen) do |
