forked from mirror/monocles_chat_clean
bump reporting xep and add ability to report messages
This commit is contained in:
parent
69744f5946
commit
5f29f4f108
12 changed files with 72 additions and 12 deletions
|
@ -460,7 +460,7 @@
|
||||||
<xmpp:SupportedXep>
|
<xmpp:SupportedXep>
|
||||||
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0377.html"/>
|
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0377.html"/>
|
||||||
<xmpp:status>complete</xmpp:status>
|
<xmpp:status>complete</xmpp:status>
|
||||||
<xmpp:version>0.2</xmpp:version>
|
<xmpp:version>0.3.1</xmpp:version>
|
||||||
</xmpp:SupportedXep>
|
</xmpp:SupportedXep>
|
||||||
</implements>
|
</implements>
|
||||||
<implements>
|
<implements>
|
||||||
|
|
|
@ -375,12 +375,18 @@ public class IqGenerator extends AbstractGenerator {
|
||||||
return iq;
|
return iq;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IqPacket generateSetBlockRequest(final Jid jid, boolean reportSpam) {
|
public IqPacket generateSetBlockRequest(final Jid jid, final boolean reportSpam, final String serverMsgId) {
|
||||||
final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
|
final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
|
||||||
final Element block = iq.addChild("block", Namespace.BLOCKING);
|
final Element block = iq.addChild("block", Namespace.BLOCKING);
|
||||||
final Element item = block.addChild("item").setAttribute("jid", jid);
|
final Element item = block.addChild("item").setAttribute("jid", jid);
|
||||||
if (reportSpam) {
|
if (reportSpam) {
|
||||||
item.addChild("report", "urn:xmpp:reporting:0").addChild("spam");
|
final Element report = item.addChild("report", Namespace.REPORTING);
|
||||||
|
report.setAttribute("reason", Namespace.REPORTING_REASON_SPAM);
|
||||||
|
if (serverMsgId != null) {
|
||||||
|
final Element stanzaId = report.addChild("stanza-id", Namespace.STANZA_IDS);
|
||||||
|
stanzaId.setAttribute("by", jid);
|
||||||
|
stanzaId.setAttribute("id", serverMsgId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Log.d(Config.LOGTAG, iq.toString());
|
Log.d(Config.LOGTAG, iq.toString());
|
||||||
return iq;
|
return iq;
|
||||||
|
|
|
@ -5798,10 +5798,10 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean sendBlockRequest(final Blockable blockable, boolean reportSpam) {
|
public boolean sendBlockRequest(final Blockable blockable, final boolean reportSpam, final String serverMsgId) {
|
||||||
if (blockable != null && blockable.getBlockedJid() != null) {
|
if (blockable != null && blockable.getBlockedJid() != null) {
|
||||||
final Jid jid = blockable.getBlockedJid();
|
final Jid jid = blockable.getBlockedJid();
|
||||||
this.sendIqPacket(blockable.getAccount(), getIqGenerator().generateSetBlockRequest(jid, reportSpam), (a, response) -> {
|
this.sendIqPacket(blockable.getAccount(), getIqGenerator().generateSetBlockRequest(jid, reportSpam, serverMsgId), (a, response) -> {
|
||||||
if (response.getType() == IqPacket.TYPE.RESULT) {
|
if (response.getType() == IqPacket.TYPE.RESULT) {
|
||||||
a.getBlocklist().add(jid);
|
a.getBlocklist().add(jid);
|
||||||
updateBlocklistUi(OnUpdateBlocklist.Status.BLOCKED);
|
updateBlocklistUi(OnUpdateBlocklist.Status.BLOCKED);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package eu.siacs.conversations.ui;
|
package eu.siacs.conversations.ui;
|
||||||
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
@ -14,13 +15,27 @@ import eu.siacs.conversations.ui.util.JidDialog;
|
||||||
import me.drakeet.support.toast.ToastCompat;
|
import me.drakeet.support.toast.ToastCompat;
|
||||||
|
|
||||||
public final class BlockContactDialog {
|
public final class BlockContactDialog {
|
||||||
|
|
||||||
public static void show(final XmppActivity xmppActivity, final Blockable blockable) {
|
public static void show(final XmppActivity xmppActivity, final Blockable blockable) {
|
||||||
|
show(xmppActivity, blockable, null);
|
||||||
|
}
|
||||||
|
public static void show(final XmppActivity xmppActivity, final Blockable blockable, final String serverMsgId) {
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(xmppActivity);
|
final AlertDialog.Builder builder = new AlertDialog.Builder(xmppActivity);
|
||||||
final boolean isBlocked = blockable.isBlocked();
|
final boolean isBlocked = blockable.isBlocked();
|
||||||
builder.setNegativeButton(R.string.cancel, null);
|
builder.setNegativeButton(R.string.cancel, null);
|
||||||
DialogBlockContactBinding binding = DataBindingUtil.inflate(xmppActivity.getLayoutInflater(), R.layout.dialog_block_contact, null, false);
|
DialogBlockContactBinding binding = DataBindingUtil.inflate(xmppActivity.getLayoutInflater(), R.layout.dialog_block_contact, null, false);
|
||||||
final boolean reporting = blockable.getAccount().getXmppConnection().getFeatures().spamReporting();
|
final boolean reporting = blockable.getAccount().getXmppConnection().getFeatures().spamReporting();
|
||||||
binding.reportSpam.setVisibility(!isBlocked && reporting ? View.VISIBLE : View.GONE);
|
if (reporting && !isBlocked) {
|
||||||
|
binding.reportSpam.setVisibility(View.VISIBLE);
|
||||||
|
if (serverMsgId != null) {
|
||||||
|
binding.reportSpam.setChecked(true);
|
||||||
|
binding.reportSpam.setEnabled(false);
|
||||||
|
} else {
|
||||||
|
binding.reportSpam.setEnabled(true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
binding.reportSpam.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
builder.setView(binding.getRoot());
|
builder.setView(binding.getRoot());
|
||||||
|
|
||||||
final String value;
|
final String value;
|
||||||
|
@ -34,8 +49,18 @@ public final class BlockContactDialog {
|
||||||
value =blockable.getJid().getDomain().toEscapedString();
|
value =blockable.getJid().getDomain().toEscapedString();
|
||||||
res = isBlocked ? R.string.unblock_domain_text : R.string.block_domain_text;
|
res = isBlocked ? R.string.unblock_domain_text : R.string.block_domain_text;
|
||||||
} else {
|
} else {
|
||||||
int resBlockAction = blockable instanceof Conversation && ((Conversation) blockable).isWithStranger() ? R.string.block_stranger : R.string.action_block_contact;
|
if (isBlocked) {
|
||||||
builder.setTitle(isBlocked ? R.string.action_unblock_contact : resBlockAction);
|
builder.setTitle(R.string.action_unblock_contact);
|
||||||
|
} else if (serverMsgId != null) {
|
||||||
|
builder.setTitle(R.string.report_spam_and_block);
|
||||||
|
} else {
|
||||||
|
final int resBlockAction =
|
||||||
|
blockable instanceof Conversation
|
||||||
|
&& ((Conversation) blockable).isWithStranger()
|
||||||
|
? R.string.block_stranger
|
||||||
|
: R.string.action_block_contact;
|
||||||
|
builder.setTitle(resBlockAction);
|
||||||
|
}
|
||||||
value = blockable.getJid().asBareJid().toEscapedString();
|
value = blockable.getJid().asBareJid().toEscapedString();
|
||||||
res = isBlocked ? R.string.unblock_contact_text : R.string.block_contact_text;
|
res = isBlocked ? R.string.unblock_contact_text : R.string.block_contact_text;
|
||||||
}
|
}
|
||||||
|
@ -45,7 +70,7 @@ public final class BlockContactDialog {
|
||||||
xmppActivity.xmppConnectionService.sendUnblockRequest(blockable);
|
xmppActivity.xmppConnectionService.sendUnblockRequest(blockable);
|
||||||
} else {
|
} else {
|
||||||
boolean toastShown = false;
|
boolean toastShown = false;
|
||||||
if (xmppActivity.xmppConnectionService.sendBlockRequest(blockable, binding.reportSpam.isChecked())) {
|
if (xmppActivity.xmppConnectionService.sendBlockRequest(blockable, binding.reportSpam.isChecked(), serverMsgId)) {
|
||||||
ToastCompat.makeText(xmppActivity, R.string.corresponding_conversations_closed, ToastCompat.LENGTH_SHORT).show();
|
ToastCompat.makeText(xmppActivity, R.string.corresponding_conversations_closed, ToastCompat.LENGTH_SHORT).show();
|
||||||
toastShown = true;
|
toastShown = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ public class BlocklistActivity extends AbstractSearchableListItemActivity implem
|
||||||
|
|
||||||
dialog.setOnEnterJidDialogPositiveListener((accountJid, contactJid, x, y) -> {
|
dialog.setOnEnterJidDialogPositiveListener((accountJid, contactJid, x, y) -> {
|
||||||
Blockable blockable = new RawBlockable(account, contactJid);
|
Blockable blockable = new RawBlockable(account, contactJid);
|
||||||
if (xmppConnectionService.sendBlockRequest(blockable, false)) {
|
if (xmppConnectionService.sendBlockRequest(blockable, false, null)) {
|
||||||
ToastCompat.makeText(BlocklistActivity.this, R.string.corresponding_conversations_closed, ToastCompat.LENGTH_SHORT).show();
|
ToastCompat.makeText(BlocklistActivity.this, R.string.corresponding_conversations_closed, ToastCompat.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -2043,6 +2043,7 @@ public class ConversationFragment extends XmppFragment
|
||||||
|| m.getEncryption() == Message.ENCRYPTION_PGP;
|
|| m.getEncryption() == Message.ENCRYPTION_PGP;
|
||||||
final boolean receiving = m.getStatus() == Message.STATUS_RECEIVED && (t instanceof JingleFileTransferConnection || t instanceof HttpDownloadConnection);
|
final boolean receiving = m.getStatus() == Message.STATUS_RECEIVED && (t instanceof JingleFileTransferConnection || t instanceof HttpDownloadConnection);
|
||||||
activity.getMenuInflater().inflate(R.menu.message_context, menu);
|
activity.getMenuInflater().inflate(R.menu.message_context, menu);
|
||||||
|
final MenuItem reportAndBlock = menu.findItem(R.id.action_report_and_block);
|
||||||
MenuItem openWith = menu.findItem(R.id.open_with);
|
MenuItem openWith = menu.findItem(R.id.open_with);
|
||||||
MenuItem copyMessage = menu.findItem(R.id.copy_message);
|
MenuItem copyMessage = menu.findItem(R.id.copy_message);
|
||||||
MenuItem quoteMessage = menu.findItem(R.id.quote_message);
|
MenuItem quoteMessage = menu.findItem(R.id.quote_message);
|
||||||
|
@ -2067,6 +2068,17 @@ public class ConversationFragment extends XmppFragment
|
||||||
onlyThisThread.setVisible(!conversation.getLockThread() && m.getThread() != null);
|
onlyThisThread.setVisible(!conversation.getLockThread() && m.getThread() != null);
|
||||||
final boolean unInitiatedButKnownSize = MessageUtils.unInitiatedButKnownSize(m);
|
final boolean unInitiatedButKnownSize = MessageUtils.unInitiatedButKnownSize(m);
|
||||||
final boolean showError = m.getStatus() == Message.STATUS_SEND_FAILED && m.getErrorMessage() != null && !Message.ERROR_MESSAGE_CANCELLED.equals(m.getErrorMessage());
|
final boolean showError = m.getStatus() == Message.STATUS_SEND_FAILED && m.getErrorMessage() != null && !Message.ERROR_MESSAGE_CANCELLED.equals(m.getErrorMessage());
|
||||||
|
final Conversational conversational = m.getConversation();
|
||||||
|
if (m.getStatus() == Message.STATUS_RECEIVED && conversational instanceof Conversation c) {
|
||||||
|
final XmppConnection connection = c.getAccount().getXmppConnection();
|
||||||
|
if (c.isWithStranger()
|
||||||
|
&& m.getServerMsgId() != null
|
||||||
|
&& !c.isBlocked()
|
||||||
|
&& connection != null
|
||||||
|
&& connection.getFeatures().spamReporting()) {
|
||||||
|
reportAndBlock.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
final boolean messageDeleted = m.isMessageDeleted();
|
final boolean messageDeleted = m.isMessageDeleted();
|
||||||
deleteMessage.setVisible(true);
|
deleteMessage.setVisible(true);
|
||||||
if (!encrypted && !m.getBody().equals("")) {
|
if (!encrypted && !m.getBody().equals("")) {
|
||||||
|
@ -2268,6 +2280,9 @@ public class ConversationFragment extends XmppFragment
|
||||||
case R.id.show_error_message:
|
case R.id.show_error_message:
|
||||||
showErrorMessage(selectedMessage);
|
showErrorMessage(selectedMessage);
|
||||||
return true;
|
return true;
|
||||||
|
case R.id.action_report_and_block:
|
||||||
|
reportMessage(selectedMessage);
|
||||||
|
return true;
|
||||||
case R.id.open_with:
|
case R.id.open_with:
|
||||||
openWith(selectedMessage);
|
openWith(selectedMessage);
|
||||||
return true;
|
return true;
|
||||||
|
@ -3451,6 +3466,10 @@ public class ConversationFragment extends XmppFragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void reportMessage(final Message message) {
|
||||||
|
BlockContactDialog.show(activity, conversation.getContact(), message.getServerMsgId());
|
||||||
|
}
|
||||||
|
|
||||||
private void showErrorMessage(final Message message) {
|
private void showErrorMessage(final Message message) {
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());
|
final AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());
|
||||||
builder.setTitle(R.string.error_message);
|
builder.setTitle(R.string.error_message);
|
||||||
|
|
|
@ -318,7 +318,7 @@ public final class MucDetailsContextMenuHelper {
|
||||||
return true;
|
return true;
|
||||||
case R.id.context_muc_contact_block_unblock:
|
case R.id.context_muc_contact_block_unblock:
|
||||||
try {
|
try {
|
||||||
activity.xmppConnectionService.sendBlockRequest(new RawBlockable(account, user.getFullJid()), false);
|
activity.xmppConnectionService.sendBlockRequest(new RawBlockable(account, user.getFullJid()), false,null);
|
||||||
activity.xmppConnectionService.leaveMuc(conversation);
|
activity.xmppConnectionService.leaveMuc(conversation);
|
||||||
activity.xmppConnectionService.joinMuc(conversation);
|
activity.xmppConnectionService.joinMuc(conversation);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -69,4 +69,6 @@ public final class Namespace {
|
||||||
public static final String UNIFIED_PUSH = "http://gultsch.de/xmpp/drafts/unified-push";
|
public static final String UNIFIED_PUSH = "http://gultsch.de/xmpp/drafts/unified-push";
|
||||||
public static final String VCARD4 = "urn:ietf:params:xml:ns:vcard-4.0";
|
public static final String VCARD4 = "urn:ietf:params:xml:ns:vcard-4.0";
|
||||||
public static final String SDP_OFFER_ANSWER = "urn:ietf:rfc:3264";
|
public static final String SDP_OFFER_ANSWER = "urn:ietf:rfc:3264";
|
||||||
|
public static final String REPORTING = "urn:xmpp:reporting:1";
|
||||||
|
public static final String REPORTING_REASON_SPAM = "urn:xmpp:reporting:spam";
|
||||||
}
|
}
|
||||||
|
|
|
@ -2926,7 +2926,7 @@ public class XmppConnection implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean spamReporting() {
|
public boolean spamReporting() {
|
||||||
return hasDiscoFeature(account.getDomain(), "urn:xmpp:reporting:reason:spam:0");
|
return hasDiscoFeature(account.getDomain(), Namespace.REPORTING);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean flexibleOfflineMessageRetrieval() {
|
public boolean flexibleOfflineMessageRetrieval() {
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_report_and_block"
|
||||||
|
android:title="@string/report_spam"
|
||||||
|
android:visible="false" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/open_with"
|
android:id="@+id/open_with"
|
||||||
android:title="@string/open_with"
|
android:title="@string/open_with"
|
||||||
|
|
|
@ -1452,4 +1452,6 @@
|
||||||
<string name="grey">Grau</string>
|
<string name="grey">Grau</string>
|
||||||
<string name="blue">Blau</string>
|
<string name="blue">Blau</string>
|
||||||
<string name="green_and_blue">Grün und blau</string>
|
<string name="green_and_blue">Grün und blau</string>
|
||||||
|
<string name="report_spam">Melde Spam</string>
|
||||||
|
<string name="report_spam_and_block">Melde Spam und blockiere Spammer</string>
|
||||||
</resources>
|
</resources>
|
|
@ -1408,4 +1408,6 @@
|
||||||
<string name="green_and_blue">Green and blue</string>
|
<string name="green_and_blue">Green and blue</string>
|
||||||
<string name="pref_send_link_previews">Send link previews</string>
|
<string name="pref_send_link_previews">Send link previews</string>
|
||||||
<string name="pref_send_link_previews_summary">Attach metadata about links when sending a message</string>
|
<string name="pref_send_link_previews_summary">Attach metadata about links when sending a message</string>
|
||||||
|
<string name="report_spam">Report spam</string>
|
||||||
|
<string name="report_spam_and_block">Report spam and block spammer</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue