Software /
code /
prosody
Comparison
plugins/mod_muc.lua @ 1139:ed4d43c3eaf2
mod_muc: Extracted sending of occupant list into its own function
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Fri, 08 May 2009 01:27:22 +0500 |
parent | 1138:0310a0f5ce3a |
child | 1140:76bd1bd14234 |
comparison
equal
deleted
inserted
replaced
1138:0310a0f5ce3a | 1139:ed4d43c3eaf2 |
---|---|
214 core_route_stanza(component, msg); | 214 core_route_stanza(component, msg); |
215 end | 215 end |
216 end | 216 end |
217 if rooms_info:get(room, 'subject') then | 217 if rooms_info:get(room, 'subject') then |
218 core_route_stanza(component, st.message({type='groupchat', from=room, to=to}):tag("subject"):text(rooms_info:get(room, 'subject'))); | 218 core_route_stanza(component, st.message({type='groupchat', from=room, to=to}):tag("subject"):text(rooms_info:get(room, 'subject'))); |
219 end | |
220 end | |
221 function send_occupant_list(room, to) | |
222 local r = rooms:get(room); | |
223 if r then | |
224 local current_nick = jid_nick:get(to, room); | |
225 for occupant, o_data in pairs(r) do | |
226 if occupant ~= current_nick then | |
227 local pres = get_filtered_presence(o_data.sessions[o_data.jid]); | |
228 pres.attr.to, pres.attr.from = to, occupant; | |
229 pres:tag("x", {xmlns='http://jabber.org/protocol/muc#user'}) | |
230 :tag("item", {affiliation=o_data.affiliation, role=o_data.role}):up(); | |
231 core_route_stanza(component, pres); | |
232 end | |
233 end | |
219 end | 234 end |
220 end | 235 end |
221 | 236 |
222 function handle_to_occupant(origin, stanza) -- PM, vCards, etc | 237 function handle_to_occupant(origin, stanza) -- PM, vCards, etc |
223 local from, to = stanza.attr.from, stanza.attr.to; | 238 local from, to = stanza.attr.from, stanza.attr.to; |
295 if not data then -- new occupant | 310 if not data then -- new occupant |
296 data = {affiliation='none', role='participant', jid=from, sessions={[from]=get_filtered_presence(stanza)}}; | 311 data = {affiliation='none', role='participant', jid=from, sessions={[from]=get_filtered_presence(stanza)}}; |
297 end | 312 end |
298 rooms:set(room, to, data); | 313 rooms:set(room, to, data); |
299 jid_nick:set(from, room, to); | 314 jid_nick:set(from, room, to); |
300 local r = rooms:get(room); | 315 send_occupant_list(room, from); |
301 if r then | |
302 for occupant, o_data in pairs(r) do | |
303 if occupant ~= to then | |
304 local pres = get_filtered_presence(o_data.sessions[o_data.jid]); | |
305 pres.attr.to, pres.attr.from = from, occupant; | |
306 pres:tag("x", {xmlns='http://jabber.org/protocol/muc#user'}) | |
307 :tag("item", {affiliation=o_data.affiliation, role=o_data.role}):up(); | |
308 core_route_stanza(component, pres); | |
309 end | |
310 end | |
311 end | |
312 pr.attr.from = to; | 316 pr.attr.from = to; |
313 broadcast_presence_stanza(room, pr); | 317 broadcast_presence_stanza(room, pr); |
314 broadcast_history(room, from); | 318 broadcast_history(room, from); |
315 end | 319 end |
316 end | 320 end |