diff --git a/res/layout/view_conversation.xml b/res/layout/view_conversation.xml index fffeb392e0..43a82160ba 100644 --- a/res/layout/view_conversation.xml +++ b/res/layout/view_conversation.xml @@ -8,7 +8,7 @@ android:gravity="center_vertical"> diff --git a/res/menu/conversation_block.xml b/res/menu/conversation_block.xml new file mode 100644 index 0000000000..14dfea3546 --- /dev/null +++ b/res/menu/conversation_block.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/res/menu/conversation_unblock.xml b/res/menu/conversation_unblock.xml new file mode 100644 index 0000000000..354401a817 --- /dev/null +++ b/res/menu/conversation_unblock.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java index d9300166c8..f09264505d 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java @@ -753,10 +753,11 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity } if (isSingleConversation()) { - /* - if (isSecureText) inflater.inflate(R.menu.conversation_callable_secure, menu); - else inflater.inflate(R.menu.conversation_callable_insecure, menu); - */ + if (recipient.isBlocked()) { + inflater.inflate(R.menu.conversation_unblock, menu); + } else { + inflater.inflate(R.menu.conversation_block, menu); + } } else if (isGroupConversation() && !isOpenGroupOrRSSFeed) { inflater.inflate(R.menu.conversation_group_options, menu); @@ -860,8 +861,10 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity public boolean onOptionsItemSelected(MenuItem item) { super.onOptionsItemSelected(item); switch (item.getItemId()) { - case R.id.menu_call_secure: handleDial(getRecipient(), true); return true; - case R.id.menu_call_insecure: handleDial(getRecipient(), false); return true; + case R.id.menu_call_secure: handleDial(getRecipient(), true); return true; + case R.id.menu_call_insecure: handleDial(getRecipient(), false); return true; + case R.id.menu_unblock: handleUnblock(); return true; + case R.id.menu_block: handleBlock(); return true; case R.id.menu_view_media: handleViewMedia(); return true; case R.id.menu_add_shortcut: handleAddShortcut(); return true; case R.id.menu_search: handleSearch(); return true; @@ -986,12 +989,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity int titleRes = R.string.ConversationActivity_unblock_this_contact_question; int bodyRes = R.string.ConversationActivity_you_will_once_again_be_able_to_receive_messages_and_calls_from_this_contact; - if (recipient.isGroupRecipient()) { - titleRes = R.string.ConversationActivity_unblock_this_group_question; - bodyRes = R.string.ConversationActivity_unblock_this_group_description; - } - - //noinspection CodeBlock2Expr new AlertDialog.Builder(this) .setTitle(titleRes) .setMessage(bodyRes) @@ -1070,6 +1067,33 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity builder.show(); } + private void handleBlock() { + int titleRes = R.string.RecipientPreferenceActivity_block_this_contact_question; + int bodyRes = R.string.RecipientPreferenceActivity_you_will_no_longer_receive_messages_and_calls_from_this_contact; + + new AlertDialog.Builder(this) + .setTitle(titleRes) + .setMessage(bodyRes) + .setNegativeButton(android.R.string.cancel, null) + .setPositiveButton(R.string.RecipientPreferenceActivity_block, (dialog, which) -> { + new AsyncTask() { + @Override + protected Void doInBackground(Void... params) { + DatabaseFactory.getRecipientDatabase(ConversationActivity.this) + .setBlocked(recipient, true); + + ApplicationContext.getInstance(ConversationActivity.this) + .getJobManager() + .add(new MultiDeviceBlockedUpdateJob()); + + Util.runOnMain(() -> finish()); + + return null; + } + }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + }).show(); + } + private void handleViewMedia() { Intent intent = new Intent(this, MediaOverviewActivity.class); intent.putExtra(MediaOverviewActivity.ADDRESS_EXTRA, recipient.getAddress()); diff --git a/src/org/thoughtcrime/securesms/loki/views/ConversationView.kt b/src/org/thoughtcrime/securesms/loki/views/ConversationView.kt index 26b9762622..f859faa85e 100644 --- a/src/org/thoughtcrime/securesms/loki/views/ConversationView.kt +++ b/src/org/thoughtcrime/securesms/loki/views/ConversationView.kt @@ -13,6 +13,7 @@ import org.thoughtcrime.securesms.loki.utilities.MentionManagerUtilities.populat import org.thoughtcrime.securesms.loki.utilities.MentionUtilities.highlightMentions import org.thoughtcrime.securesms.mms.GlideRequests import org.thoughtcrime.securesms.util.DateUtils +import org.thoughtcrime.securesms.util.TextSecurePreferences import org.whispersystems.signalservice.loki.protocol.mentions.MentionsManager import java.util.* @@ -46,14 +47,26 @@ class ConversationView : LinearLayout { // region Updating fun bind(thread: ThreadRecord, isTyping: Boolean, glide: GlideRequests) { this.thread = thread - populateUserPublicKeyCacheIfNeeded(thread.threadId, context) // FIXME: This is a terrible place to do this - unreadMessagesIndicatorView.visibility = if (thread.unreadCount > 0) View.VISIBLE else View.INVISIBLE + populateUserPublicKeyCacheIfNeeded(thread.threadId, context) // FIXME: This is a bad place to do this + if (thread.recipient.isBlocked) { + accentView.setBackgroundResource(R.color.destructive) + accentView.visibility = View.VISIBLE + } else { + accentView.setBackgroundResource(R.color.accent) + accentView.visibility = if (thread.unreadCount > 0) View.VISIBLE else View.INVISIBLE + } if (thread.recipient.isGroupRecipient) { if ("Session Public Chat" == thread.recipient.name) { profilePictureView.publicKey = "" + profilePictureView.additionalPublicKey = null profilePictureView.isRSSFeed = true } else { - val users = MentionsManager.shared.userPublicKeyCache[thread.threadId]?.toList() ?: listOf() + val users = MentionsManager.shared.userPublicKeyCache[thread.threadId]?.toMutableList() ?: mutableListOf() + users.remove(TextSecurePreferences.getLocalNumber(context)) + val masterPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context) + if (masterPublicKey != null) { + users.remove(masterPublicKey) + } val randomUsers = users.sorted() // Sort to provide a level of stability profilePictureView.publicKey = randomUsers.getOrNull(0) ?: "" profilePictureView.additionalPublicKey = randomUsers.getOrNull(1) ?: ""