Comparison

plugins/muc/muc.lib.lua @ 6223:2a7ce69844ca

plugins/muc/muc.lib: Refactor subject logic; fix bug of mixed up subject/author
author daurnimator <quae@daurnimator.com>
date Tue, 15 Apr 2014 18:20:56 -0400
parent 6222:355b29881117
child 6224:2a9aff163545
comparison
equal deleted inserted replaced
6222:355b29881117 6223:2a7ce69844ca
295 end 295 end
296 return reply; 296 return reply;
297 end 297 end
298 298
299 function room_mt:get_subject() 299 function room_mt:get_subject()
300 return self._data['subject'], self._data['subject_from'] 300 return self._data.subject_from, self._data.subject;
301 end 301 end
302 local function create_subject_message(from, subject) 302 local function create_subject_message(from, subject)
303 return st.message({from = from; type = "groupchat"}) 303 return st.message({from = from; type = "groupchat"})
304 :tag('subject'):text(subject):up(); 304 :tag('subject'):text(subject):up();
305 end 305 end
876 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); 876 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
877 return true; 877 return true;
878 end 878 end
879 end 879 end
880 880
881 module:hook("muc-subject-change", function(event)
882 local room, stanza = event.room, event.stanza;
883 local occupant = room:get_occupant_by_real_jid(stanza.attr.from);
884 if occupant.role == "moderator" or
885 ( occupant.role == "participant" and room:get_changesubject() ) then -- and participant
886 local subject = stanza:get_child_text("subject");
887 room:set_subject(occupant.nick, subject);
888 else
889 event.origin.send(st.error_reply(stanza, "auth", "forbidden"));
890 end
891 return true;
892 end);
893
881 function room_mt:handle_groupchat_to_room(origin, stanza) 894 function room_mt:handle_groupchat_to_room(origin, stanza)
895 -- Prosody has made the decision that messages with <subject/> are exclusively subject changes
896 -- e.g. body will be ignored; even if the subject change was not allowed
897 if stanza:get_child("subject") then
898 return module:fire_event("muc-subject-change", {room = self, origin = origin, stanza = stanza});
899 end
882 local from = stanza.attr.from; 900 local from = stanza.attr.from;
883 local occupant = self:get_occupant_by_real_jid(from); 901 local occupant = self:get_occupant_by_real_jid(from);
884 if not occupant then -- not in room 902 if not occupant then -- not in room
885 origin.send(st.error_reply(stanza, "cancel", "not-acceptable")); 903 origin.send(st.error_reply(stanza, "cancel", "not-acceptable"));
886 return true; 904 return true;
887 elseif occupant.role == "visitor" then 905 elseif occupant.role == "visitor" then
888 origin.send(st.error_reply(stanza, "auth", "forbidden")); 906 origin.send(st.error_reply(stanza, "auth", "forbidden"));
889 return true; 907 return true;
890 else 908 end
891 local from = stanza.attr.from; 909 stanza.attr.from = occupant.nick;
892 stanza.attr.from = occupant.nick; 910 self:broadcast_message(stanza);
893 local subject = stanza:get_child_text("subject"); 911 stanza.attr.from = from;
894 if subject then 912 return true;
895 if occupant.role == "moderator" or
896 ( self:get_changesubject() and occupant.role == "participant" ) then -- and participant
897 self:set_subject(occupant.nick, subject);
898 else
899 stanza.attr.from = from;
900 origin.send(st.error_reply(stanza, "auth", "forbidden"));
901 end
902 else
903 self:broadcast_message(stanza);
904 end
905 stanza.attr.from = from;
906 return true;
907 end
908 end 913 end
909 914
910 -- hack - some buggy clients send presence updates to the room rather than their nick 915 -- hack - some buggy clients send presence updates to the room rather than their nick
911 function room_mt:handle_presence_to_room(origin, stanza) 916 function room_mt:handle_presence_to_room(origin, stanza)
912 local current_nick = self:get_occupant_jid(stanza.attr.from); 917 local current_nick = self:get_occupant_jid(stanza.attr.from);