aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2016-09-18 23:21:05 +0200
committerChristian Schneppe <christian@pix-art.de>2016-09-23 21:55:03 +0200
commit029756947294e3d81e272659cf0bf84915db2bde (patch)
treecb1de4f8e92d2fe167823bc2fecb3c289fef2cd4 /src
parentcccd15e4dc1ba769727fdfeb3359c2307f3e8ac6 (diff)
add support for XEP-0377: Spam Reporting
Diffstat (limited to 'src')
-rw-r--r--src/main/java/de/pixart/messenger/generator/IqGenerator.java8
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java4
-rw-r--r--src/main/java/de/pixart/messenger/ui/BlockContactDialog.java18
-rw-r--r--src/main/java/de/pixart/messenger/xmpp/XmppConnection.java4
-rw-r--r--src/main/res/layout/dialog_block_contact.xml25
-rw-r--r--src/main/res/values/strings.xml1
6 files changed, 53 insertions, 7 deletions
diff --git a/src/main/java/de/pixart/messenger/generator/IqGenerator.java b/src/main/java/de/pixart/messenger/generator/IqGenerator.java
index 1b1626a8c..fd7177a8c 100644
--- a/src/main/java/de/pixart/messenger/generator/IqGenerator.java
+++ b/src/main/java/de/pixart/messenger/generator/IqGenerator.java
@@ -254,10 +254,14 @@ public class IqGenerator extends AbstractGenerator {
return iq;
}
- public IqPacket generateSetBlockRequest(final Jid jid) {
+ public IqPacket generateSetBlockRequest(final Jid jid, boolean reportSpam) {
final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
final Element block = iq.addChild("block", Xmlns.BLOCKING);
- block.addChild("item").setAttribute("jid", jid.toBareJid().toString());
+ final Element item = block.addChild("item").setAttribute("jid", jid.toBareJid().toString());
+ if (reportSpam) {
+ item.addChild("report", "urn:xmpp:reporting:0").addChild("spam");
+ }
+ Log.d(Config.LOGTAG,iq.toString());
return iq;
}
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index 879fee405..57598f1fb 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -3434,10 +3434,10 @@ public class XmppConnectionService extends Service {
mDatabaseExecutor.execute(runnable);
}
- public void sendBlockRequest(final Blockable blockable) {
+ public void sendBlockRequest(final Blockable blockable, boolean reportSpam) {
if (blockable != null && blockable.getBlockedJid() != null) {
final Jid jid = blockable.getBlockedJid();
- this.sendIqPacket(blockable.getAccount(), getIqGenerator().generateSetBlockRequest(jid), new OnIqPacketReceived() {
+ this.sendIqPacket(blockable.getAccount(), getIqGenerator().generateSetBlockRequest(jid, reportSpam), new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(final Account account, final IqPacket packet) {
diff --git a/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java b/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java
index b625e8b62..7f175e615 100644
--- a/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java
+++ b/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java
@@ -3,6 +3,11 @@ package de.pixart.messenger.ui;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.CheckBox;
+import android.widget.LinearLayout;
+import android.widget.TextView;
import de.pixart.messenger.R;
import de.pixart.messenger.entities.Blockable;
@@ -15,14 +20,21 @@ public final class BlockContactDialog {
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
final boolean isBlocked = blockable.isBlocked();
builder.setNegativeButton(R.string.cancel, null);
+ LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ LinearLayout view = (LinearLayout) inflater.inflate(R.layout.dialog_block_contact,null);
+ TextView message = (TextView) view.findViewById(R.id.text);
+ final CheckBox report = (CheckBox) view.findViewById(R.id.report_spam);
+ final boolean reporting = blockable.getAccount().getXmppConnection().getFeatures().spamReporting();
+ report.setVisibility(!isBlocked && reporting ? View.VISIBLE : View.GONE);
+ builder.setView(view);
if (blockable.getJid().isDomainJid() || blockable.getAccount().isBlocked(blockable.getJid().toDomainJid())) {
builder.setTitle(isBlocked ? R.string.action_unblock_domain : R.string.action_block_domain);
- builder.setMessage(context.getResources().getString(isBlocked ? R.string.unblock_domain_text : R.string.block_domain_text,
+ message.setText(context.getResources().getString(isBlocked ? R.string.unblock_domain_text : R.string.block_domain_text,
blockable.getJid().toDomainJid()));
} else {
builder.setTitle(isBlocked ? R.string.action_unblock_contact : R.string.action_block_contact);
- builder.setMessage(context.getResources().getString(isBlocked ? R.string.unblock_contact_text : R.string.block_contact_text,
+ message.setText(context.getResources().getString(isBlocked ? R.string.unblock_contact_text : R.string.block_contact_text,
blockable.getJid().toBareJid()));
}
builder.setPositiveButton(isBlocked ? R.string.unblock : R.string.block, new DialogInterface.OnClickListener() {
@@ -32,7 +44,7 @@ public final class BlockContactDialog {
if (isBlocked) {
xmppConnectionService.sendUnblockRequest(blockable);
} else {
- xmppConnectionService.sendBlockRequest(blockable);
+ xmppConnectionService.sendBlockRequest(blockable, report.isChecked());
}
}
});
diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
index 8f1948b50..41fab523d 100644
--- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
+++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
@@ -1613,6 +1613,10 @@ public class XmppConnection implements Runnable {
return hasDiscoFeature(account.getServer(), Xmlns.BLOCKING);
}
+ public boolean spamReporting() {
+ return hasDiscoFeature(account.getServer(), "urn:xmpp:reporting:reason:spam:0");
+ }
+
public boolean register() {
return hasDiscoFeature(account.getServer(), Xmlns.REGISTER);
}
diff --git a/src/main/res/layout/dialog_block_contact.xml b/src/main/res/layout/dialog_block_contact.xml
new file mode 100644
index 000000000..b3615533c
--- /dev/null
+++ b/src/main/res/layout/dialog_block_contact.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical"
+ android:paddingLeft="?attr/dialog_horizontal_padding"
+ android:paddingRight="?attr/dialog_horizontal_padding"
+ android:paddingBottom="?attr/dialog_vertical_padding"
+ android:paddingTop="?attr/dialog_vertical_padding">
+
+ <TextView
+ android:id="@+id/text"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textSize="?attr/TextSizeBody"
+ android:textColor="@color/black87"/>
+ <CheckBox
+ android:layout_marginTop="8dp"
+ android:id="@+id/report_spam"
+ android:layout_width="wrap_content"
+ android:textColor="?attr/color_text_primary"
+ android:layout_height="wrap_content"
+ android:text="@string/report_jid_as_spammer" />
+
+</LinearLayout> \ No newline at end of file
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index 452b58535..322f9e7a0 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -703,4 +703,5 @@
<string name="missing_keys_from_x">Missing OMEMO keys from %s.</string>
<string name="wrong_conference_configuration">This is not a private, non-anonymous conference.</string>
<string name="this_conference_has_no_members">There are no members in this conference.</string>
+ <string name="report_jid_as_spammer">Report this JID as sending unwanted messages.</string>
</resources>