# HG changeset patch # User daurnimator # Date 1395682603 14400 # Node ID 544f75256883ca6f8968720df198ec92fb6ac88a # Parent fa746d83442449826cbaa94a727e748f576ed6b2 plugins/muc/muc.lib: Extra utility functions around subjects diff -r fa746d834424 -r 544f75256883 plugins/muc/muc.lib.lua --- a/plugins/muc/muc.lib.lua Mon Mar 24 13:34:06 2014 -0400 +++ b/plugins/muc/muc.lib.lua Mon Mar 24 13:36:43 2014 -0400 @@ -246,11 +246,6 @@ self:_route_stanza(msg); end end -function room_mt:send_subject(to) - if self._data['subject'] then - self:_route_stanza(st.message({type='groupchat', from=self._data['subject_from'] or self.jid, to=to}):tag("subject"):text(self._data['subject'])); - end -end function room_mt:get_disco_info(stanza) local count = 0; for _ in pairs(self._occupants) do count = count + 1; end @@ -277,13 +272,30 @@ end return reply; end + +function room_mt:get_subject() + return self._data['subject'], self._data['subject_from'] +end +local function create_subject_message(subject) + return st.message({type='groupchat'}) + :tag('subject'):text(subject):up(); +end +function room_mt:send_subject(to) + local from, subject = self:get_subject() + if subject then + local msg = create_subject_message(subject) + msg.attr.from = from + msg.attr.to = to + self:_route_stanza(msg); + end +end function room_mt:set_subject(current_nick, subject) if subject == "" then subject = nil; end self._data['subject'] = subject; self._data['subject_from'] = current_nick; if self.save then self:save(); end - local msg = st.message({type='groupchat', from=current_nick}) - :tag('subject'):text(subject):up(); + local msg = create_subject_message(subject) + msg.attr.from = current_nick self:broadcast_message(msg, false); return true; end