From 72b559101202e68dfe4c7f084149a44707fa95c2 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 22 Apr 2024 12:49:27 +0200 Subject: [PATCH] introduce setting to ignore invites from strangers --- .../conversations/parser/MessageParser.java | 59 +++++++++++++------ .../siacs/conversations/ui/XmppActivity.java | 9 +-- .../ui/util/MucDetailsContextMenuHelper.java | 1 + src/main/res/values/bools.xml | 1 + src/main/res/values/strings.xml | 2 + src/main/res/xml/preferences.xml | 5 ++ 6 files changed, 54 insertions(+), 23 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 438c199f3a..4cd4ddfdb0 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -5,7 +5,6 @@ import android.util.Pair; import android.net.Uri; - import de.monocles.chat.BobTransfer; import de.monocles.chat.WebxdcUpdate; import java.io.File; @@ -611,7 +610,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece if (selfAddressed) { counterpart = from; } else { - counterpart = to != null ? to : account.getJid(); + counterpart = to; } } else { status = Message.STATUS_RECEIVED; @@ -1509,33 +1508,55 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece this.inviter = inviter; } - public boolean execute(Account account) { - return execute(account, null); - } public boolean execute(final Account account, LocalizedContent body) { if (this.jid == null) { return false; } - final Contact contact = this.inviter != null ? account.getRoster().getContact(this.inviter) : null; + final Contact contact = + this.inviter != null ? account.getRoster().getContact(this.inviter) : null; if (contact != null && contact.isBlocked()) { - Log.d(Config.LOGTAG,account.getJid().asBareJid()+": ignore invite from "+contact.getJid()+" because contact is blocked"); + Log.d( + Config.LOGTAG, + account.getJid().asBareJid() + + ": ignore invite from " + + contact.getJid() + + " because contact is blocked"); return false; } - final Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, jid, true, false); - if (conversation.getMucOptions().online()) { - Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": received invite to " + jid + " but muc is considered to be online"); - mXmppConnectionService.mucSelfPingAndRejoin(conversation); - } else { - conversation.getMucOptions().setPassword(password); - mXmppConnectionService.databaseBackend.updateConversation(conversation); - mXmppConnectionService.joinMuc(conversation, contact != null && contact.showInContactList()); - mXmppConnectionService.updateConversationUi(); - if (body != null) { - mXmppConnectionService.showInvitationNotification(conversation, contact, body); + if ((contact != null && contact.showInContactList()) + || mXmppConnectionService.getBooleanPreference("accept_invites_from_strangers", R.bool.accept_invites_from_strangers)) { + final Conversation conversation = + mXmppConnectionService.findOrCreateConversation(account, jid, true, false); + if (conversation.getMucOptions().online()) { + Log.d( + Config.LOGTAG, + account.getJid().asBareJid() + + ": received invite to " + + jid + + " but muc is considered to be online"); + mXmppConnectionService.mucSelfPingAndRejoin(conversation); + } else { + conversation.getMucOptions().setPassword(password); + mXmppConnectionService.databaseBackend.updateConversation(conversation); + mXmppConnectionService.joinMuc( + conversation, contact != null && contact.showInContactList()); + mXmppConnectionService.updateConversationUi(); + if (body != null) { + mXmppConnectionService.showInvitationNotification(conversation, contact, body); + } } + return true; + } else { + Log.d( + Config.LOGTAG, + account.getJid().asBareJid() + + ": ignoring invite from " + + this.inviter + + " because we are not accepting invites from strangers. direct=" + + direct); + return false; } - return true; } } } diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index 3d4df6c7ab..1b0b0abcc0 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -1392,14 +1392,15 @@ public abstract class XmppActivity extends ActionBarActivity { return invite; } - public boolean execute(XmppActivity activity) { - XmppConnectionService service = activity.xmppConnectionService; - Conversation conversation = service.findConversationByUuid(this.uuid); + public boolean execute(final XmppActivity activity) { + final XmppConnectionService service = activity.xmppConnectionService; + final Conversation conversation = service.findConversationByUuid(this.uuid); if (conversation == null) { return false; } if (conversation.getMode() == Conversation.MODE_MULTI) { - for (Jid jid : jids) { + for (final Jid jid : jids) { + // TODO use direct invites for public conferences service.invite(conversation, jid); } return false; diff --git a/src/main/java/eu/siacs/conversations/ui/util/MucDetailsContextMenuHelper.java b/src/main/java/eu/siacs/conversations/ui/util/MucDetailsContextMenuHelper.java index 1e765ffa56..8c76cc1906 100644 --- a/src/main/java/eu/siacs/conversations/ui/util/MucDetailsContextMenuHelper.java +++ b/src/main/java/eu/siacs/conversations/ui/util/MucDetailsContextMenuHelper.java @@ -310,6 +310,7 @@ public final class MucDetailsContextMenuHelper { activity.privateMsgInMuc(conversation, user.getNick()); return true; case R.id.invite: + // TODO use direct invites for public conferences if (user.getAffiliation().ranks(MucOptions.Affiliation.MEMBER)) { activity.xmppConnectionService.directInvite(conversation, jid.asBareJid()); } else { diff --git a/src/main/res/values/bools.xml b/src/main/res/values/bools.xml index 048c7c8cdc..6d71dded20 100644 --- a/src/main/res/values/bools.xml +++ b/src/main/res/values/bools.xml @@ -14,4 +14,5 @@ false false true + false \ No newline at end of file diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 29789e4510..c121b14c3d 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -1439,4 +1439,6 @@ GIFs imported Import own GIFs Import your own GIFs. They will be sorted by the filename. + Invites from strangers + Accept invites to group chats from strangers diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml index be746b4fc2..179a2f2323 100644 --- a/src/main/res/xml/preferences.xml +++ b/src/main/res/xml/preferences.xml @@ -488,6 +488,11 @@ android:key="last_activity" android:summary="@string/pref_broadcast_last_activity_summary" android:title="@string/pref_broadcast_last_activity" /> +