Software /
code /
prosody
Comparison
plugins/muc/muc.lib.lua @ 2412:e243b7c81de6
Added notification of configuration changes for MUCs
author | Rob Hoelz <rob@hoelzro.net> |
---|---|
date | Wed, 30 Dec 2009 13:26:11 -0600 |
parent | 2411:c2b6c55201af |
child | 2416:89be536aae25 |
comparison
equal
deleted
inserted
replaced
2411:c2b6c55201af | 2412:e243b7c81de6 |
---|---|
432 fields[field.attr.var] = field.tags[1][1] or ""; | 432 fields[field.attr.var] = field.tags[1][1] or ""; |
433 end | 433 end |
434 end | 434 end |
435 if fields.FORM_TYPE ~= "http://jabber.org/protocol/muc#roomconfig" then origin.send(st.error_reply(stanza, "cancel", "bad-request")); return; end | 435 if fields.FORM_TYPE ~= "http://jabber.org/protocol/muc#roomconfig" then origin.send(st.error_reply(stanza, "cancel", "bad-request")); return; end |
436 | 436 |
437 local dirty = false | |
438 | |
437 local persistent = fields['muc#roomconfig_persistentroom']; | 439 local persistent = fields['muc#roomconfig_persistentroom']; |
438 if persistent == "0" or persistent == "false" then persistent = nil; elseif persistent == "1" or persistent == "true" then persistent = true; | 440 if persistent == "0" or persistent == "false" then persistent = nil; elseif persistent == "1" or persistent == "true" then persistent = true; |
439 else origin.send(st.error_reply(stanza, "cancel", "bad-request")); return; end | 441 else origin.send(st.error_reply(stanza, "cancel", "bad-request")); return; end |
442 dirty = dirty or (self._data.persistent ~= persistent) | |
440 self._data.persistent = persistent; | 443 self._data.persistent = persistent; |
441 module:log("debug", "persistent=%s", tostring(persistent)); | 444 module:log("debug", "persistent=%s", tostring(persistent)); |
442 | 445 |
443 local public = fields['muc#roomconfig_publicroom']; | 446 local public = fields['muc#roomconfig_publicroom']; |
444 if public == "0" or public == "false" then public = nil; elseif public == "1" or public == "true" then public = true; | 447 if public == "0" or public == "false" then public = nil; elseif public == "1" or public == "true" then public = true; |
445 else origin.send(st.error_reply(stanza, "cancel", "bad-request")); return; end | 448 else origin.send(st.error_reply(stanza, "cancel", "bad-request")); return; end |
449 dirty = dirty or (self._data.hidden ~= (not public and true or nil)) | |
446 self._data.hidden = not public and true or nil; | 450 self._data.hidden = not public and true or nil; |
447 | 451 |
448 local whois = fields['muc#roomconfig_whois']; | 452 local whois = fields['muc#roomconfig_whois']; |
449 if not valid_whois[whois] then | 453 if not valid_whois[whois] then |
450 origin.send(st.error_reply(stanza, 'cancel', 'bad-request')); | 454 origin.send(st.error_reply(stanza, 'cancel', 'bad-request')); |
451 return; | 455 return; |
452 end | 456 end |
457 local whois_changed = self._data.whois ~= whois | |
453 self._data.whois = whois | 458 self._data.whois = whois |
454 module:log('debug', 'whois=%s', tostring(whois)) | 459 module:log('debug', 'whois=%s', tostring(whois)) |
455 | 460 |
456 if self.save then self:save(true); end | 461 if self.save then self:save(true); end |
457 origin.send(st.reply(stanza)); | 462 origin.send(st.reply(stanza)); |
463 | |
464 if dirty or whois_changed then | |
465 local msg = st.message({type='groupchat', from=self.jid}) | |
466 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'}):up() | |
467 | |
468 if dirty then | |
469 msg.tags[1]:tag('status', {code = '104'}) | |
470 end | |
471 if whois_changed then | |
472 local code = (whois == 'moderators') and 173 or 172 | |
473 msg.tags[1]:tag('status', {code = code}) | |
474 end | |
475 | |
476 self:broadcast_message(msg, false) | |
477 end | |
458 end | 478 end |
459 | 479 |
460 function room_mt:destroy(newjid, reason, password) | 480 function room_mt:destroy(newjid, reason, password) |
461 local pr = st.presence({type = "unavailable"}) | 481 local pr = st.presence({type = "unavailable"}) |
462 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) | 482 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) |