Skip to content

Commit

Permalink
add support for XEP-0377: Spam Reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
iNPUTmice committed Sep 18, 2016
1 parent badc97e commit 7eac903
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/XEPs.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@
* XEP-0357: Push Notifications
* XEP-0363: HTTP File Upload
* XEP-0368: SRV records for XMPP over TLS
* XEP-0377: Spam Reporting
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,14 @@ public IqPacket generateGetBlockList() {
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3346,10 +3346,10 @@ public void run() {
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) {
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/eu/siacs/conversations/ui/BlockContactDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
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 eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Blockable;
Expand All @@ -15,14 +20,21 @@ public static void show(final Context context,
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() {
Expand All @@ -32,7 +44,7 @@ public void onClick(final DialogInterface dialog, final int which) {
if (isBlocked) {
xmppConnectionService.sendUnblockRequest(blockable);
} else {
xmppConnectionService.sendBlockRequest(blockable);
xmppConnectionService.sendBlockRequest(blockable, report.isChecked());
}
}
});
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,10 @@ public boolean blocking() {
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);
}
Expand Down
25 changes: 25 additions & 0 deletions src/main/res/layout/dialog_block_contact.xml
Original file line number Diff line number Diff line change
@@ -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>
1 change: 1 addition & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -686,4 +686,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>

0 comments on commit 7eac903

Please sign in to comment.