From 567fc4966c2c555b1b649ef9c25c2abb14e592b8 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 25 Sep 2009 12:35:09 +0500 Subject: MUC: Refactored to remove some duplicate code. --- plugins/muc/muc.lib.lua | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua index 6917b21a..260ce422 100644 --- a/plugins/muc/muc.lib.lua +++ b/plugins/muc/muc.lib.lua @@ -113,17 +113,8 @@ function room_mt:broadcast_presence(stanza, code, nick) if code then stanza:tag("status", {code=code}):up(); end - local me; - for occupant, o_data in pairs(self._occupants) do - if occupant ~= stanza.attr.from then - for jid in pairs(o_data.sessions) do - stanza.attr.to = jid; - self:route_stanza(stanza); - end - else - me = o_data; - end - end + self:broadcast_except_nick(stanza, stanza.attr.from); + local me = self._occupants[stanza.attr.from]; if me then stanza:tag("status", {code='110'}); for jid in pairs(me.sessions) do -- cgit v1.2.3 From 9547770360bcec49cd8959c183deeb02538e57ac Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 25 Sep 2009 12:36:11 +0500 Subject: MUC: Renamed a variable name. --- plugins/muc/muc.lib.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua index 260ce422..9a3e720f 100644 --- a/plugins/muc/muc.lib.lua +++ b/plugins/muc/muc.lib.lua @@ -107,9 +107,9 @@ end function room_mt:broadcast_presence(stanza, code, nick) stanza = get_filtered_presence(stanza); - local data = self._occupants[stanza.attr.from]; + local occupant = self._occupants[stanza.attr.from]; stanza:tag("x", {xmlns='http://jabber.org/protocol/muc#user'}) - :tag("item", {affiliation=data.affiliation, role=data.role, nick=nick}):up(); + :tag("item", {affiliation=occupant.affiliation, role=occupant.role, nick=nick}):up(); if code then stanza:tag("status", {code=code}):up(); end -- cgit v1.2.3 From 02cc8144246e44d0ef272b57e50abf68951b7010 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 25 Sep 2009 12:39:28 +0500 Subject: MUC: Added multi-session support to the room-exiting occupant use case. --- plugins/muc/muc.lib.lua | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua index 9a3e720f..35bde4c6 100644 --- a/plugins/muc/muc.lib.lua +++ b/plugins/muc/muc.lib.lua @@ -215,10 +215,22 @@ function room_mt:handle_to_occupant(origin, stanza) -- PM, vCards, etc elseif type == "unavailable" then -- unavailable if current_nick then log("debug", "%s leaving %s", current_nick, room); - local data = self._occupants[current_nick]; - data.role = 'none'; - self:broadcast_presence(pr); - self._occupants[current_nick] = nil; + local occupant = self._occupants[current_nick]; + local old_session = occupant.sessions[from]; + local new_jid = next(occupant.sessions); + if new_jid == from then new_jid = next(occupant.sessions, new_jid); end + if new_jid then + occupant.jid = new_jid; + occupant.sessions[from] = nil; + local pr = st.clone(occupant[new_jid]) + :tag("x", {xmlns='http://jabber.org/protocol/muc#user'}) + :tag("item", {affiliation=occupant.affiliation, role=occupant.role}); + self:broadcast_except_nick(pr, current_nick); + else + occupant.role = 'none'; + self:broadcast_presence(pr); + self._occupants[current_nick] = nil; + end self._jid_nick[from] = nil; end elseif not type then -- available -- cgit v1.2.3