Skip to content

Commit 38ca53f

Browse files
committed
bump reporting xep and add ability to report messages
1 parent 60dd710 commit 38ca53f

10 files changed

+69
-11
lines changed

conversations.doap

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@
375375
<xmpp:SupportedXep>
376376
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0377.html"/>
377377
<xmpp:status>complete</xmpp:status>
378-
<xmpp:version>0.2</xmpp:version>
378+
<xmpp:version>0.3.1</xmpp:version>
379379
</xmpp:SupportedXep>
380380
</implements>
381381
<implements>

src/main/java/eu/siacs/conversations/generator/IqGenerator.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,18 @@ public IqPacket generateGetBlockList() {
344344
return iq;
345345
}
346346

347-
public IqPacket generateSetBlockRequest(final Jid jid, boolean reportSpam) {
347+
public IqPacket generateSetBlockRequest(final Jid jid, final boolean reportSpam, final String serverMsgId) {
348348
final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
349349
final Element block = iq.addChild("block", Namespace.BLOCKING);
350350
final Element item = block.addChild("item").setAttribute("jid", jid);
351351
if (reportSpam) {
352-
item.addChild("report", "urn:xmpp:reporting:0").addChild("spam");
352+
final Element report = item.addChild("report", Namespace.REPORTING);
353+
report.setAttribute("reason", Namespace.REPORTING_REASON_SPAM);
354+
if (serverMsgId != null) {
355+
final Element stanzaId = report.addChild("stanza-id", Namespace.STANZA_IDS);
356+
stanzaId.setAttribute("by", jid);
357+
stanzaId.setAttribute("id", serverMsgId);
358+
}
353359
}
354360
Log.d(Config.LOGTAG, iq.toString());
355361
return iq;

src/main/java/eu/siacs/conversations/services/XmppConnectionService.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -4756,10 +4756,10 @@ public void clearConversationHistory(final Conversation conversation) {
47564756
mDatabaseWriterExecutor.execute(runnable);
47574757
}
47584758

4759-
public boolean sendBlockRequest(final Blockable blockable, boolean reportSpam) {
4759+
public boolean sendBlockRequest(final Blockable blockable, final boolean reportSpam, final String serverMsgId) {
47604760
if (blockable != null && blockable.getBlockedJid() != null) {
47614761
final Jid jid = blockable.getBlockedJid();
4762-
this.sendIqPacket(blockable.getAccount(), getIqGenerator().generateSetBlockRequest(jid, reportSpam), (a, response) -> {
4762+
this.sendIqPacket(blockable.getAccount(), getIqGenerator().generateSetBlockRequest(jid, reportSpam, serverMsgId), (a, response) -> {
47634763
if (response.getType() == IqPacket.TYPE.RESULT) {
47644764
a.getBlocklist().add(jid);
47654765
updateBlocklistUi(OnUpdateBlocklist.Status.BLOCKED);

src/main/java/eu/siacs/conversations/ui/BlockContactDialog.java

+28-4
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,27 @@
1414
import eu.siacs.conversations.ui.util.JidDialog;
1515

1616
public final class BlockContactDialog {
17+
1718
public static void show(final XmppActivity xmppActivity, final Blockable blockable) {
19+
show(xmppActivity, blockable, null);
20+
}
21+
public static void show(final XmppActivity xmppActivity, final Blockable blockable, final String serverMsgId) {
1822
final AlertDialog.Builder builder = new AlertDialog.Builder(xmppActivity);
1923
final boolean isBlocked = blockable.isBlocked();
2024
builder.setNegativeButton(R.string.cancel, null);
2125
DialogBlockContactBinding binding = DataBindingUtil.inflate(xmppActivity.getLayoutInflater(), R.layout.dialog_block_contact, null, false);
2226
final boolean reporting = blockable.getAccount().getXmppConnection().getFeatures().spamReporting();
23-
binding.reportSpam.setVisibility(!isBlocked && reporting ? View.VISIBLE : View.GONE);
27+
if (reporting && !isBlocked) {
28+
binding.reportSpam.setVisibility(View.VISIBLE);
29+
if (serverMsgId != null) {
30+
binding.reportSpam.setChecked(true);
31+
binding.reportSpam.setEnabled(false);
32+
} else {
33+
binding.reportSpam.setEnabled(true);
34+
}
35+
} else {
36+
binding.reportSpam.setVisibility(View.GONE);
37+
}
2438
builder.setView(binding.getRoot());
2539

2640
final String value;
@@ -34,8 +48,18 @@ public static void show(final XmppActivity xmppActivity, final Blockable blockab
3448
value =blockable.getJid().getDomain().toEscapedString();
3549
res = isBlocked ? R.string.unblock_domain_text : R.string.block_domain_text;
3650
} else {
37-
int resBlockAction = blockable instanceof Conversation && ((Conversation) blockable).isWithStranger() ? R.string.block_stranger : R.string.action_block_contact;
38-
builder.setTitle(isBlocked ? R.string.action_unblock_contact : resBlockAction);
51+
if (isBlocked) {
52+
builder.setTitle(R.string.action_unblock_contact);
53+
} else if (serverMsgId != null) {
54+
builder.setTitle(R.string.report_spam_and_block);
55+
} else {
56+
final int resBlockAction =
57+
blockable instanceof Conversation
58+
&& ((Conversation) blockable).isWithStranger()
59+
? R.string.block_stranger
60+
: R.string.action_block_contact;
61+
builder.setTitle(resBlockAction);
62+
}
3963
value = blockable.getJid().asBareJid().toEscapedString();
4064
res = isBlocked ? R.string.unblock_contact_text : R.string.block_contact_text;
4165
}
@@ -45,7 +69,7 @@ public static void show(final XmppActivity xmppActivity, final Blockable blockab
4569
xmppActivity.xmppConnectionService.sendUnblockRequest(blockable);
4670
} else {
4771
boolean toastShown = false;
48-
if (xmppActivity.xmppConnectionService.sendBlockRequest(blockable, binding.reportSpam.isChecked())) {
72+
if (xmppActivity.xmppConnectionService.sendBlockRequest(blockable, binding.reportSpam.isChecked(), serverMsgId)) {
4973
Toast.makeText(xmppActivity, R.string.corresponding_conversations_closed, Toast.LENGTH_SHORT).show();
5074
toastShown = true;
5175
}

src/main/java/eu/siacs/conversations/ui/BlocklistActivity.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected void showEnterJidDialog() {
8787

8888
dialog.setOnEnterJidDialogPositiveListener((accountJid, contactJid) -> {
8989
Blockable blockable = new RawBlockable(account, contactJid);
90-
if (xmppConnectionService.sendBlockRequest(blockable, false)) {
90+
if (xmppConnectionService.sendBlockRequest(blockable, false, null)) {
9191
Toast.makeText(BlocklistActivity.this, R.string.corresponding_conversations_closed, Toast.LENGTH_SHORT).show();
9292
}
9393
return true;

src/main/java/eu/siacs/conversations/ui/ConversationFragment.java

+19
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,7 @@ private void populateContextMenu(ContextMenu menu) {
13081308
|| t instanceof HttpDownloadConnection);
13091309
activity.getMenuInflater().inflate(R.menu.message_context, menu);
13101310
menu.setHeaderTitle(R.string.message_options);
1311+
final MenuItem reportAndBlock = menu.findItem(R.id.action_report_and_block);
13111312
MenuItem openWith = menu.findItem(R.id.open_with);
13121313
MenuItem copyMessage = menu.findItem(R.id.copy_message);
13131314
MenuItem copyLink = menu.findItem(R.id.copy_link);
@@ -1326,6 +1327,17 @@ private void populateContextMenu(ContextMenu menu) {
13261327
m.getStatus() == Message.STATUS_SEND_FAILED
13271328
&& m.getErrorMessage() != null
13281329
&& !Message.ERROR_MESSAGE_CANCELLED.equals(m.getErrorMessage());
1330+
final Conversational conversational = m.getConversation();
1331+
if (m.getStatus() == Message.STATUS_RECEIVED && conversational instanceof Conversation c) {
1332+
final XmppConnection connection = c.getAccount().getXmppConnection();
1333+
if (c.isWithStranger()
1334+
&& m.getServerMsgId() != null
1335+
&& !c.isBlocked()
1336+
&& connection != null
1337+
&& connection.getFeatures().spamReporting()) {
1338+
reportAndBlock.setVisible(true);
1339+
}
1340+
}
13291341
if (!m.isFileOrImage()
13301342
&& !encrypted
13311343
&& !m.isGeoUri()
@@ -1449,6 +1461,9 @@ public boolean onContextItemSelected(MenuItem item) {
14491461
case R.id.open_with:
14501462
openWith(selectedMessage);
14511463
return true;
1464+
case R.id.action_report_and_block:
1465+
reportMessage(selectedMessage);
1466+
return true;
14521467
default:
14531468
return super.onContextItemSelected(item);
14541469
}
@@ -2114,6 +2129,10 @@ private void openWith(final Message message) {
21142129
}
21152130
}
21162131

2132+
private void reportMessage(final Message message) {
2133+
BlockContactDialog.show(activity, conversation.getContact(), message.getServerMsgId());
2134+
}
2135+
21172136
private void showErrorMessage(final Message message) {
21182137
AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());
21192138
builder.setTitle(R.string.error_message);

src/main/java/eu/siacs/conversations/xml/Namespace.java

+2
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,6 @@ public final class Namespace {
6767
public static final String OMEMO_DTLS_SRTP_VERIFICATION = "http://gultsch.de/xmpp/drafts/omemo/dlts-srtp-verification";
6868
public static final String JINGLE_TRANSPORT_ICE_OPTION = "http://gultsch.de/xmpp/drafts/jingle/transports/ice-udp/option";
6969
public static final String UNIFIED_PUSH = "http://gultsch.de/xmpp/drafts/unified-push";
70+
public static final String REPORTING = "urn:xmpp:reporting:1";
71+
public static final String REPORTING_REASON_SPAM = "urn:xmpp:reporting:spam";
7072
}

src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2689,7 +2689,7 @@ public boolean blocking() {
26892689
}
26902690

26912691
public boolean spamReporting() {
2692-
return hasDiscoFeature(account.getDomain(), "urn:xmpp:reporting:reason:spam:0");
2692+
return hasDiscoFeature(account.getDomain(), Namespace.REPORTING);
26932693
}
26942694

26952695
public boolean flexibleOfflineMessageRetrieval() {

src/main/res/menu/message_context.xml

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<menu xmlns:android="http://schemas.android.com/apk/res/android">
33

4+
<item
5+
android:id="@+id/action_report_and_block"
6+
android:title="@string/report_spam"
7+
android:visible="false" />
8+
49
<item
510
android:id="@+id/open_with"
611
android:title="@string/open_with"

src/main/res/values/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -1020,4 +1020,6 @@
10201020
<string name="log_in">Log in</string>
10211021
<string name="contact_uses_unverified_keys">Your contact uses unverified devices. Scan their 2D barcode to perform verification and impede active MITM attacks.</string>
10221022
<string name="unverified_devices">You are using unverified devices. Scan the 2D barcode on your other devices to perform verification and impede active MITM attacks.</string>
1023+
<string name="report_spam">Report spam</string>
1024+
<string name="report_spam_and_block">Report spam and block spammer</string>
10231025
</resources>

0 commit comments

Comments
 (0)