Comparison

plugins/muc/muc.lib.lua @ 6139:544f75256883

plugins/muc/muc.lib: Extra utility functions around subjects
author daurnimator <quae@daurnimator.com>
date Mon, 24 Mar 2014 13:36:43 -0400
parent 6138:fa746d834424
child 6140:e4cdb3e5d7d0
comparison
equal deleted inserted replaced
6138:fa746d834424 6139:544f75256883
242 next_stanza = function() end; -- events should define this iterator 242 next_stanza = function() end; -- events should define this iterator
243 } 243 }
244 module:fire_event("muc-get-history", event) 244 module:fire_event("muc-get-history", event)
245 for msg in event.next_stanza , event do 245 for msg in event.next_stanza , event do
246 self:_route_stanza(msg); 246 self:_route_stanza(msg);
247 end
248 end
249 function room_mt:send_subject(to)
250 if self._data['subject'] then
251 self:_route_stanza(st.message({type='groupchat', from=self._data['subject_from'] or self.jid, to=to}):tag("subject"):text(self._data['subject']));
252 end 247 end
253 end 248 end
254 249
255 function room_mt:get_disco_info(stanza) 250 function room_mt:get_disco_info(stanza)
256 local count = 0; for _ in pairs(self._occupants) do count = count + 1; end 251 local count = 0; for _ in pairs(self._occupants) do count = count + 1; end
275 for room_jid in pairs(self._occupants) do 270 for room_jid in pairs(self._occupants) do
276 reply:tag("item", {jid = room_jid, name = room_jid:match("/(.*)")}):up(); 271 reply:tag("item", {jid = room_jid, name = room_jid:match("/(.*)")}):up();
277 end 272 end
278 return reply; 273 return reply;
279 end 274 end
275
276 function room_mt:get_subject()
277 return self._data['subject'], self._data['subject_from']
278 end
279 local function create_subject_message(subject)
280 return st.message({type='groupchat'})
281 :tag('subject'):text(subject):up();
282 end
283 function room_mt:send_subject(to)
284 local from, subject = self:get_subject()
285 if subject then
286 local msg = create_subject_message(subject)
287 msg.attr.from = from
288 msg.attr.to = to
289 self:_route_stanza(msg);
290 end
291 end
280 function room_mt:set_subject(current_nick, subject) 292 function room_mt:set_subject(current_nick, subject)
281 if subject == "" then subject = nil; end 293 if subject == "" then subject = nil; end
282 self._data['subject'] = subject; 294 self._data['subject'] = subject;
283 self._data['subject_from'] = current_nick; 295 self._data['subject_from'] = current_nick;
284 if self.save then self:save(); end 296 if self.save then self:save(); end
285 local msg = st.message({type='groupchat', from=current_nick}) 297 local msg = create_subject_message(subject)
286 :tag('subject'):text(subject):up(); 298 msg.attr.from = current_nick
287 self:broadcast_message(msg, false); 299 self:broadcast_message(msg, false);
288 return true; 300 return true;
289 end 301 end
290 302
291 function room_mt:handle_kickable(origin, stanza) 303 function room_mt:handle_kickable(origin, stanza)