Comparison

plugins/muc/muc.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 6419:84b332eacde9
child 6431:540f4e33394a
comparison
equal deleted inserted replaced
6428:3ee09bfe16e1 6429:675aea867574
802 return true; 802 return true;
803 end 803 end
804 end 804 end
805 805
806 function room_mt:handle_groupchat_to_room(origin, stanza) 806 function room_mt:handle_groupchat_to_room(origin, stanza)
807 -- Prosody has made the decision that messages with <subject/> are exclusively subject changes
808 -- e.g. body will be ignored; even if the subject change was not allowed
809 if stanza:get_child("subject") then
810 return module:fire_event("muc-subject-change", {room = self, origin = origin, stanza = stanza});
811 end
812 local from = stanza.attr.from; 807 local from = stanza.attr.from;
813 local occupant = self:get_occupant_by_real_jid(from); 808 local occupant = self:get_occupant_by_real_jid(from);
814 if not occupant then -- not in room 809 if module:fire_event("muc-occupant-groupchat", {
815 origin.send(st.error_reply(stanza, "cancel", "not-acceptable")); 810 room = self; origin = origin; stanza = stanza; from = from; occupant = occupant;
816 return true; 811 }) then return true; end
817 elseif occupant.role == "visitor" then
818 origin.send(st.error_reply(stanza, "auth", "forbidden"));
819 return true;
820 end
821 stanza.attr.from = occupant.nick; 812 stanza.attr.from = occupant.nick;
822 self:broadcast_message(stanza); 813 self:broadcast_message(stanza);
823 stanza.attr.from = from; 814 stanza.attr.from = from;
824 return true; 815 return true;
825 end 816 end
817
818 -- Role check
819 module:hook("muc-occupant-groupchat", function(event)
820 local role_rank = valid_roles[event.occupant and event.occupant.role or "none"];
821 if role_rank <= valid_roles.none then
822 event.origin.send(st.error_reply(event.stanza, "cancel", "not-acceptable"));
823 return true;
824 elseif role_rank <= valid_roles.visitor then
825 event.origin.send(st.error_reply(event.stanza, "auth", "forbidden"));
826 return true;
827 end
828 end, 50);
826 829
827 -- hack - some buggy clients send presence updates to the room rather than their nick 830 -- hack - some buggy clients send presence updates to the room rather than their nick
828 function room_mt:handle_presence_to_room(origin, stanza) 831 function room_mt:handle_presence_to_room(origin, stanza)
829 local current_nick = self:get_occupant_jid(stanza.attr.from); 832 local current_nick = self:get_occupant_jid(stanza.attr.from);
830 local handled 833 local handled