From 345e2b7da1f1bc39a2e6d2274813adc7b6a410c0 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Fri, 15 Nov 2019 16:00:09 +0100 Subject: rework no write access hint in moderated public mucs --- .../messenger/services/XmppConnectionService.java | 4 +++ .../pixart/messenger/ui/ConversationFragment.java | 40 ++++++++++++++++++---- .../de/pixart/messenger/ui/SettingsActivity.java | 1 + src/main/res/values/defaults.xml | 1 + src/main/res/values/strings.xml | 3 +- 5 files changed, 42 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index e8ade33de..ecf7d68b5 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -4274,6 +4274,10 @@ public class XmppConnectionService extends Service { return getBooleanPreference(SettingsActivity.WARN_UNENCRYPTED_CHAT, R.bool.warn_unencrypted_chat); } + + public boolean hideYouAreNotParticipating() { + return getBooleanPreference(SettingsActivity.HIDE_YOU_ARE_NOT_PARTICIPATING, R.bool.hide_you_are_not_participating); + } public boolean broadcastLastActivity() { return getBooleanPreference(SettingsActivity.BROADCAST_LAST_ACTIVITY, R.bool.last_activity); } diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index 362bd4495..fdeb4a56f 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -124,6 +124,7 @@ import de.pixart.messenger.xmpp.jingle.JingleConnection; import rocks.xmpp.addr.Jid; import static de.pixart.messenger.entities.Message.DELETED_MESSAGE_BODY; +import static de.pixart.messenger.ui.SettingsActivity.HIDE_YOU_ARE_NOT_PARTICIPATING; import static de.pixart.messenger.ui.SettingsActivity.WARN_UNENCRYPTED_CHAT; import static de.pixart.messenger.ui.XmppActivity.EXTRA_ACCOUNT; import static de.pixart.messenger.ui.XmppActivity.REQUEST_INVITE_TO_CONVERSATION; @@ -503,6 +504,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } } }; + private View.OnLongClickListener mSendButtonLongListener = new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { @@ -513,6 +515,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke return true; } }; + private int completionIndex = 0; private int lastCompletionLength = 0; private String incomplete; @@ -931,7 +934,8 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke R.string.send_private_message_to, conversation.getNextCounterpart().getResource())); } else if (multi && !conversation.getMucOptions().participating()) { - this.binding.textInputHint.setVisibility(View.GONE); + this.binding.textInputHint.setVisibility(View.VISIBLE); + this.binding.textInputHint.setText(R.string.ask_for_writeaccess); this.binding.textinput.setHint(R.string.you_are_not_participating); } else { this.binding.textInputHint.setVisibility(View.GONE); @@ -2226,7 +2230,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke messageListAdapter.updatePreferences(); refresh(false); this.conversation.messagesLoaded.set(true); - + hasWriteAccessInMUC(); Log.d(Config.LOGTAG, "scrolledToBottomAndNoPending=" + Boolean.toString(scrolledToBottomAndNoPending)); if (hasExtras || scrolledToBottomAndNoPending) { @@ -2255,6 +2259,34 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke return true; } + private void hasWriteAccessInMUC() { + if ((conversation.getMode() == Conversation.MODE_MULTI && !conversation.getMucOptions().participating()) && !activity.xmppConnectionService.hideYouAreNotParticipating()) { + activity.runOnUiThread(() -> { + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setTitle(getString(R.string.you_are_not_participating)); + builder.setMessage(getString(R.string.no_write_access_in_public_muc)); + builder.setNegativeButton(getString(R.string.hide_warning), + (dialog, which) -> { + SharedPreferences preferences = activity.getPreferences(); + preferences.edit().putBoolean(HIDE_YOU_ARE_NOT_PARTICIPATING, true).apply(); + hideSnackbar(); + }); + builder.setPositiveButton(getString(R.string.ok), + (dialog, which) -> { + Intent intent = new Intent(getActivity(), ConferenceDetailsActivity.class); + intent.setAction(ConferenceDetailsActivity.ACTION_VIEW_MUC); + intent.putExtra("uuid", conversation.getUuid()); + startActivity(intent); + activity.overridePendingTransition(R.animator.fade_in, R.animator.fade_out); + }); + builder.create().show(); + }); + + + showSnackbar(R.string.no_write_access_in_public_muc, R.string.ok, clickToMuc); + } + } + private void resetUnreadMessagesCount() { lastMessageUuid = null; hideUnreadMessagesCount(); @@ -2455,9 +2487,6 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke hideSnackbar(); break; } - } else if ((mode == Conversation.MODE_MULTI - && !conversation.getMucOptions().participating())) { - showSnackbar(R.string.no_write_access_in_public_muc, R.string.ok, clickToMuc); } else if (account.hasPendingPgpIntent(conversation)) { showSnackbar(R.string.openpgp_messages_found, R.string.decrypt, clickToDecryptListener); } else if (mode == Conversation.MODE_SINGLE @@ -2541,7 +2570,6 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke binding.unreadCountCustomView.setUnreadCount(conversation.getReceivedMessagesCountSinceUuid(lastMessageUuid)); } this.messageListAdapter.notifyDataSetChanged(); - updateChatMsgHint(); if (notifyConversationRead && activity != null) { binding.messagesView.post(this::fireReadEvent); } diff --git a/src/main/java/de/pixart/messenger/ui/SettingsActivity.java b/src/main/java/de/pixart/messenger/ui/SettingsActivity.java index 419785ecf..a9ffe12bd 100644 --- a/src/main/java/de/pixart/messenger/ui/SettingsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/SettingsActivity.java @@ -53,6 +53,7 @@ public class SettingsActivity extends XmppActivity implements public static final String AUTOMATIC_MESSAGE_DELETION = "automatic_message_deletion"; public static final String BROADCAST_LAST_ACTIVITY = "last_activity"; public static final String WARN_UNENCRYPTED_CHAT = "warn_unencrypted_chat"; + public static final String HIDE_YOU_ARE_NOT_PARTICIPATING = "hide_you_are_not_participating"; public static final String THEME = "theme"; public static final String SHOW_DYNAMIC_TAGS = "show_dynamic_tags"; public static final String OMEMO_SETTING = "omemo"; diff --git a/src/main/res/values/defaults.xml b/src/main/res/values/defaults.xml index e1e39fbe5..26d1179ae 100644 --- a/src/main/res/values/defaults.xml +++ b/src/main/res/values/defaults.xml @@ -39,6 +39,7 @@ false true true + false true false true diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 7c899ecd4..e0d3b9120 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -702,7 +702,7 @@ Would you like to destroy the group chat %s? This will remove this group chat permanently. Group chat successfully destroyed Group chat could not be destroyed - You are not participating this group chat and have no write access at the moment.\nPlease go to the group chat details by pressing OK and send a private message to a moderator, administrator or owner by long clicking one of the members name at the top of the list to ask for write access. + You are not participating this group chat and have no write access at the moment.\nPlease go to the group chat details by pressing OK and send a private message to a moderator, administrator or owner by long clicking one of the members name at the top/front of the list to ask for write access. Snooze Protected Apps To keep receiving notifications, even when the screen is turned off, you need to add Pix-Art Messenger to the list of protected apps. @@ -988,4 +988,5 @@ Long Grace Period The length of time notifications are silenced after detecting activity on one of your other devices. + Please ask for write access -- cgit v1.2.3