diff --git a/src/main/java/org/jitsi/impl/protocol/xmpp/ChatRoomImpl.java b/src/main/java/org/jitsi/impl/protocol/xmpp/ChatRoomImpl.java index a5258f2157..f024dc3763 100644 --- a/src/main/java/org/jitsi/impl/protocol/xmpp/ChatRoomImpl.java +++ b/src/main/java/org/jitsi/impl/protocol/xmpp/ChatRoomImpl.java @@ -30,6 +30,7 @@ import org.jivesoftware.smack.*; import org.jivesoftware.smack.SmackException.*; import org.jivesoftware.smack.packet.*; +import org.jivesoftware.smack.packet.id.*; import org.jivesoftware.smackx.muc.*; import org.jivesoftware.smackx.muc.MultiUserChatException.*; import org.jivesoftware.smackx.muc.packet.*; @@ -965,9 +966,9 @@ private MUCUser getMUCUserExtension(Presence packet) if (packet != null) { // Get the MUC User extension - return (MUCUser) packet.getExtension( - "x", "http://jabber.org/protocol/muc#user"); + return packet.getExtension(MUCInitialPresence.ELEMENT, MUCInitialPresence.NAMESPACE); } + return null; } @@ -980,9 +981,6 @@ public void setPresenceExtension(ExtensionElement extension, return; } - XmppProtocolProvider xmppProtocolProvider - = (XmppProtocolProvider) getParentProvider(); - boolean presenceUpdated = false; // Remove old @@ -1004,16 +1002,7 @@ public void setPresenceExtension(ExtensionElement extension, if (presenceUpdated) { - XmppConnection connection = xmppProtocolProvider.getConnectionAdapter(); - if (connection == null) { - logger.error("Failed to send presence extension - no connection"); - return; - } - - // Reset the stanza ID before sending - lastPresenceSent.setStanzaId(null); - - connection.sendStanza(lastPresenceSent); + sendLastPresence(); } } @@ -1039,9 +1028,6 @@ public void modifyPresence(Collection toRemove, return; } - XmppProtocolProvider xmppProtocolProvider - = (XmppProtocolProvider) getParentProvider(); - // Remove old if (toRemove != null) { @@ -1054,6 +1040,17 @@ public void modifyPresence(Collection toRemove, toAdd.forEach(newExt -> lastPresenceSent.addExtension(newExt)); } + sendLastPresence(); + } + + /** + * Prepares and sends the last seen presence. + * Removes the initial extension and sets new id. + */ + private void sendLastPresence() + { + XmppProtocolProvider xmppProtocolProvider = (XmppProtocolProvider) getParentProvider(); + XmppConnection connection = xmppProtocolProvider.getConnectionAdapter(); if (connection == null) { @@ -1061,8 +1058,14 @@ public void modifyPresence(Collection toRemove, return; } - // Reset the stanza ID before sending - lastPresenceSent.setStanzaId(null); + // The initial presence sent by smack contains an empty "x" + // extension. If this extension is included in a subsequent stanza, + // it indicates that the client lost its synchronization and causes + // the MUC service to re-send the presence of each occupant in the + // room. + lastPresenceSent.removeExtension(MUCInitialPresence.ELEMENT, MUCInitialPresence.NAMESPACE); + + lastPresenceSent.setStanzaId(StanzaIdUtil.newStanzaId()); connection.sendStanza(lastPresenceSent); }