diff --git a/src/main/java/eu/siacs/conversations/AppSettings.java b/src/main/java/eu/siacs/conversations/AppSettings.java index dde4ff8db..0916d1e1a 100644 --- a/src/main/java/eu/siacs/conversations/AppSettings.java +++ b/src/main/java/eu/siacs/conversations/AppSettings.java @@ -44,6 +44,8 @@ public class AppSettings { public static final String COLORFUL_CHAT_BUBBLES = "use_green_background"; public static final String LARGE_FONT = "large_font"; + private static final String ACCEPT_INVITES_FROM_STRANGERS = "accept_invites_from_strangers"; + private final Context context; public AppSettings(final Context context) { @@ -107,6 +109,11 @@ public class AppSettings { return getBooleanPreference(USE_TOR, R.bool.use_tor); } + public boolean isAcceptInvitesFromStrangers() { + return getBooleanPreference( + ACCEPT_INVITES_FROM_STRANGERS, R.bool.accept_invites_from_strangers); + } + private boolean getBooleanPreference(@NonNull final String name, @BoolRes int res) { final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index a949b088d..97c0181b7 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -14,6 +14,7 @@ import java.util.Map; import java.util.Set; import java.util.UUID; +import eu.siacs.conversations.AppSettings; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.crypto.axolotl.AxolotlService; @@ -459,7 +460,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; @@ -1136,22 +1137,48 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece 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); + final AppSettings appSettings = new AppSettings(mXmppConnectionService); + if ((contact != null && contact.showInContactList()) + || appSettings.isAcceptInvitesFromStrangers()) { + 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(); + } + return true; } else { - conversation.getMucOptions().setPassword(password); - mXmppConnectionService.databaseBackend.updateConversation(conversation); - mXmppConnectionService.joinMuc(conversation, contact != null && contact.showInContactList()); - mXmppConnectionService.updateConversationUi(); + 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 5739d0595..2ce3eb52a 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -976,14 +976,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 6b5ea13c8..c768df44e 100644 --- a/src/main/java/eu/siacs/conversations/ui/util/MucDetailsContextMenuHelper.java +++ b/src/main/java/eu/siacs/conversations/ui/util/MucDetailsContextMenuHelper.java @@ -183,6 +183,7 @@ public final class MucDetailsContextMenuHelper { activity.privateMsgInMuc(conversation, user.getName()); 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/defaults.xml b/src/main/res/values/defaults.xml index 03bc16b6f..61900117d 100644 --- a/src/main/res/values/defaults.xml +++ b/src/main/res/values/defaults.xml @@ -25,6 +25,7 @@ 0 true true + true false false false diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 5eb496f3d..bb1e1120f 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -1057,5 +1057,7 @@ When acting as a UnifiedPush Distributor the persistent, reliable and battery-friendly XMPP connection will be utilized to wake up other UnifiedPush compatible app such as Tusky, Ltt.rs, FluffyChat and more. Large font Increase font size in message bubbles + Invites from strangers + Accept invites to group chats from strangers diff --git a/src/main/res/xml/preferences_privacy.xml b/src/main/res/xml/preferences_privacy.xml index 61b121fbd..1d2aae4ef 100644 --- a/src/main/res/xml/preferences_privacy.xml +++ b/src/main/res/xml/preferences_privacy.xml @@ -15,8 +15,8 @@ android:title="@string/pref_chat_states" /> @@ -28,7 +28,12 @@ android:key="allow_message_correction" android:summary="@string/pref_allow_message_correction_summary" android:title="@string/pref_allow_message_correction" /> - +