offer to block entire domain in message from stranger snackbar. fixes #2391

This commit is contained in:
Daniel Gultsch 2017-03-20 12:55:48 +01:00
parent 4171e2b90e
commit c2c6904eda
4 changed files with 40 additions and 3 deletions

View File

@ -15,6 +15,7 @@ import android.widget.Toast;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Blockable;
import eu.siacs.conversations.entities.Conversation;
public final class BlockContactDialog {
public static void show(final XmppActivity xmppActivity,
@ -37,7 +38,8 @@ public final class BlockContactDialog {
value = blockable.getJid().toDomainJid().toString();
spannable = new SpannableString(xmppActivity.getString(isBlocked ? R.string.unblock_domain_text : R.string.block_domain_text, value));
} else {
builder.setTitle(isBlocked ? R.string.action_unblock_contact : R.string.action_block_contact);
int resBlockAction = blockable instanceof Conversation && ((Conversation) blockable).isWithStranger() ? R.string.block_stranger : R.string.action_block_contact;
builder.setTitle(isBlocked ? R.string.action_unblock_contact : resBlockAction);
value = blockable.getJid().toBareJid().toString();
spannable = new SpannableString(xmppActivity.getString(isBlocked ? R.string.unblock_contact_text : R.string.block_contact_text, value));
}

View File

@ -37,6 +37,7 @@ import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.PopupMenu;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
@ -53,6 +54,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
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.DownloadableFile;
@ -957,8 +959,30 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
private OnClickListener mBlockClickListener = new OnClickListener() {
@Override
public void onClick(final View v) {
BlockContactDialog.show(activity, conversation);
public void onClick(final View view) {
final Jid jid = conversation.getJid();
if (jid.isDomainJid()) {
BlockContactDialog.show(activity, conversation);
} else {
PopupMenu popupMenu = new PopupMenu(activity, view);
popupMenu.inflate(R.menu.block);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
Blockable blockable;
switch (menuItem.getItemId()) {
case R.id.block_domain:
blockable = conversation.getAccount().getRoster().getContact(jid.toDomainJid());
break;
default:
blockable = conversation;
}
BlockContactDialog.show(activity, blockable);
return true;
}
});
popupMenu.show();
}
}
};

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/block_domain"
android:title="@string/block_entire_domain" />
<item
android:id="@+id/block_contact"
android:title="@string/block_stranger" />
</menu>

View File

@ -741,4 +741,6 @@
<string name="pref_notifications_from_strangers">Notifications from strangers</string>
<string name="pref_notifications_from_strangers_summary">Notify for messages received from strangers.</string>
<string name="received_message_from_stranger">Received message from stranger</string>
<string name="block_stranger">Block stranger</string>
<string name="block_entire_domain">Block entire domain</string>
</resources>