comparison plugins/muc/muc.lib.lua @ 1837:c07f8f3e93ea

Merge with trunk
author Matthew Wild <mwild1@gmail.com>
date Sun, 27 Sep 2009 12:28:45 +0100
parents de165b5de254
children 115f274dd17f
comparison
equal deleted inserted replaced
1836:f4c88dd32724 1837:c07f8f3e93ea
105 end 105 end
106 end 106 end
107 107
108 function room_mt:broadcast_presence(stanza, code, nick) 108 function room_mt:broadcast_presence(stanza, code, nick)
109 stanza = get_filtered_presence(stanza); 109 stanza = get_filtered_presence(stanza);
110 local data = self._occupants[stanza.attr.from]; 110 local occupant = self._occupants[stanza.attr.from];
111 stanza:tag("x", {xmlns='http://jabber.org/protocol/muc#user'}) 111 stanza:tag("x", {xmlns='http://jabber.org/protocol/muc#user'})
112 :tag("item", {affiliation=data.affiliation, role=data.role, nick=nick}):up(); 112 :tag("item", {affiliation=occupant.affiliation, role=occupant.role, nick=nick}):up();
113 if code then 113 if code then
114 stanza:tag("status", {code=code}):up(); 114 stanza:tag("status", {code=code}):up();
115 end 115 end
116 local me; 116 self:broadcast_except_nick(stanza, stanza.attr.from);
117 for occupant, o_data in pairs(self._occupants) do 117 local me = self._occupants[stanza.attr.from];
118 if occupant ~= stanza.attr.from then
119 for jid in pairs(o_data.sessions) do
120 stanza.attr.to = jid;
121 self:route_stanza(stanza);
122 end
123 else
124 me = o_data;
125 end
126 end
127 if me then 118 if me then
128 stanza:tag("status", {code='110'}); 119 stanza:tag("status", {code='110'});
129 for jid in pairs(me.sessions) do 120 for jid in pairs(me.sessions) do
130 stanza.attr.to = jid; 121 stanza.attr.to = jid;
131 self:route_stanza(stanza); 122 self:route_stanza(stanza);
222 :tag('status'):text('This participant is kicked from the room because he sent an error presence')); -- send unavailable 213 :tag('status'):text('This participant is kicked from the room because he sent an error presence')); -- send unavailable
223 end 214 end
224 elseif type == "unavailable" then -- unavailable 215 elseif type == "unavailable" then -- unavailable
225 if current_nick then 216 if current_nick then
226 log("debug", "%s leaving %s", current_nick, room); 217 log("debug", "%s leaving %s", current_nick, room);
227 local data = self._occupants[current_nick]; 218 local occupant = self._occupants[current_nick];
228 data.role = 'none'; 219 local old_session = occupant.sessions[from];
229 self:broadcast_presence(pr); 220 local new_jid = next(occupant.sessions);
230 self._occupants[current_nick] = nil; 221 if new_jid == from then new_jid = next(occupant.sessions, new_jid); end
222 if new_jid then
223 occupant.jid = new_jid;
224 occupant.sessions[from] = nil;
225 local pr = st.clone(occupant[new_jid])
226 :tag("x", {xmlns='http://jabber.org/protocol/muc#user'})
227 :tag("item", {affiliation=occupant.affiliation, role=occupant.role});
228 self:broadcast_except_nick(pr, current_nick);
229 else
230 occupant.role = 'none';
231 self:broadcast_presence(pr);
232 self._occupants[current_nick] = nil;
233 end
231 self._jid_nick[from] = nil; 234 self._jid_nick[from] = nil;
232 end 235 end
233 elseif not type then -- available 236 elseif not type then -- available
234 if current_nick then 237 if current_nick then
235 --if #pr == #stanza or current_nick ~= to then -- commented because google keeps resending directed presence 238 --if #pr == #stanza or current_nick ~= to then -- commented because google keeps resending directed presence