From 9bdebb81ba94fd38942eae1d7a68ebe68d47b082 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 9 Jul 2018 11:35:30 +0200 Subject: [PATCH] handle non participating mucs a bit better --- .../services/XmppConnectionService.java | 2 +- .../ui/ConversationFragment.java | 19 ++++++++++++++----- .../ui/util/ConversationMenuConfigurator.java | 9 +++++++++ .../conversations/ui/widget/EditMessage.java | 2 +- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 3f69c829e..589494865 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -1535,7 +1535,7 @@ public class XmppConnectionService extends Service { } else { for (Conversation conversation : getConversations()) { if (conversation.getMode() == Conversation.MODE_SINGLE - || conversation.getAccount().httpUploadAvailable()) { + || (conversation.getAccount().httpUploadAvailable() && conversation.getMucOptions().participating())) { list.add(conversation); } } diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index ba91f947d..264469ec0 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -69,6 +69,7 @@ import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Blockable; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; +import eu.siacs.conversations.entities.Conversational; import eu.siacs.conversations.entities.DownloadableFile; import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.MucOptions; @@ -1775,7 +1776,8 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } if (this.conversation != null) { final String msg = this.binding.textinput.getText().toString(); - if (this.conversation.getStatus() != Conversation.STATUS_ARCHIVED && this.conversation.setNextMessage(msg)) { + final boolean participating = conversation.getMode() == Conversational.MODE_SINGLE || conversation.getMucOptions().participating(); + if (this.conversation.getStatus() != Conversation.STATUS_ARCHIVED && participating && this.conversation.setNextMessage(msg)) { this.activity.xmppConnectionService.updateConversation(this.conversation); } updateChatState(this.conversation, msg); @@ -1799,7 +1801,8 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } Log.d(Config.LOGTAG, "ConversationFragment.saveMessageDraftStopAudioPlayer()"); final String msg = this.binding.textinput.getText().toString(); - if (previousConversation.setNextMessage(msg)) { + final boolean participating = previousConversation.getMode() == Conversational.MODE_SINGLE || previousConversation.getMucOptions().participating(); + if (participating && previousConversation.setNextMessage(msg)) { activity.xmppConnectionService.updateConversation(previousConversation); } updateChatState(this.conversation, msg); @@ -1855,7 +1858,10 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke this.binding.textSendButton.setContentDescription(activity.getString(R.string.send_message_to_x, conversation.getName())); this.binding.textinput.setKeyboardListener(null); this.binding.textinput.setText(""); - this.binding.textinput.append(this.conversation.getNextMessage()); + final boolean participating = conversation.getMode() == Conversational.MODE_SINGLE || conversation.getMucOptions().participating(); + if (participating) { + this.binding.textinput.append(this.conversation.getNextMessage()); + } this.binding.textinput.setKeyboardListener(this); messageListAdapter.updatePreferences(); refresh(false); @@ -2077,6 +2083,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } updateSendButton(); updateEditablity(); + activity.invalidateOptionsMenu(); } } } @@ -2088,8 +2095,9 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke this.binding.textinput.append(conversation.getDraftMessage()); conversation.setDraftMessage(null); } - if (conversation.setNextMessage(this.binding.textinput.getText().toString())) { - activity.xmppConnectionService.updateConversation(conversation); + final boolean participating = conversation.getMode() == Conversational.MODE_SINGLE || conversation.getMucOptions().participating(); + if (participating && conversation.setNextMessage(this.binding.textinput.getText().toString())) { + activity.xmppConnectionService.databaseBackend.updateConversation(conversation); } updateChatMsgHint(); SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(activity); @@ -2117,6 +2125,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke this.binding.textinput.setFocusableInTouchMode(canWrite); this.binding.textSendButton.setEnabled(canWrite); this.binding.textinput.setCursorVisible(canWrite); + this.binding.textinput.setEnabled(canWrite); } public void updateSendButton() { diff --git a/src/main/java/eu/siacs/conversations/ui/util/ConversationMenuConfigurator.java b/src/main/java/eu/siacs/conversations/ui/util/ConversationMenuConfigurator.java index 288ebbe87..69bb38278 100644 --- a/src/main/java/eu/siacs/conversations/ui/util/ConversationMenuConfigurator.java +++ b/src/main/java/eu/siacs/conversations/ui/util/ConversationMenuConfigurator.java @@ -42,6 +42,7 @@ import eu.siacs.conversations.R; import eu.siacs.conversations.crypto.OmemoSetting; import eu.siacs.conversations.crypto.axolotl.AxolotlService; import eu.siacs.conversations.entities.Conversation; +import eu.siacs.conversations.entities.Conversational; import eu.siacs.conversations.entities.Message; public class ConversationMenuConfigurator { @@ -70,6 +71,14 @@ public class ConversationMenuConfigurator { public static void configureEncryptionMenu(@NonNull Conversation conversation, Menu menu) { final MenuItem menuSecure = menu.findItem(R.id.action_security); + + final boolean participating = conversation.getMode() == Conversational.MODE_SINGLE || conversation.getMucOptions().participating(); + + if (!participating) { + menuSecure.setVisible(false); + return; + } + final MenuItem none = menu.findItem(R.id.encryption_choice_none); final MenuItem pgp = menu.findItem(R.id.encryption_choice_pgp); final MenuItem axolotl = menu.findItem(R.id.encryption_choice_axolotl); diff --git a/src/main/java/eu/siacs/conversations/ui/widget/EditMessage.java b/src/main/java/eu/siacs/conversations/ui/widget/EditMessage.java index 33220bde3..359571dd3 100644 --- a/src/main/java/eu/siacs/conversations/ui/widget/EditMessage.java +++ b/src/main/java/eu/siacs/conversations/ui/widget/EditMessage.java @@ -149,7 +149,7 @@ public class EditMessage extends EmojiWrapperEditText { public InputConnection onCreateInputConnection(EditorInfo editorInfo) { final InputConnection ic = super.onCreateInputConnection(editorInfo); - if (mimeTypes != null && mCommitContentListener != null) { + if (mimeTypes != null && mCommitContentListener != null && ic != null) { EditorInfoCompat.setContentMimeTypes(editorInfo, mimeTypes); return InputConnectionCompat.createWrapper(ic, editorInfo, (inputContentInfo, flags, opts) -> EditMessage.this.mCommitContentListener.onCommitContent(inputContentInfo, flags, opts, mimeTypes)); } else {