aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/muc/muc.lib.lua
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2014-09-25 17:43:00 -0400
committerdaurnimator <quae@daurnimator.com>2014-09-25 17:43:00 -0400
commita1942ca7a9748be1def0bf47ee11ad32dc998c8e (patch)
treeb03ac5b3c634f9a3c4e9e2a60f29e4390569f717 /plugins/muc/muc.lib.lua
parent36cd6e26bd72d1e494c6de5a836568edfd3eda78 (diff)
downloadprosody-a1942ca7a9748be1def0bf47ee11ad32dc998c8e.tar.gz
prosody-a1942ca7a9748be1def0bf47ee11ad32dc998c8e.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/muc.lib.lua')
-rw-r--r--plugins/muc/muc.lib.lua27
1 files changed, 15 insertions, 12 deletions
diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua
index f2dde69e..35dd9eac 100644
--- a/plugins/muc/muc.lib.lua
+++ b/plugins/muc/muc.lib.lua
@@ -804,26 +804,29 @@ function room_mt:handle_owner_query_set_to_room(origin, stanza)
end
function room_mt:handle_groupchat_to_room(origin, stanza)
- -- 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
- if stanza:get_child("subject") then
- return module:fire_event("muc-subject-change", {room = self, origin = origin, stanza = stanza});
- end
local from = stanza.attr.from;
local occupant = self:get_occupant_by_real_jid(from);
- if not occupant then -- not in room
- origin.send(st.error_reply(stanza, "cancel", "not-acceptable"));
- return true;
- elseif occupant.role == "visitor" then
- origin.send(st.error_reply(stanza, "auth", "forbidden"));
- return true;
- end
+ if module:fire_event("muc-occupant-groupchat", {
+ room = self; origin = origin; stanza = stanza; from = from; occupant = occupant;
+ }) then return true; end
stanza.attr.from = occupant.nick;
self:broadcast_message(stanza);
stanza.attr.from = from;
return true;
end
+-- Role check
+module:hook("muc-occupant-groupchat", function(event)
+ local role_rank = valid_roles[event.occupant and event.occupant.role or "none"];
+ if role_rank <= valid_roles.none then
+ event.origin.send(st.error_reply(event.stanza, "cancel", "not-acceptable"));
+ return true;
+ elseif role_rank <= valid_roles.visitor then
+ event.origin.send(st.error_reply(event.stanza, "auth", "forbidden"));
+ return true;
+ end
+end, 50);
+
-- hack - some buggy clients send presence updates to the room rather than their nick
function room_mt:handle_presence_to_room(origin, stanza)
local current_nick = self:get_occupant_jid(stanza.attr.from);