Comparison

plugins/muc/muc.lib.lua @ 3632:d82189efecc0

MUC: Include the user's current presence contents when broadcasting a role change.
author Waqas Hussain <waqas20@gmail.com>
date Fri, 19 Nov 2010 03:20:29 +0500
parent 3631:138f385e8246
child 3989:84792db89336
comparison
equal deleted inserted replaced
3631:138f385e8246 3632:d82189efecc0
980 if role == "none" then role = nil; end 980 if role == "none" then role = nil; end
981 if role and role ~= "moderator" and role ~= "participant" and role ~= "visitor" then return nil, "modify", "not-acceptable"; end 981 if role and role ~= "moderator" and role ~= "participant" and role ~= "visitor" then return nil, "modify", "not-acceptable"; end
982 local allowed, err_type, err_condition = self:can_set_role(actor, occupant_jid, role); 982 local allowed, err_type, err_condition = self:can_set_role(actor, occupant_jid, role);
983 if not allowed then return allowed, err_type, err_condition; end 983 if not allowed then return allowed, err_type, err_condition; end
984 local occupant = self._occupants[occupant_jid]; 984 local occupant = self._occupants[occupant_jid];
985 local p = st.presence({from = occupant_jid}) 985 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user"})
986 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"})
987 :tag("item", {affiliation=occupant.affiliation or "none", nick=select(3, jid_split(occupant_jid)), role=role or "none"}) 986 :tag("item", {affiliation=occupant.affiliation or "none", nick=select(3, jid_split(occupant_jid)), role=role or "none"})
988 :tag("reason"):text(reason or ""):up() 987 :tag("reason"):text(reason or ""):up()
989 :up(); 988 :up();
989 local presence_type = nil;
990 if not role then -- kick 990 if not role then -- kick
991 p.attr.type = "unavailable"; 991 presence_type = "unavailable";
992 self._occupants[occupant_jid] = nil; 992 self._occupants[occupant_jid] = nil;
993 for jid in pairs(occupant.sessions) do -- remove for all sessions of the nick 993 for jid in pairs(occupant.sessions) do -- remove for all sessions of the nick
994 self._jid_nick[jid] = nil; 994 self._jid_nick[jid] = nil;
995 end 995 end
996 p:tag("status", {code = "307"}):up(); 996 x:tag("status", {code = "307"}):up();
997 else 997 else
998 occupant.role = role; 998 occupant.role = role;
999 end 999 end
1000 for jid in pairs(occupant.sessions) do -- send to all sessions of the nick 1000 local bp;
1001 for jid,pres in pairs(occupant.sessions) do -- send to all sessions of the nick
1002 local p = st.clone(pres);
1003 p.attr.from = occupant_jid;
1004 p.attr.type = presence_type;
1001 p.attr.to = jid; 1005 p.attr.to = jid;
1006 p:add_child(x);
1002 self:_route_stanza(p); 1007 self:_route_stanza(p);
1008 if occupant.jid == jid then
1009 bp = p;
1010 end
1003 end 1011 end
1004 if callback then callback(); end 1012 if callback then callback(); end
1005 self:broadcast_except_nick(p, occupant_jid); 1013 if bp then
1014 self:broadcast_except_nick(bp, occupant_jid);
1015 end
1006 return true; 1016 return true;
1007 end 1017 end
1008 1018
1009 function room_mt:_route_stanza(stanza) 1019 function room_mt:_route_stanza(stanza)
1010 local muc_child; 1020 local muc_child;