Software /
code /
prosody
Comparison
plugins/muc/muc.lib.lua @ 6129:6c66571ab0f9
plugins/muc: Have utility methods for locking the room
author | daurnimator <quae@daurnimator.com> |
---|---|
date | Thu, 20 Mar 2014 11:06:10 -0400 |
parent | 6128:8a71a1c34202 |
child | 6130:c95d9132592a |
comparison
equal
deleted
inserted
replaced
6128:8a71a1c34202 | 6129:6c66571ab0f9 |
---|---|
81 elseif not affiliation then | 81 elseif not affiliation then |
82 if not self:get_members_only() then | 82 if not self:get_members_only() then |
83 return self:get_moderated() and "visitor" or "participant"; | 83 return self:get_moderated() and "visitor" or "participant"; |
84 end | 84 end |
85 end | 85 end |
86 end | |
87 | |
88 function room_mt:lock() | |
89 self.locked = true | |
90 end | |
91 function room_mt:unlock() | |
92 module:fire_event("muc-room-unlocked", { room = self }); | |
93 self.locked = nil | |
94 end | |
95 function room_mt:is_locked() | |
96 return not not self.locked | |
86 end | 97 end |
87 | 98 |
88 function room_mt:broadcast_presence(stanza, sid, code, nick) | 99 function room_mt:broadcast_presence(stanza, sid, code, nick) |
89 stanza = get_filtered_presence(stanza); | 100 stanza = get_filtered_presence(stanza); |
90 local occupant = self._occupants[stanza.attr.from]; | 101 local occupant = self._occupants[stanza.attr.from]; |
463 function room_mt:handle_join(origin, stanza) | 474 function room_mt:handle_join(origin, stanza) |
464 local from, to = stanza.attr.from, stanza.attr.to; | 475 local from, to = stanza.attr.from, stanza.attr.to; |
465 log("debug", "%s joining as %s", from, to); | 476 log("debug", "%s joining as %s", from, to); |
466 if not next(self._affiliations) then -- new room, no owners | 477 if not next(self._affiliations) then -- new room, no owners |
467 self._affiliations[jid_bare(from)] = "owner"; | 478 self._affiliations[jid_bare(from)] = "owner"; |
468 if self.locked and not stanza:get_child("x", "http://jabber.org/protocol/muc") then | 479 if self:is_locked() and not stanza:get_child("x", "http://jabber.org/protocol/muc") then |
469 self.locked = nil; -- Older groupchat protocol doesn't lock | 480 self:unlock(); -- Older groupchat protocol doesn't lock |
470 end | 481 end |
471 elseif self.locked then -- Deny entry | 482 elseif self:is_locked() then -- Deny entry |
472 origin.send(st.error_reply(stanza, "cancel", "item-not-found")); | 483 origin.send(st.error_reply(stanza, "cancel", "item-not-found")); |
473 return true; | 484 return true; |
474 end | 485 end |
475 local affiliation = self:get_affiliation(from); | 486 local affiliation = self:get_affiliation(from); |
476 local role = self:get_default_role(affiliation) | 487 local role = self:get_default_role(affiliation) |
492 end | 503 end |
493 pr:tag("status", {code='110'}):up(); | 504 pr:tag("status", {code='110'}):up(); |
494 if self:get_whois() == 'anyone' then | 505 if self:get_whois() == 'anyone' then |
495 pr:tag("status", {code='100'}):up(); | 506 pr:tag("status", {code='100'}):up(); |
496 end | 507 end |
497 if self.locked then | 508 if self:is_locked() then |
498 pr:tag("status", {code='201'}):up(); | 509 pr:tag("status", {code='201'}):up(); |
499 end | 510 end |
500 pr.attr.to = from; | 511 pr.attr.to = from; |
501 self:_route_stanza(pr); | 512 self:_route_stanza(pr); |
502 self:send_history(from, stanza); | 513 self:send_history(from, stanza); |
775 handle_option("historylength", "muc#roomconfig_historylength"); | 786 handle_option("historylength", "muc#roomconfig_historylength"); |
776 handle_option("whois", "muc#roomconfig_whois", valid_whois); | 787 handle_option("whois", "muc#roomconfig_whois", valid_whois); |
777 handle_option("password", "muc#roomconfig_roomsecret"); | 788 handle_option("password", "muc#roomconfig_roomsecret"); |
778 | 789 |
779 if self.save then self:save(true); end | 790 if self.save then self:save(true); end |
780 if self.locked then | 791 if self:is_locked() then |
781 module:fire_event("muc-room-unlocked", { room = self }); | 792 self:unlock(); |
782 self.locked = nil; | |
783 end | 793 end |
784 origin.send(st.reply(stanza)); | 794 origin.send(st.reply(stanza)); |
785 | 795 |
786 if next(changed) then | 796 if next(changed) then |
787 local msg = st.message({type='groupchat', from=self.jid}) | 797 local msg = st.message({type='groupchat', from=self.jid}) |
1265 local _M = {}; -- module "muc" | 1275 local _M = {}; -- module "muc" |
1266 | 1276 |
1267 function _M.new_room(jid, config) | 1277 function _M.new_room(jid, config) |
1268 return setmetatable({ | 1278 return setmetatable({ |
1269 jid = jid; | 1279 jid = jid; |
1280 locked = nil; | |
1270 _jid_nick = {}; | 1281 _jid_nick = {}; |
1271 _occupants = {}; | 1282 _occupants = {}; |
1272 _data = { | 1283 _data = { |
1273 whois = 'moderators'; | 1284 whois = 'moderators'; |
1274 history_length = math.min((config and config.history_length) | 1285 history_length = math.min((config and config.history_length) |