From 6cab0ad496cc9b025b1631c616f11c3869ccd6eb Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 12 Feb 2021 10:35:13 +0100 Subject: [PATCH] make rtp proposal tracked by SM. fixes #3983 --- .../services/XmppConnectionService.java | 22 +++++++++++++++---- .../xmpp/OnMessageAcknowledged.java | 2 +- .../conversations/xmpp/XmppConnection.java | 10 ++++++--- .../xmpp/jingle/JingleConnectionManager.java | 11 +++++++--- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 3cf5aa9d1..bd409da8d 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -152,6 +152,7 @@ import eu.siacs.conversations.xmpp.chatstate.ChatState; import eu.siacs.conversations.xmpp.forms.Data; import eu.siacs.conversations.xmpp.jingle.AbstractJingleConnection; import eu.siacs.conversations.xmpp.jingle.JingleConnectionManager; +import eu.siacs.conversations.xmpp.jingle.JingleRtpConnection; import eu.siacs.conversations.xmpp.jingle.Media; import eu.siacs.conversations.xmpp.jingle.RtpEndUserState; import eu.siacs.conversations.xmpp.mam.MamReference; @@ -251,10 +252,23 @@ public class XmppConnectionService extends Service { private final OnMessageAcknowledged mOnMessageAcknowledgedListener = new OnMessageAcknowledged() { @Override - public boolean onMessageAcknowledged(Account account, String uuid) { + public boolean onMessageAcknowledged(final Account account, final Jid to, final String id) { + if (id.startsWith(JingleRtpConnection.JINGLE_MESSAGE_PROPOSE_ID_PREFIX)) { + final String sessionId = id.substring(JingleRtpConnection.JINGLE_MESSAGE_PROPOSE_ID_PREFIX.length()); + mJingleConnectionManager.updateProposedSessionDiscovered( + account, + to, + sessionId, + JingleConnectionManager.DeviceDiscoveryState.SEARCHING_ACKNOWLEDGED + ); + } + + + final Jid bare = to.asBareJid(); + for (final Conversation conversation : getConversations()) { - if (conversation.getAccount() == account) { - Message message = conversation.findUnsentMessageWithUuid(uuid); + if (conversation.getAccount() == account && conversation.getJid().asBareJid().equals(bare)) { + final Message message = conversation.findUnsentMessageWithUuid(id); if (message != null) { message.setStatus(Message.STATUS_SEND); message.setErrorMessage(null); @@ -4281,7 +4295,7 @@ public class XmppConnectionService extends Service { } public void sendMessagePacket(Account account, MessagePacket packet) { - XmppConnection connection = account.getXmppConnection(); + final XmppConnection connection = account.getXmppConnection(); if (connection != null) { connection.sendMessagePacket(packet); } diff --git a/src/main/java/eu/siacs/conversations/xmpp/OnMessageAcknowledged.java b/src/main/java/eu/siacs/conversations/xmpp/OnMessageAcknowledged.java index 4e20b81b6..997f96f8e 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/OnMessageAcknowledged.java +++ b/src/main/java/eu/siacs/conversations/xmpp/OnMessageAcknowledged.java @@ -3,5 +3,5 @@ package eu.siacs.conversations.xmpp; import eu.siacs.conversations.entities.Account; public interface OnMessageAcknowledged { - boolean onMessageAcknowledged(Account account, String id); + boolean onMessageAcknowledged(Account account, Jid to, String id); } diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index ce3b98d5d..baa8dcae8 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -661,10 +661,14 @@ public class XmppConnection implements Runnable { if (Config.EXTENDED_SM_LOGGING) { Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": server acknowledged stanza #" + mStanzaQueue.keyAt(i)); } - AbstractAcknowledgeableStanza stanza = mStanzaQueue.valueAt(i); + final AbstractAcknowledgeableStanza stanza = mStanzaQueue.valueAt(i); if (stanza instanceof MessagePacket && acknowledgedListener != null) { - MessagePacket packet = (MessagePacket) stanza; - acknowledgedMessages |= acknowledgedListener.onMessageAcknowledged(account, packet.getId()); + final MessagePacket packet = (MessagePacket) stanza; + final String id = packet.getId(); + final Jid to = packet.getTo(); + if (id != null && to != null) { + acknowledgedMessages |= acknowledgedListener.onMessageAcknowledged(account, to, id); + } } mStanzaQueue.removeAt(i); i--; diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java index 27111af35..8dddbe3d5 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java @@ -133,7 +133,9 @@ public class JingleConnectionManager extends AbstractConnectionManager { } } synchronized (this.rtpSessionProposals) { - return this.rtpSessionProposals.containsValue(DeviceDiscoveryState.DISCOVERED) || this.rtpSessionProposals.containsValue(DeviceDiscoveryState.SEARCHING); + return this.rtpSessionProposals.containsValue(DeviceDiscoveryState.DISCOVERED) + || this.rtpSessionProposals.containsValue(DeviceDiscoveryState.SEARCHING) + || this.rtpSessionProposals.containsValue(DeviceDiscoveryState.SEARCHING_ACKNOWLEDGED); } } @@ -154,7 +156,9 @@ public class JingleConnectionManager extends AbstractConnectionManager { for (Map.Entry entry : this.rtpSessionProposals.entrySet()) { final RtpSessionProposal proposal = entry.getKey(); final DeviceDiscoveryState state = entry.getValue(); - final boolean openProposal = state == DeviceDiscoveryState.DISCOVERED || state == DeviceDiscoveryState.SEARCHING; + final boolean openProposal = state == DeviceDiscoveryState.DISCOVERED + || state == DeviceDiscoveryState.SEARCHING + || state == DeviceDiscoveryState.SEARCHING_ACKNOWLEDGED; if (openProposal && proposal.account == account && proposal.with.equals(with.asBareJid()) @@ -772,11 +776,12 @@ public class JingleConnectionManager extends AbstractConnectionManager { } public enum DeviceDiscoveryState { - SEARCHING, DISCOVERED, FAILED; + SEARCHING, SEARCHING_ACKNOWLEDGED, DISCOVERED, FAILED; public RtpEndUserState toEndUserState() { switch (this) { case SEARCHING: + case SEARCHING_ACKNOWLEDGED: return RtpEndUserState.FINDING_DEVICE; case DISCOVERED: return RtpEndUserState.RINGING;