Comparison

plugins/mod_muc.lua @ 757:f77843f31c7d

mod_muc: Add 'nick' to unavailable presence of nick changes. Thanks to Asterix for spotting :)
author Matthew Wild <mwild1@gmail.com>
date Thu, 29 Jan 2009 20:49:32 +0000
parent 756:2ca5fa47f317
child 779:ec0eadf4e9ff
comparison
equal deleted inserted replaced
756:2ca5fa47f317 757:f77843f31c7d
93 save_room(); 93 save_room();
94 broadcast_message(current_nick, room, subject or "", nil); 94 broadcast_message(current_nick, room, subject or "", nil);
95 return true; 95 return true;
96 end 96 end
97 97
98 function broadcast_presence(type, from, room, code) 98 function broadcast_presence(type, from, room, code, newnick)
99 local data = rooms:get(room, from); 99 local data = rooms:get(room, from);
100 local stanza = st.presence({type=type, from=from}) 100 local stanza = st.presence({type=type, from=from})
101 :tag("x", {xmlns='http://jabber.org/protocol/muc#user'}) 101 :tag("x", {xmlns='http://jabber.org/protocol/muc#user'})
102 :tag("item", {affiliation=data.affiliation, role=data.role}):up(); 102 :tag("item", {affiliation=data.affiliation, role=data.role, nick = newnick}):up();
103 if code then 103 if code then
104 stanza:tag("status", {code=code}):up(); 104 stanza:tag("status", {code=code}):up();
105 end 105 end
106 local me; 106 local me;
107 local r = rooms:get(room); 107 local r = rooms:get(room);
161 else -- change nick 161 else -- change nick
162 if rooms:get(room, to) then 162 if rooms:get(room, to) then
163 origin.send(st.error_reply(stanza, "cancel", "conflict")); 163 origin.send(st.error_reply(stanza, "cancel", "conflict"));
164 else 164 else
165 local data = rooms:get(room, current_nick); 165 local data = rooms:get(room, current_nick);
166 broadcast_presence('unavailable', current_nick, room, '303'); 166 local to_nick = select(3, jid_split(to));
167 rooms:remove(room, current_nick); 167 if to_nick then
168 rooms:set(room, to, data); 168 broadcast_presence('unavailable', current_nick, room, '303', to_nick);
169 jid_nick:set(from, room, to); 169 rooms:remove(room, current_nick);
170 broadcast_presence(nil, to, room); 170 rooms:set(room, to, data);
171 jid_nick:set(from, room, to);
172 broadcast_presence(nil, to, room, nil);
173 else
174 --TODO: malformed-jid
175 end
171 end 176 end
172 end 177 end
173 else -- enter room 178 else -- enter room
174 if rooms:get(room, to) then 179 if rooms:get(room, to) then
175 origin.send(st.error_reply(stanza, "cancel", "conflict")); 180 origin.send(st.error_reply(stanza, "cancel", "conflict"));