From c7c26149c1bbed6eb2cd198a78a0e4452789e0c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=8F=D0=BD=20=D0=9C=D0=B8=D0=BD=D0=BA?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Thu, 7 Jan 2021 09:41:26 -0600 Subject: [PATCH] fix: Fixes sending last seen presence. (#662) * fix: Skip sending duplicate identical presences. In this case removing the extension BridgeNotAvailablePacketExt from presence on every onColibriConferenceAllocated, was resending last presence. * fix: Fixes sending last seen presence. Removing the extension that indicates joining and would trigger the server sending all presences and chat history. Updates the stanza id with new value before sending it. --- .../impl/protocol/xmpp/ChatRoomImpl.java | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) 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); }