Software /
code /
prosody
Comparison
plugins/muc/muc.lib.lua @ 2411:c2b6c55201af
Add support for non-anonymous MUC rooms
author | Rob Hoelz <rob@hoelzro.net> |
---|---|
date | Tue, 29 Dec 2009 16:21:12 -0600 |
parent | 2217:838f6d546177 |
child | 2412:e243b7c81de6 |
comparison
equal
deleted
inserted
replaced
2399:0325f241a26c | 2411:c2b6c55201af |
---|---|
400 :tag("value"):text(self._data.persistent and "1" or "0"):up() | 400 :tag("value"):text(self._data.persistent and "1" or "0"):up() |
401 :up() | 401 :up() |
402 :tag("field", {type='boolean', label='Make Room Publicly Searchable?', var='muc#roomconfig_publicroom'}) | 402 :tag("field", {type='boolean', label='Make Room Publicly Searchable?', var='muc#roomconfig_publicroom'}) |
403 :tag("value"):text(self._data.hidden and "0" or "1"):up() | 403 :tag("value"):text(self._data.hidden and "0" or "1"):up() |
404 :up() | 404 :up() |
405 :tag("field", {type='list-single', label='Who May Discover Real JIDs?', var='muc#roomconfig_whois'}) | |
406 :tag("value"):text(self._data.whois or 'moderators'):up() | |
407 :tag("option", {label = 'Moderators Only'}) | |
408 :tag("value"):text('moderators'):up() | |
409 :up() | |
410 :tag("option", {label = 'Anyone'}) | |
411 :tag("value"):text('anyone'):up() | |
412 :up() | |
413 :up() | |
405 ); | 414 ); |
406 end | 415 end |
416 | |
417 local valid_whois = { | |
418 moderators = true, | |
419 anyone = true, | |
420 } | |
407 | 421 |
408 function room_mt:process_form(origin, stanza) | 422 function room_mt:process_form(origin, stanza) |
409 local query = stanza.tags[1]; | 423 local query = stanza.tags[1]; |
410 local form; | 424 local form; |
411 for _, tag in ipairs(query.tags) do if tag.name == "x" and tag.attr.xmlns == "jabber:x:data" then form = tag; break; end end | 425 for _, tag in ipairs(query.tags) do if tag.name == "x" and tag.attr.xmlns == "jabber:x:data" then form = tag; break; end end |
428 | 442 |
429 local public = fields['muc#roomconfig_publicroom']; | 443 local public = fields['muc#roomconfig_publicroom']; |
430 if public == "0" or public == "false" then public = nil; elseif public == "1" or public == "true" then public = true; | 444 if public == "0" or public == "false" then public = nil; elseif public == "1" or public == "true" then public = true; |
431 else origin.send(st.error_reply(stanza, "cancel", "bad-request")); return; end | 445 else origin.send(st.error_reply(stanza, "cancel", "bad-request")); return; end |
432 self._data.hidden = not public and true or nil; | 446 self._data.hidden = not public and true or nil; |
447 | |
448 local whois = fields['muc#roomconfig_whois']; | |
449 if not valid_whois[whois] then | |
450 origin.send(st.error_reply(stanza, 'cancel', 'bad-request')); | |
451 return; | |
452 end | |
453 self._data.whois = whois | |
454 module:log('debug', 'whois=%s', tostring(whois)) | |
433 | 455 |
434 if self.save then self:save(true); end | 456 if self.save then self:save(true); end |
435 origin.send(st.reply(stanza)); | 457 origin.send(st.reply(stanza)); |
436 end | 458 end |
437 | 459 |
733 if callback then callback(); end | 755 if callback then callback(); end |
734 self:broadcast_except_nick(p, nick); | 756 self:broadcast_except_nick(p, nick); |
735 return true; | 757 return true; |
736 end | 758 end |
737 | 759 |
760 local function _get_muc_child(stanza) | |
761 for i=#stanza.tags,1,-1 do | |
762 local tag = stanza.tags[i]; | |
763 if tag.name == "x" and tag.attr.xmlns == "http://jabber.org/protocol/muc#user" then | |
764 return tag; | |
765 end | |
766 end | |
767 end | |
768 | |
738 function room_mt:_route_stanza(stanza) | 769 function room_mt:_route_stanza(stanza) |
739 local muc_child; | 770 local muc_child; |
740 local to_occupant = self._occupants[self._jid_nick[stanza.attr.to]]; | 771 local to_occupant = self._occupants[self._jid_nick[stanza.attr.to]]; |
741 local from_occupant = self._occupants[stanza.attr.from]; | 772 local from_occupant = self._occupants[stanza.attr.from]; |
742 if stanza.name == "presence" then | 773 if stanza.name == "presence" then |
743 if to_occupant and from_occupant then | 774 if to_occupant and from_occupant then |
744 if to_occupant.role == "moderator" or jid_bare(to_occupant.jid) == jid_bare(from_occupant.jid) then | 775 if self._data.whois == 'anyone' then |
745 for i=#stanza.tags,1,-1 do | 776 muc_child = _get_muc_child(stanza) |
746 local tag = stanza.tags[i]; | 777 else |
747 if tag.name == "x" and tag.attr.xmlns == "http://jabber.org/protocol/muc#user" then | 778 if to_occupant.role == "moderator" or jid_bare(to_occupant.jid) == jid_bare(from_occupant.jid) then |
748 muc_child = tag; | 779 muc_child = _get_muc_child(stanza) |
749 break; | |
750 end | |
751 end | 780 end |
752 end | 781 end |
753 end | 782 end |
754 end | 783 end |
755 if muc_child then | 784 if muc_child then |
760 else | 789 else |
761 item.attr.jid = from_occupant.jid; | 790 item.attr.jid = from_occupant.jid; |
762 end | 791 end |
763 end | 792 end |
764 end | 793 end |
794 if self._data.whois == 'anyone' then | |
795 muc_child:tag('status', { code = '100' }); | |
796 end | |
765 end | 797 end |
766 self:route_stanza(stanza); | 798 self:route_stanza(stanza); |
767 if muc_child then | 799 if muc_child then |
768 for _, item in pairs(muc_child.tags) do | 800 for _, item in pairs(muc_child.tags) do |
769 if item.name == "item" then | 801 if item.name == "item" then |
778 function _M.new_room(jid) | 810 function _M.new_room(jid) |
779 return setmetatable({ | 811 return setmetatable({ |
780 jid = jid; | 812 jid = jid; |
781 _jid_nick = {}; | 813 _jid_nick = {}; |
782 _occupants = {}; | 814 _occupants = {}; |
783 _data = {}; | 815 _data = { |
816 whois = 'moderators', | |
817 }; | |
784 _affiliations = {}; | 818 _affiliations = {}; |
785 }, room_mt); | 819 }, room_mt); |
786 end | 820 end |
787 | 821 |
788 return _M; | 822 return _M; |