mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +00:00
Implement blocking
This commit is contained in:
parent
af5a37c601
commit
c388d31873
@ -8,7 +8,7 @@
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<View
|
||||
android:id="@+id/unreadMessagesIndicatorView"
|
||||
android:id="@+id/accentView"
|
||||
android:layout_width="@dimen/accent_line_thickness"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/accent" />
|
||||
|
8
res/menu/conversation_block.xml
Normal file
8
res/menu/conversation_block.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item android:title="@string/recipient_preferences__block"
|
||||
android:id="@+id/menu_block"
|
||||
android:icon="@drawable/ic_block_white_24dp" />
|
||||
|
||||
</menu>
|
8
res/menu/conversation_unblock.xml
Normal file
8
res/menu/conversation_unblock.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item android:title="@string/ConversationActivity_unblock"
|
||||
android:id="@+id/menu_unblock"
|
||||
android:icon="@drawable/ic_check_white_24dp" />
|
||||
|
||||
</menu>
|
@ -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);
|
||||
|
||||
@ -862,6 +863,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
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_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<Void, Void, Void>() {
|
||||
@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());
|
||||
|
@ -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) ?: ""
|
||||
|
Loading…
x
Reference in New Issue
Block a user