Comparison

plugins/muc/muc.lib.lua @ 7426:3a90e9732204

Backed out changeset 63141a85beea, broke multi-session nicks
author Kim Alvefur <zash@zash.se>
date Sat, 14 May 2016 22:36:37 +0200
parent 7423:63141a85beea
child 7427:bf43a08e5a74
comparison
equal deleted inserted replaced
7425:0bb98138dacf 7426:3a90e9732204
444 return true; 444 return true;
445 end 445 end
446 446
447 function room_mt:handle_normal_presence(origin, stanza) 447 function room_mt:handle_normal_presence(origin, stanza)
448 local type = stanza.attr.type; 448 local type = stanza.attr.type;
449 local muc_x = stanza:get_child("x", "http://jabber.org/protocol/muc");
450 local real_jid = stanza.attr.from; 449 local real_jid = stanza.attr.from;
451 local bare_jid = jid_bare(real_jid); 450 local bare_jid = jid_bare(real_jid);
452 local orig_occupant = self:get_occupant_by_real_jid(real_jid); 451 local orig_occupant = self:get_occupant_by_real_jid(real_jid);
453 if type == "unavailable" and orig_occupant == nil then return true; end -- Unavailable from someone not in the room 452 if type == "unavailable" and orig_occupant == nil then return true; end -- Unavailable from someone not in the room
454 local is_first_dest_session; 453 local is_first_dest_session;
455 local dest_occupant; 454 local dest_occupant;
456 if type == "unavailable" then -- luacheck: ignore 542 455 if type == "unavailable" then -- luacheck: ignore 542
457 -- FIXME Why the empty if branch? 456 -- FIXME Why the empty if branch?
458 -- dest_occupant = nil 457 -- dest_occupant = nil
459 elseif orig_occupant and not muc_x and orig_occupant.nick == stanza.attr.to then -- Just a presence update 458 elseif orig_occupant and orig_occupant.nick == stanza.attr.to then -- Just a presence update
460 log("debug", "presence update for %s from session %s", orig_occupant.nick, real_jid); 459 log("debug", "presence update for %s from session %s", orig_occupant.nick, real_jid);
461 dest_occupant = orig_occupant; 460 dest_occupant = orig_occupant;
462 else 461 else
463 local dest_jid = stanza.attr.to; 462 local dest_jid = stanza.attr.to;
464 dest_occupant = self:get_occupant_by_nick(dest_jid); 463 dest_occupant = self:get_occupant_by_nick(dest_jid);
465 if muc_x then 464 if dest_occupant == nil then
466 dest_occupant = self:new_occupant(bare_jid, dest_jid);
467 if dest_occupant == nil then
468 is_first_dest_session = true;
469 end
470 elseif dest_occupant == nil then
471 log("debug", "no occupant found for %s; creating new occupant object for %s", dest_jid, real_jid); 465 log("debug", "no occupant found for %s; creating new occupant object for %s", dest_jid, real_jid);
472 is_first_dest_session = true; 466 is_first_dest_session = true;
473 dest_occupant = self:new_occupant(bare_jid, dest_jid); 467 dest_occupant = self:new_occupant(bare_jid, dest_jid);
474 else 468 else
475 is_first_dest_session = false; 469 is_first_dest_session = false;
481 local iter, ob, last = orig_occupant:each_session(); 475 local iter, ob, last = orig_occupant:each_session();
482 is_last_orig_session = iter(ob, iter(ob, last)) == nil; 476 is_last_orig_session = iter(ob, iter(ob, last)) == nil;
483 end 477 end
484 478
485 -- TODO Handle these cases sensibly 479 -- TODO Handle these cases sensibly
480 local muc_x = stanza:get_child("x", "http://jabber.org/protocol/muc");
486 if orig_occupant == nil and not muc_x then 481 if orig_occupant == nil and not muc_x then
487 module:log("debug", "Join without <x>, possibly desynced"); 482 module:log("debug", "Join without <x>, possibly desynced");
488 elseif orig_occupant ~= nil and muc_x then 483 elseif orig_occupant ~= nil and muc_x then
489 module:log("debug", "Presence update with <x>, possibly desynced"); 484 module:log("debug", "Presence update with <x>, possibly desynced");
490 end 485 end