Skip to content

Commit

Permalink
fix: Fixes sending last seen presence. (#662)
Browse files Browse the repository at this point in the history
* 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 <x> 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.
  • Loading branch information
damencho authored Jan 7, 2021
1 parent b4f34c4 commit c7c2614
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions src/main/java/org/jitsi/impl/protocol/xmpp/ChatRoomImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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;
}

Expand All @@ -980,9 +981,6 @@ public void setPresenceExtension(ExtensionElement extension,
return;
}

XmppProtocolProvider xmppProtocolProvider
= (XmppProtocolProvider) getParentProvider();

boolean presenceUpdated = false;

// Remove old
Expand All @@ -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();
}
}

Expand All @@ -1039,9 +1028,6 @@ public void modifyPresence(Collection<ExtensionElement> toRemove,
return;
}

XmppProtocolProvider xmppProtocolProvider
= (XmppProtocolProvider) getParentProvider();

// Remove old
if (toRemove != null)
{
Expand All @@ -1054,15 +1040,32 @@ public void modifyPresence(Collection<ExtensionElement> toRemove,
toAdd.forEach(newExt -> lastPresenceSent.addExtension(newExt));
}

sendLastPresence();
}

/**
* Prepares and sends the last seen presence.
* Removes the initial <x> extension and sets new id.
*/
private void sendLastPresence()
{
XmppProtocolProvider xmppProtocolProvider = (XmppProtocolProvider) getParentProvider();

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);
// 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);
}
Expand Down

0 comments on commit c7c2614

Please sign in to comment.