aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2014-04-02 18:37:52 -0400
committerdaurnimator <quae@daurnimator.com>2014-04-02 18:37:52 -0400
commit9b57ba8391c07c5c5931641725b45760823570b7 (patch)
tree7ee2e7ce94cae03045a0d34a4dbf9353dca78df6 /plugins
parent538ed6fc20ccd0b2622bc8b1b474c76db0cf8397 (diff)
downloadprosody-9b57ba8391c07c5c5931641725b45760823570b7.tar.gz
prosody-9b57ba8391c07c5c5931641725b45760823570b7.zip
plugins/muc/occupant.lib: Don't allow an unavailable session to be the primary jid
Diffstat (limited to 'plugins')
-rw-r--r--plugins/muc/occupant.lib.lua22
1 files changed, 17 insertions, 5 deletions
diff --git a/plugins/muc/occupant.lib.lua b/plugins/muc/occupant.lib.lua
index b4b12390..5cecb139 100644
--- a/plugins/muc/occupant.lib.lua
+++ b/plugins/muc/occupant.lib.lua
@@ -36,7 +36,8 @@ end
local function copy_occupant(occupant)
local sessions = {};
for full_jid, presence_stanza in pairs(occupant.sessions) do
- if presence_stanza.attr.type ~= "unavailable" then
+ -- Don't keep unavailable presences, as they'll accumulate; unless they're the primary session
+ if presence_stanza.attr.type ~= "unavailable" or full_jid == occupant.jid then
sessions[full_jid] = presence_stanza;
end
end
@@ -49,24 +50,35 @@ local function copy_occupant(occupant)
}, occupant_mt);
end
+-- finds another session to be the primary (there might not be one)
+function occupant_mt:choose_new_primary()
+ for jid, pr in self:each_session() do
+ if pr.attr.type ~= "unavailable" then
+ return jid;
+ end
+ end
+ return nil;
+end
+
function occupant_mt:set_session(real_jid, presence_stanza, replace_primary)
local pr = get_filtered_presence(presence_stanza);
pr.attr.from = self.nick;
pr.attr.to = real_jid;
self.sessions[real_jid] = pr;
- if replace_primary or self.jid == nil then
+ if replace_primary then
self.jid = real_jid;
+ elseif self.jid == nil or (pr.attr.type == "unavailable" and self.jid == real_jid) then
+ -- Only leave an unavailable presence as primary when there are no other options
+ self.jid = self:choose_new_primary() or real_jid;
end
end
function occupant_mt:remove_session(real_jid)
-- Delete original session
- local presence_stanza = self.sessions[real_jid];
self.sessions[real_jid] = nil;
if self.jid == real_jid then
- -- find another session to be the primary (might be nil)
- self.jid = next(self.sessions);
+ self.jid = self:choose_new_primary();
end
end