introduce setting to ignore invites from strangers

This commit is contained in:
Daniel Gultsch 2024-04-22 12:49:27 +02:00
parent d0945c35ee
commit 3892015310
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
7 changed files with 62 additions and 18 deletions

View file

@ -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);

View file

@ -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;
}
}
}

View file

@ -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;

View file

@ -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 {

View file

@ -25,6 +25,7 @@
<integer name="automatic_message_deletion">0</integer>
<bool name="trust_system_ca_store">true</bool>
<bool name="allow_message_correction">true</bool>
<bool name="accept_invites_from_strangers">true</bool>
<bool name="use_tor">false</bool>
<bool name="show_connection_options">false</bool>
<bool name="display_enter_key">false</bool>

View file

@ -1057,5 +1057,7 @@
<string name="pref_up_long_summary">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.</string>
<string name="pref_large_font">Large font</string>
<string name="pref_large_font_summary">Increase font size in message bubbles</string>
<string name="pref_accept_invites_from_strangers">Invites from strangers</string>
<string name="pref_accept_invites_from_strangers_summary">Accept invites to group chats from strangers</string>
</resources>

View file

@ -15,8 +15,8 @@
android:title="@string/pref_chat_states" />
<SwitchPreferenceCompat
android:defaultValue="@bool/last_activity"
android:key="last_activity"
android:icon="@drawable/ic_visibility_24dp"
android:key="last_activity"
android:summary="@string/pref_broadcast_last_activity_summary"
android:title="@string/pref_broadcast_last_activity" />
@ -28,7 +28,12 @@
android:key="allow_message_correction"
android:summary="@string/pref_allow_message_correction_summary"
android:title="@string/pref_allow_message_correction" />
<SwitchPreferenceCompat
android:defaultValue="@bool/accept_invites_from_strangers"
android:icon="@drawable/ic_domino_mask_24dp"
android:key="accept_invites_from_strangers"
android:summary="@string/pref_accept_invites_from_strangers_summary"
android:title="@string/pref_accept_invites_from_strangers" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_presence_settings">
<SwitchPreferenceCompat