From 7138d1090a1747232a53761903933ccffd584837 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 14 Jan 2011 15:52:36 +0100 Subject: MUC: Add option to allow participants to change the subject. --- plugins/muc/muc.lib.lua | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua index 7a069852..8bbf0df2 100644 --- a/plugins/muc/muc.lib.lua +++ b/plugins/muc/muc.lib.lua @@ -327,6 +327,16 @@ end function room_mt:is_hidden() return self._data.hidden; end +function room_mt:set_changesubject(changesubject) + changesubject = changesubject and true or nil; + if self._data.changesubject ~= changesubject then + self._data.changesubject = changesubject; + if self.save then self:save(true); end + end +end +function room_mt:get_changesubject() + return self._data.changesubject; +end function room_mt:handle_to_occupant(origin, stanza) -- PM, vCards, etc local from, to = stanza.attr.from, stanza.attr.to; @@ -564,6 +574,12 @@ function room_mt:get_form_layout() label = 'Make Room Publicly Searchable?', value = not self:is_hidden() }, + { + name = 'muc#roomconfig_changesubject', + type = 'boolean', + label = 'Allow Occupants to Change Subject?', + value = self:get_changesubject() + }, { name = 'muc#roomconfig_whois', type = 'list-single', @@ -637,6 +653,10 @@ function room_mt:process_form(origin, stanza) local public = fields['muc#roomconfig_publicroom']; dirty = dirty or (self:is_hidden() ~= (not public and true or nil)) + local changesubject = fields['muc#roomconfig_changesubject']; + dirty = dirty or (self:get_changesubject() ~= (not changesubject and true or nil)) + module:log('debug', 'changesubject=%s', changesubject and "true" or "false") + local whois = fields['muc#roomconfig_whois']; if not valid_whois[whois] then origin.send(st.error_reply(stanza, 'cancel', 'bad-request', "Invalid value for 'whois'")); @@ -654,6 +674,7 @@ function room_mt:process_form(origin, stanza) self:set_members_only(membersonly); self:set_persistent(persistent); self:set_hidden(not public); + self:set_changesubject(changesubject); if self.save then self:save(true); end origin.send(st.reply(stanza)); @@ -817,7 +838,8 @@ function room_mt:handle_to_room(origin, stanza) -- presence changes and groupcha stanza.attr.from = current_nick; local subject = getText(stanza, {"subject"}); if subject then - if occupant.role == "moderator" then + if occupant.role == "moderator" or + ( self._data.changesubject and occupant.role == "participant" ) then -- and participant self:set_subject(current_nick, subject); -- TODO use broadcast_message_stanza else stanza.attr.from = from; -- cgit v1.2.3