Software /
code /
prosody
Comparison
plugins/muc/subject.lib.lua @ 6429:675aea867574
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
author | daurnimator <quae@daurnimator.com> |
---|---|
date | Thu, 25 Sep 2014 17:43:00 -0400 |
parent | 6277:f2c9c36979b3 |
child | 6991:84e01dbb739e |
comparison
equal
deleted
inserted
replaced
6428:3ee09bfe16e1 | 6429:675aea867574 |
---|---|
6 -- This project is MIT/X11 licensed. Please see the | 6 -- This project is MIT/X11 licensed. Please see the |
7 -- COPYING file in the source package for more information. | 7 -- COPYING file in the source package for more information. |
8 -- | 8 -- |
9 | 9 |
10 local st = require "util.stanza"; | 10 local st = require "util.stanza"; |
11 | |
12 local muc_util = module:require "muc/util"; | |
13 local valid_roles = muc_util.valid_roles; | |
11 | 14 |
12 local function create_subject_message(from, subject) | 15 local function create_subject_message(from, subject) |
13 return st.message({from = from; type = "groupchat"}) | 16 return st.message({from = from; type = "groupchat"}) |
14 :tag("subject"):text(subject):up(); | 17 :tag("subject"):text(subject):up(); |
15 end | 18 end |
68 -- Send subject to joining user | 71 -- Send subject to joining user |
69 module:hook("muc-occupant-session-new", function(event) | 72 module:hook("muc-occupant-session-new", function(event) |
70 send_subject(event.room, event.stanza.attr.from); | 73 send_subject(event.room, event.stanza.attr.from); |
71 end, 20); | 74 end, 20); |
72 | 75 |
73 -- Role check for subject changes | 76 -- Prosody has made the decision that messages with <subject/> are exclusively subject changes |
74 module:hook("muc-subject-change", function(event) | 77 -- e.g. body will be ignored; even if the subject change was not allowed |
75 local room, stanza = event.room, event.stanza; | 78 module:hook("muc-occupant-groupchat", function(event) |
76 local occupant = room:get_occupant_by_real_jid(stanza.attr.from); | 79 local stanza = event.stanza; |
77 if occupant.role == "moderator" or | 80 local subject = stanza:get_child("subject"); |
78 ( occupant.role == "participant" and get_changesubject(room) ) then -- and participant | 81 if subject then |
79 local subject = stanza:get_child_text("subject"); | 82 local occupant = event.occupant; |
80 set_subject(room, occupant.nick, subject); | 83 -- Role check for subject changes |
81 return true; | 84 local role_rank = valid_roles[occupant and occupant.role or "none"]; |
82 else | 85 if role_rank >= valid_roles.moderator or |
83 event.origin.send(st.error_reply(stanza, "auth", "forbidden")); | 86 ( role_rank >= valid_roles.participant and get_changesubject(event.room) ) then -- and participant |
84 return true; | 87 set_subject(event.room, occupant.nick, subject:get_text()); |
88 return true; | |
89 else | |
90 event.origin.send(st.error_reply(stanza, "auth", "forbidden")); | |
91 return true; | |
92 end | |
85 end | 93 end |
86 end); | 94 end, 20); |
87 | 95 |
88 return { | 96 return { |
89 get_changesubject = get_changesubject; | 97 get_changesubject = get_changesubject; |
90 set_changesubject = set_changesubject; | 98 set_changesubject = set_changesubject; |
91 get = get_subject; | 99 get = get_subject; |