From afa34ce15ac089da851e7a24d9caccb94f6bbc67 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 3 Mar 2017 11:56:08 +0100 Subject: [PATCH] block send action while encrypting pgp message --- .../siacs/conversations/ui/ConversationActivity.java | 3 +++ .../siacs/conversations/ui/ConversationFragment.java | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index afd56b528..e63a44927 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -1688,6 +1688,9 @@ public class ConversationActivity extends XmppActivity ).show(); } }); + if (mConversationFragment != null) { + mConversationFragment.doneSendingPgpMessage(); + } } }); } diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 970fbee12..fb3f3331c 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -48,6 +48,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.UUID; +import java.util.concurrent.atomic.AtomicBoolean; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; @@ -1071,6 +1072,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa } protected void messageSent() { + mSendingPgpMessage.set(false); mEditMessage.setText(""); updateChatMsgHint(); new Handler().post(new Runnable() { @@ -1086,6 +1088,10 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa mEditMessage.requestFocus(); } + public void doneSendingPgpMessage() { + mSendingPgpMessage.set(false); + } + enum SendButtonAction {TEXT, TAKE_PHOTO, SEND_LOCATION, RECORD_VOICE, CANCEL, CHOOSE_PICTURE} private int getSendButtonImageResource(SendButtonAction action, Presence.Status status) { @@ -1299,6 +1305,8 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa messageSent(); } + private AtomicBoolean mSendingPgpMessage = new AtomicBoolean(false); + protected void sendPgpMessage(final Message message) { final ConversationActivity activity = (ConversationActivity) getActivity(); final XmppConnectionService xmppService = activity.xmppConnectionService; @@ -1311,6 +1319,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa activity.announcePgp(conversation.getAccount(), conversation, activity.onOpenPGPKeyPublished); return; } + if (!mSendingPgpMessage.compareAndSet(false,true)) { + Log.d(Config.LOGTAG,"sending pgp message already in progress"); + } if (conversation.getMode() == Conversation.MODE_SINGLE) { if (contact.getPgpKeyId() != 0) { xmppService.getPgpEngine().hasKey(contact, @@ -1340,6 +1351,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa ).show(); } }); + mSendingPgpMessage.set(false); } });