Software /
code /
prosody
Comparison
plugins/muc/muc.lib.lua @ 7423:63141a85beea
MUC: Treat explicit join presence as join
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 07 May 2016 17:22:58 +0200 |
parent | 7418:e9f7043b86b5 |
child | 7426:3a90e9732204 |
comparison
equal
deleted
inserted
replaced
7422:41be97f8158f | 7423:63141a85beea |
---|---|
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"); | |
449 local real_jid = stanza.attr.from; | 450 local real_jid = stanza.attr.from; |
450 local bare_jid = jid_bare(real_jid); | 451 local bare_jid = jid_bare(real_jid); |
451 local orig_occupant = self:get_occupant_by_real_jid(real_jid); | 452 local orig_occupant = self:get_occupant_by_real_jid(real_jid); |
452 if type == "unavailable" and orig_occupant == nil then return true; end -- Unavailable from someone not in the room | 453 if type == "unavailable" and orig_occupant == nil then return true; end -- Unavailable from someone not in the room |
453 local is_first_dest_session; | 454 local is_first_dest_session; |
454 local dest_occupant; | 455 local dest_occupant; |
455 if type == "unavailable" then -- luacheck: ignore 542 | 456 if type == "unavailable" then -- luacheck: ignore 542 |
456 -- FIXME Why the empty if branch? | 457 -- FIXME Why the empty if branch? |
457 -- dest_occupant = nil | 458 -- dest_occupant = nil |
458 elseif orig_occupant and orig_occupant.nick == stanza.attr.to then -- Just a presence update | 459 elseif orig_occupant and not muc_x and orig_occupant.nick == stanza.attr.to then -- Just a presence update |
459 log("debug", "presence update for %s from session %s", orig_occupant.nick, real_jid); | 460 log("debug", "presence update for %s from session %s", orig_occupant.nick, real_jid); |
460 dest_occupant = orig_occupant; | 461 dest_occupant = orig_occupant; |
461 else | 462 else |
462 local dest_jid = stanza.attr.to; | 463 local dest_jid = stanza.attr.to; |
463 dest_occupant = self:get_occupant_by_nick(dest_jid); | 464 dest_occupant = self:get_occupant_by_nick(dest_jid); |
464 if dest_occupant == nil then | 465 if muc_x 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 | |
465 log("debug", "no occupant found for %s; creating new occupant object for %s", dest_jid, real_jid); | 471 log("debug", "no occupant found for %s; creating new occupant object for %s", dest_jid, real_jid); |
466 is_first_dest_session = true; | 472 is_first_dest_session = true; |
467 dest_occupant = self:new_occupant(bare_jid, dest_jid); | 473 dest_occupant = self:new_occupant(bare_jid, dest_jid); |
468 else | 474 else |
469 is_first_dest_session = false; | 475 is_first_dest_session = false; |
475 local iter, ob, last = orig_occupant:each_session(); | 481 local iter, ob, last = orig_occupant:each_session(); |
476 is_last_orig_session = iter(ob, iter(ob, last)) == nil; | 482 is_last_orig_session = iter(ob, iter(ob, last)) == nil; |
477 end | 483 end |
478 | 484 |
479 -- TODO Handle these cases sensibly | 485 -- TODO Handle these cases sensibly |
480 local muc_x = stanza:get_child("x", "http://jabber.org/protocol/muc"); | |
481 if orig_occupant == nil and not muc_x then | 486 if orig_occupant == nil and not muc_x then |
482 module:log("debug", "Join without <x>, possibly desynced"); | 487 module:log("debug", "Join without <x>, possibly desynced"); |
483 elseif orig_occupant ~= nil and muc_x then | 488 elseif orig_occupant ~= nil and muc_x then |
484 module:log("debug", "Presence update with <x>, possibly desynced"); | 489 module:log("debug", "Presence update with <x>, possibly desynced"); |
485 end | 490 end |