From 0f6623888a091563a200f7e8351268bc4c597f58 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Thu, 20 Jun 2019 20:54:50 +0200 Subject: attempt to keep messages waiting until muc is connected --- .../java/de/pixart/messenger/entities/Account.java | 1 + .../messenger/services/XmppConnectionService.java | 25 +++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/pixart/messenger/entities/Account.java b/src/main/java/de/pixart/messenger/entities/Account.java index 3ebb1fafa..c2c5e90c8 100644 --- a/src/main/java/de/pixart/messenger/entities/Account.java +++ b/src/main/java/de/pixart/messenger/entities/Account.java @@ -72,6 +72,7 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable private final Collection blocklist = new CopyOnWriteArraySet<>(); public List pendingConferenceJoins = new CopyOnWriteArrayList<>(); public List pendingConferenceLeaves = new CopyOnWriteArrayList<>(); + public final Set inProgressConferenceJoins = new HashSet<>(); protected Jid jid; protected String password; protected int options = 0; diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index ec46a91f1..0dc298fd6 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -380,8 +380,13 @@ public class XmppConnectionService extends Service { } List conversations = getConversations(); for (Conversation conversation : conversations) { + final boolean inProgressJoin; + synchronized (account.inProgressConferenceJoins) { + inProgressJoin = account.inProgressConferenceJoins.contains(conversation); + } if (conversation.getAccount() == account - && !account.pendingConferenceJoins.contains(conversation)) { + && !account.pendingConferenceJoins.contains(conversation) + && !inProgressJoin) { if (!conversation.startOtrIfNeeded()) { Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": couldn't start OTR with " + conversation.getContact().getJid() + " when needed"); } @@ -1504,7 +1509,12 @@ public class XmppConnectionService extends Service { message1 -> markMessage(message1, Message.STATUS_SEND_FAILED)); } - if (account.isOnlineAndConnected()) { + final boolean inProgressJoin; + synchronized (account.inProgressConferenceJoins) { + inProgressJoin = conversation.getMode() == Conversational.MODE_MULTI && account.inProgressConferenceJoins.contains(conversation); + } + + if (account.isOnlineAndConnected() && !inProgressJoin) { switch (message.getEncryption()) { case Message.ENCRYPTION_NONE: if (message.needsUploading()) { @@ -2712,6 +2722,9 @@ public class XmppConnectionService extends Service { account.pendingConferenceJoins.remove(conversation); account.pendingConferenceLeaves.remove(conversation); if (account.getStatus() == Account.State.ONLINE) { + synchronized (account.inProgressConferenceJoins) { + account.inProgressConferenceJoins.add(conversation); + } sendPresencePacket(account, mPresenceGenerator.leave(conversation.getMucOptions())); conversation.resetMucOptions(); if (onConferenceJoined != null) { @@ -2765,7 +2778,10 @@ public class XmppConnectionService extends Service { saveConversationAsBookmark(conversation, null); } } - sendUnsentMessages(conversation); + synchronized (account.inProgressConferenceJoins) { + account.inProgressConferenceJoins.remove(conversation); + sendUnsentMessages(conversation); + } } @Override @@ -2784,6 +2800,9 @@ public class XmppConnectionService extends Service { return; } if (error != null && "remote-server-not-found".equals(error.getName())) { + synchronized (account.inProgressConferenceJoins) { + account.inProgressConferenceJoins.remove(conversation); + } conversation.getMucOptions().setError(MucOptions.Error.SERVER_NOT_FOUND); updateConversationUi(); } else { -- cgit v1.2.3