Comparison

plugins/mod_presence.lua @ 4967:b7bcf088e723

mod_presence: Handle nil disconnection error
author Matthew Wild <mwild1@gmail.com>
date Sun, 22 Jul 2012 17:02:18 +0100
parent 4139:eef75a0c85e3
child 4993:5243b74a4cbb
comparison
equal deleted inserted replaced
4966:073eff2853a1 4967:b7bcf088e723
350 module:hook("resource-unbind", function(event) 350 module:hook("resource-unbind", function(event)
351 local session, err = event.session, event.error; 351 local session, err = event.session, event.error;
352 -- Send unavailable presence 352 -- Send unavailable presence
353 if session.presence then 353 if session.presence then
354 local pres = st.presence{ type = "unavailable" }; 354 local pres = st.presence{ type = "unavailable" };
355 if not(err) or err == "closed" then err = "connection closed"; end 355 if err then
356 pres:tag("status"):text("Disconnected: "..err):up(); 356 pres:tag("status"):text("Disconnected: "..err):up();
357 end
357 session:dispatch_stanza(pres); 358 session:dispatch_stanza(pres);
358 elseif session.directed then 359 elseif session.directed then
359 local pres = st.presence{ type = "unavailable", from = session.full_jid }; 360 local pres = st.presence{ type = "unavailable", from = session.full_jid };
360 if not(err) or err == "closed" then err = "connection closed"; end 361 if err then
361 pres:tag("status"):text("Disconnected: "..err):up(); 362 pres:tag("status"):text("Disconnected: "..err):up();
363 end
362 for jid in pairs(session.directed) do 364 for jid in pairs(session.directed) do
363 pres.attr.to = jid; 365 pres.attr.to = jid;
364 core_post_stanza(session, pres, true); 366 core_post_stanza(session, pres, true);
365 end 367 end
366 session.directed = nil; 368 session.directed = nil;