diff options
author | daurnimator <quae@daurnimator.com> | 2014-09-25 17:43:00 -0400 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2014-09-25 17:43:00 -0400 |
commit | 026a3baf9f1299aaf542961434ac314e042fbfb7 (patch) | |
tree | b03ac5b3c634f9a3c4e9e2a60f29e4390569f717 /plugins/muc/subject.lib.lua | |
parent | 733401fde5f11eec5164477a377e94c7aa109cb3 (diff) | |
download | prosody-026a3baf9f1299aaf542961434ac314e042fbfb7.tar.gz prosody-026a3baf9f1299aaf542961434ac314e042fbfb7.zip |
plugins/muc: Add muc-occupant-groupchat event
- Plugins can cancel messages before they are broadcast; and while they still have real from jid
- Use it for subject changes
- Allows for custom roles (via role_rank)
- Roles are now checked before subject
- Removed muc-subject-change event
Diffstat (limited to 'plugins/muc/subject.lib.lua')
-rw-r--r-- | plugins/muc/subject.lib.lua | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/plugins/muc/subject.lib.lua b/plugins/muc/subject.lib.lua index 34f9a5d4..d1895b4d 100644 --- a/plugins/muc/subject.lib.lua +++ b/plugins/muc/subject.lib.lua @@ -9,6 +9,9 @@ local st = require "util.stanza"; +local muc_util = module:require "muc/util"; +local valid_roles = muc_util.valid_roles; + local function create_subject_message(from, subject) return st.message({from = from; type = "groupchat"}) :tag("subject"):text(subject):up(); @@ -70,20 +73,25 @@ module:hook("muc-occupant-session-new", function(event) send_subject(event.room, event.stanza.attr.from); end, 20); --- Role check for subject changes -module:hook("muc-subject-change", function(event) - local room, stanza = event.room, event.stanza; - local occupant = room:get_occupant_by_real_jid(stanza.attr.from); - if occupant.role == "moderator" or - ( occupant.role == "participant" and get_changesubject(room) ) then -- and participant - local subject = stanza:get_child_text("subject"); - set_subject(room, occupant.nick, subject); - return true; - else - event.origin.send(st.error_reply(stanza, "auth", "forbidden")); - return true; +-- Prosody has made the decision that messages with <subject/> are exclusively subject changes +-- e.g. body will be ignored; even if the subject change was not allowed +module:hook("muc-occupant-groupchat", function(event) + local stanza = event.stanza; + local subject = stanza:get_child("subject"); + if subject then + local occupant = event.occupant; + -- Role check for subject changes + local role_rank = valid_roles[occupant and occupant.role or "none"]; + if role_rank >= valid_roles.moderator or + ( role_rank >= valid_roles.participant and get_changesubject(event.room) ) then -- and participant + set_subject(event.room, occupant.nick, subject:get_text()); + return true; + else + event.origin.send(st.error_reply(stanza, "auth", "forbidden")); + return true; + end end -end); +end, 20); return { get_changesubject = get_changesubject; |